]> git.proxmox.com Git - mirror_ovs.git/blame - lib/signals.c
ovsdb-idl: Fix iteration over tracked rows with no actual data.
[mirror_ovs.git] / lib / signals.c
CommitLineData
064af421 1/*
92829687 2 * Copyright (c) 2008, 2009, 2011, 2012, 2013 Nicira, Inc.
064af421 3 *
a14bc59f
BP
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:
064af421 7 *
a14bc59f
BP
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.
064af421
BP
15 */
16
17#include <config.h>
18#include "signals.h"
064af421
BP
19#include <errno.h>
20#include <limits.h>
21#include <signal.h>
5a08f9b0 22#include <stdlib.h>
064af421 23#include <unistd.h>
fd016ae3 24#include "openvswitch/poll-loop.h"
064af421 25#include "socket-util.h"
ae06a561 26#include "openvswitch/type-props.h"
064af421 27#include "util.h"
e6211adc 28#include "openvswitch/vlog.h"
279c9e03
BP
29
30VLOG_DEFINE_THIS_MODULE(signals);
064af421
BP
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
eee8089c
BP
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.
b725cf02
BP
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"). */
49const char *
eee8089c 50signal_name(int signum, char *namebuf, size_t bufsize)
b725cf02 51{
22c4e104 52#if HAVE_DECL_SYS_SIGLIST
70107327 53 if (signum >= 0 && signum < N_SIGNALS) {
eee8089c
BP
54 const char *name = sys_siglist[signum];
55 if (name) {
56 return name;
57 }
22c4e104 58 }
b725cf02 59#endif
22c4e104 60
eee8089c
BP
61 snprintf(namebuf, bufsize, "signal %d", signum);
62 return namebuf;
b725cf02 63}
279c9e03
BP
64
65void
66xsigaction(int signum, const struct sigaction *new, struct sigaction *old)
67{
68 if (sigaction(signum, new, old)) {
eee8089c
BP
69 char namebuf[SIGNAL_NAME_BUFSIZE];
70
279c9e03 71 VLOG_FATAL("sigaction(%s) failed (%s)",
eee8089c 72 signal_name(signum, namebuf, sizeof namebuf),
10a89ef0 73 ovs_strerror(errno));
279c9e03
BP
74 }
75}