mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-10-26 12:24:33 +00:00
Replace the deprecated signal() function by sigaction().
git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@5723 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
1 parent
f5aaeec448
commit
13dc7c0232
1 file changed
+26
-7
+26
-7
@@ -65,7 +65,6 @@ void sensorLog(int priority, const char *fmt, ...)
|
||||
|
||||
static void signalHandler(int sig)
|
||||
{
|
||||
signal(sig, signalHandler);
|
||||
switch (sig) {
|
||||
case SIGTERM:
|
||||
done = 1;
|
||||
@@ -147,6 +146,31 @@ static void openLog(void)
|
||||
logOpened = 1;
|
||||
}
|
||||
|
||||
static void install_sighandler(void)
|
||||
{
|
||||
struct sigaction new;
|
||||
int ret;
|
||||
|
||||
memset(&new, 0, sizeof(struct sigaction));
|
||||
new.sa_handler = signalHandler;
|
||||
sigemptyset(&new.sa_mask);
|
||||
new.sa_flags = SA_RESTART;
|
||||
|
||||
ret = sigaction(SIGTERM, &new, NULL);
|
||||
if (ret == -1) {
|
||||
fprintf(stderr, "Could not set sighandler for SIGTERM: %s\n",
|
||||
strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
ret = sigaction(SIGHUP, &new, NULL);
|
||||
if (ret == -1) {
|
||||
fprintf(stderr, "Could not set sighandler for SIGHUP: %s\n",
|
||||
strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
static void daemonize(void)
|
||||
{
|
||||
int pid;
|
||||
@@ -172,12 +196,7 @@ static void daemonize(void)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* I should use sigaction but... */
|
||||
if (signal(SIGTERM, signalHandler) == SIG_ERR ||
|
||||
signal (SIGHUP, signalHandler) == SIG_ERR) {
|
||||
perror("signal");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
install_sighandler();
|
||||
|
||||
if ((pid = fork()) == -1) {
|
||||
perror("fork()");
|
||||
|
||||
Reference in new issue
Block a user