1 /* Copyright (C) 2016-2017 Free Software Foundation, Inc.
3 This file is part of GDB.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 #include "common-defs.h"
19 #include "signals-state-save-restore.h"
23 /* The original signal actions and mask. */
26 static struct sigaction original_signal_actions
[NSIG
];
28 /* Note that we use sigprocmask without worrying about threads because
29 the save/restore functions are called either from main, or after a
30 fork. In both cases, we know the calling process is single
32 static sigset_t original_signal_mask
;
35 /* See signals-state-save-restore.h. */
38 save_original_signals_state (void)
44 res
= sigprocmask (0, NULL
, &original_signal_mask
);
46 perror_with_name (("sigprocmask"));
48 for (i
= 1; i
< NSIG
; i
++)
50 struct sigaction
*oldact
= &original_signal_actions
[i
];
52 res
= sigaction (i
, NULL
, oldact
);
53 if (res
== -1 && errno
== EINVAL
)
55 /* Some signal numbers in the range are invalid. */
59 perror_with_name (("sigaction"));
61 /* If we find a custom signal handler already installed, then
62 this function was called too late. */
63 if (oldact
->sa_handler
!= SIG_DFL
&& oldact
->sa_handler
!= SIG_IGN
)
64 internal_error (__FILE__
, __LINE__
, _("unexpected signal handler"));
69 /* See signals-state-save-restore.h. */
72 restore_original_signals_state (void)
78 for (i
= 1; i
< NSIG
; i
++)
80 res
= sigaction (i
, &original_signal_actions
[i
], NULL
);
81 if (res
== -1 && errno
== EINVAL
)
83 /* Some signal numbers in the range are invalid. */
87 perror_with_name (("sigaction"));
90 res
= sigprocmask (SIG_SETMASK
, &original_signal_mask
, NULL
);
92 perror_with_name (("sigprocmask"));