This repository has been archived on 2021-02-08. You can view files and clone it, but cannot push or open issues or pull requests.
uIRCd/src/signal.c

53 lines
1.6 KiB
C

/*
* This file is part of uIRCd. (https://git.redxen.eu/caskd/uIRCd)
* Copyright (c) 2019, 2020 Alex-David Denes
*
* uIRCd is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* uIRCd is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with uIRCd. If not, see <https://www.gnu.org/licenses/>.
*/
#include "signal.h"
#include "logging.h"
#include <errno.h> // errno
#include <signal.h> // sig_atomic_t
#include <stdbool.h> // true, false
#include <stdio.h> // NULL, fprintf()
#include <string.h> // strerror()
sig_atomic_t volatile run = true;
void
stop_loop(int sig, siginfo_t* info, void* ucontext)
{
run = 0;
}
int
setup_signals(void)
{
int res = 1;
struct sigaction sa = { .sa_flags = SA_SIGINFO, .sa_sigaction = stop_loop };
sigemptyset(&sa.sa_mask);
if (sigaction(SIGINT, &sa, NULL) == -1) {
LOG(LOG_WARN, "sigaction() failed. Children won't respond to signal SIGINT. " ERRNOFMT, strerror(errno), errno);
res = 0;
}
if (sigaction(SIGTERM, &sa, NULL) == -1) {
LOG(LOG_WARN, "sigaction() failed. Children won't respond to signal SIGTERM. " ERRNOFMT, strerror(errno), errno);
res = 0;
}
return res;
}