]> git.proxmox.com Git - mirror_ovs.git/blob - lib/signals.c
ovsdb-idl: Fix iteration over tracked rows with no actual data.
[mirror_ovs.git] / lib / signals.c
1 /*
2 * Copyright (c) 2008, 2009, 2011, 2012, 2013 Nicira, Inc.
3 *
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:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 #include <config.h>
18 #include "signals.h"
19 #include <errno.h>
20 #include <limits.h>
21 #include <signal.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include "openvswitch/poll-loop.h"
25 #include "socket-util.h"
26 #include "openvswitch/type-props.h"
27 #include "util.h"
28 #include "openvswitch/vlog.h"
29
30 VLOG_DEFINE_THIS_MODULE(signals);
31
32 #if defined(_NSIG)
33 #define N_SIGNALS _NSIG
34 #elif defined(NSIG)
35 #define N_SIGNALS NSIG
36 #else
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. */
39 #define N_SIGNALS 32
40 #endif
41
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.
45 *
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
48 * (e.g. "SIGHUP"). */
49 const char *
50 signal_name(int signum, char *namebuf, size_t bufsize)
51 {
52 #if HAVE_DECL_SYS_SIGLIST
53 if (signum >= 0 && signum < N_SIGNALS) {
54 const char *name = sys_siglist[signum];
55 if (name) {
56 return name;
57 }
58 }
59 #endif
60
61 snprintf(namebuf, bufsize, "signal %d", signum);
62 return namebuf;
63 }
64
65 void
66 xsigaction(int signum, const struct sigaction *new, struct sigaction *old)
67 {
68 if (sigaction(signum, new, old)) {
69 char namebuf[SIGNAL_NAME_BUFSIZE];
70
71 VLOG_FATAL("sigaction(%s) failed (%s)",
72 signal_name(signum, namebuf, sizeof namebuf),
73 ovs_strerror(errno));
74 }
75 }