source: trunk/third/ssh/signals.c @ 11534

Revision 11534, 3.0 KB checked in by danw, 27 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r11533, which included commits to RCS files with non-trunk default branches.
Line 
1/*
2
3signals.c
4
5Author: Tatu Ylonen <ylo@cs.hut.fi>
6
7Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
8                   All rights reserved
9
10Created: Fri Jan 19 18:09:37 1995 ylo
11
12Manipulation of signal state.  This file also contains code to set the
13maximum core dump size.
14
15*/
16
17/*
18 * $Log: not supported by cvs2svn $
19 * Revision 1.8  1998/05/04 13:37:05  kivinen
20 *      Fixed SIGPWR code so that will check if SIGPWR is same than
21 *      SIGINFO and only include it to switch clause if it is
22 *      different.
23 *
24 * Revision 1.7  1998/04/30 01:56:32  kivinen
25 *      Added SIGPWR handling.
26 *
27 * Revision 1.6  1997/04/21 01:07:28  kivinen
28 *      Added HAVE_INCOMPATIBLE_SIGINFO support.
29 *
30 * Revision 1.5  1997/03/26 07:16:44  kivinen
31 *      Change sig <= NSIG to sig < NSIG.
32 *
33 * Revision 1.4  1996/08/30 08:44:22  ylo
34 *      Added Sunos/Solaris SIGFREEZE and SIGTHAW to signals with
35 *      default processing.
36 *
37 * Revision 1.3  1996/07/12 07:27:18  ttsalo
38 *      ifdef:d SIGIO
39 *
40 * Revision 1.2  1996/04/26 00:25:48  ylo
41 *      Test for SIGURG == SIGIO (which appears to be the case on some
42 *      Linux versions).
43 *
44 * Revision 1.1.1.1  1996/02/18 21:38:11  ylo
45 *      Imported ssh-1.2.13.
46 *
47 * $EndLog$
48 */
49
50#include "includes.h"
51#ifdef HAVE_SETRLIMIT
52#include <sys/resource.h>
53#endif /* HAVE_SETRLIMIT */
54
55#ifndef NSIG
56#define NSIG 100
57#endif
58
59unsigned long original_core_limit;
60
61static RETSIGTYPE signal_handler(int sig)
62{
63  fprintf(stderr, "\nReceived signal %d.\n", sig);
64  exit(255);
65}
66
67/* Sets signal handlers so that core dumps are prevented.  This also
68   sets the maximum core dump size to zero as an extra precaution (where
69   supported).  The old core dump size limit is saved. */
70
71void signals_prevent_core()
72{
73  int sig;
74
75  for (sig = 1; sig < NSIG; sig++)
76    switch (sig)
77      {
78      case SIGSTOP:
79      case SIGTSTP:
80      case SIGCONT:
81      case SIGCHLD:
82      case SIGTTIN:
83      case SIGTTOU:
84#ifdef SIGIO
85      case SIGIO:
86#endif
87#if defined(SIGURG) && SIGURG != SIGIO
88      case SIGURG:
89#endif
90#ifdef SIGWINCH
91      case SIGWINCH:
92#endif
93#if defined(SIGINFO) && !defined(HAVE_INCOMPATIBLE_SIGINFO)
94      case SIGINFO:
95#endif
96#if defined(SIGFREEZE)
97      case SIGFREEZE:
98#endif
99#if defined(SIGTHAW)
100      case SIGTHAW:
101#endif
102#if defined(SIGPWR)
103#if !defined(SIGINFO) || (SIGINFO != SIGPWR)
104      case SIGPWR:
105#endif
106#endif
107        signal(sig, SIG_DFL);
108        break;
109      default:
110        signal(sig, signal_handler);
111        break;
112      }
113
114#if defined(HAVE_SETRLIMIT) && defined(RLIMIT_CORE)
115  {
116    struct rlimit rl;
117    getrlimit(RLIMIT_CORE, &rl);
118    original_core_limit = rl.rlim_cur;
119    rl.rlim_cur = 0;
120    setrlimit(RLIMIT_CORE, &rl);
121  }
122#endif /* HAVE_SETRLIMIT && RLIMIT_CORE */
123}
124
125/* Sets all signals to their default state.  Restores RLIMIT_CORE previously
126   saved by prevent_core(). */
127
128void signals_reset()
129{
130  int sig;
131
132  for (sig = 1; sig < NSIG; sig++)
133    signal(sig, SIG_DFL);
134
135#if defined(HAVE_SETRLIMIT) && defined(RLIMIT_CORE)
136  {
137    struct rlimit rl;
138    getrlimit(RLIMIT_CORE, &rl);
139    rl.rlim_cur = original_core_limit;
140    setrlimit(RLIMIT_CORE, &rl);
141  }
142#endif /* HAVE_SETRLIMIT && RLIMIT_CORE */
143}
Note: See TracBrowser for help on using the repository browser.