2 * Copyright (c) 2008, 2009, 2011, 2012, 2013 Nicira, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 #include "poll-loop.h"
25 #include "socket-util.h"
26 #include "type-props.h"
30 VLOG_DEFINE_THIS_MODULE(signals);
33 #define N_SIGNALS _NSIG
35 #define N_SIGNALS NSIG
37 /* We could try harder to get the maximum signal number, but in practice we
38 * only care about SIGHUP, which is normally signal 1 anyway. */
42 /* Returns the name of signal 'signum' as a string. The return value is either
43 * a statically allocated constant string or the 'bufsize'-byte buffer
44 * 'namebuf'. 'bufsize' should be at least SIGNAL_NAME_BUFSIZE.
46 * The string is probably a (possibly multi-word) description of the signal
47 * (e.g. "Hangup") instead of just the stringified version of the macro
50 signal_name(int signum, char *namebuf, size_t bufsize)
52 #if HAVE_DECL_SYS_SIGLIST
53 if (signum >= 0 && signum < N_SIGNALS) {
54 const char *name = sys_siglist[signum];
61 snprintf(namebuf, bufsize, "signal %d", signum);
66 xsigaction(int signum, const struct sigaction *new, struct sigaction *old)
68 if (sigaction(signum, new, old)) {
69 char namebuf[SIGNAL_NAME_BUFSIZE];
71 VLOG_FATAL("sigaction(%s) failed (%s)",
72 signal_name(signum, namebuf, sizeof namebuf),