2009-07-08 13:19:16 -07:00
|
|
|
/*
|
2013-04-05 12:25:50 -05:00
|
|
|
* Copyright (c) 2008, 2009, 2011, 2012, 2013 Nicira, Inc.
|
2009-07-08 13:19:16 -07:00
|
|
|
*
|
2009-06-15 15:11:30 -07:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at:
|
2009-07-08 13:19:16 -07:00
|
|
|
*
|
2009-06-15 15:11:30 -07:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2009-07-08 13:19:16 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include "signals.h"
|
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <signal.h>
|
2011-06-07 13:17:57 -07:00
|
|
|
#include <stdlib.h>
|
2009-07-08 13:19:16 -07:00
|
|
|
#include <unistd.h>
|
2017-11-03 13:53:53 +08:00
|
|
|
#include "openvswitch/poll-loop.h"
|
2009-07-08 13:19:16 -07:00
|
|
|
#include "socket-util.h"
|
2016-04-04 21:32:08 -04:00
|
|
|
#include "openvswitch/type-props.h"
|
2009-07-08 13:19:16 -07:00
|
|
|
#include "util.h"
|
2014-12-15 14:10:38 +01:00
|
|
|
#include "openvswitch/vlog.h"
|
2011-03-31 16:23:50 -07:00
|
|
|
|
|
|
|
VLOG_DEFINE_THIS_MODULE(signals);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
#if defined(_NSIG)
|
|
|
|
#define N_SIGNALS _NSIG
|
|
|
|
#elif defined(NSIG)
|
|
|
|
#define N_SIGNALS NSIG
|
|
|
|
#else
|
|
|
|
/* We could try harder to get the maximum signal number, but in practice we
|
|
|
|
* only care about SIGHUP, which is normally signal 1 anyway. */
|
|
|
|
#define N_SIGNALS 32
|
|
|
|
#endif
|
|
|
|
|
2013-04-16 15:25:10 -07:00
|
|
|
/* Returns the name of signal 'signum' as a string. The return value is either
|
|
|
|
* a statically allocated constant string or the 'bufsize'-byte buffer
|
|
|
|
* 'namebuf'. 'bufsize' should be at least SIGNAL_NAME_BUFSIZE.
|
2011-04-01 10:22:51 -07:00
|
|
|
*
|
|
|
|
* The string is probably a (possibly multi-word) description of the signal
|
|
|
|
* (e.g. "Hangup") instead of just the stringified version of the macro
|
|
|
|
* (e.g. "SIGHUP"). */
|
|
|
|
const char *
|
2013-04-16 15:25:10 -07:00
|
|
|
signal_name(int signum, char *namebuf, size_t bufsize)
|
2011-04-01 10:22:51 -07:00
|
|
|
{
|
2013-04-04 23:29:59 -05:00
|
|
|
#if HAVE_DECL_SYS_SIGLIST
|
2013-10-03 15:52:24 +09:00
|
|
|
if (signum >= 0 && signum < N_SIGNALS) {
|
2013-04-16 15:25:10 -07:00
|
|
|
const char *name = sys_siglist[signum];
|
|
|
|
if (name) {
|
|
|
|
return name;
|
|
|
|
}
|
2013-04-04 23:29:59 -05:00
|
|
|
}
|
2011-04-01 10:22:51 -07:00
|
|
|
#endif
|
2013-04-04 23:29:59 -05:00
|
|
|
|
2013-04-16 15:25:10 -07:00
|
|
|
snprintf(namebuf, bufsize, "signal %d", signum);
|
|
|
|
return namebuf;
|
2011-04-01 10:22:51 -07:00
|
|
|
}
|
2011-03-31 16:23:50 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
xsigaction(int signum, const struct sigaction *new, struct sigaction *old)
|
|
|
|
{
|
|
|
|
if (sigaction(signum, new, old)) {
|
2013-04-16 15:25:10 -07:00
|
|
|
char namebuf[SIGNAL_NAME_BUFSIZE];
|
|
|
|
|
2011-03-31 16:23:50 -07:00
|
|
|
VLOG_FATAL("sigaction(%s) failed (%s)",
|
2013-04-16 15:25:10 -07:00
|
|
|
signal_name(signum, namebuf, sizeof namebuf),
|
2013-06-24 10:54:49 -07:00
|
|
|
ovs_strerror(errno));
|
2011-03-31 16:23:50 -07:00
|
|
|
}
|
|
|
|
}
|