From 0005d2e5633b67afddcd1b0be3647c74526e8be1 Mon Sep 17 00:00:00 2001 From: Tom Cort Date: Mon, 26 Nov 2007 23:56:11 -0500 Subject: [PATCH] Single Handler Functions This module contains some functions to install and handle signals. --- sig.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sig.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 sig.c create mode 100644 sig.h diff --git a/sig.c b/sig.c new file mode 100644 index 0000000..46aa1f0 --- /dev/null +++ b/sig.c @@ -0,0 +1,65 @@ +/* + * inoclam - Inotify+ClamAV virus scanner + * Copyright (C) 2007 Vermont Department of Taxes + * + * This program 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 + * (at your option) any later version. + * + * This program 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 this program. If not, see . + * + * Contributor(s): + * Tom Cort + */ + +#include + +#include "sig.h" + +/** + * Signal handler for SIGKILL, SIGQUIT, SIGINT. + * Raises a SIGUSR1 signal to tell nanohttp to stop. + * @param sig signal to handle. + */ +void handle_signal(int sig) +{ + switch (sig) { + case SIGKILL: + exit_now = 1; + raise(SIGUSR1); + break; + case SIGQUIT: + exit_now = 1; + raise(SIGUSR1); + break; + case SIGINT: + exit_now = 1; + raise(SIGUSR1); + break; + } +} + +/** + * installs signal handlers (mostly SIG_IGN) + */ +void install_signal_handlers() +{ + int i; + + for (i = 0; i < 32; i++) { + if (i != SIGCHLD && i != SIGQUIT && i != SIGINT && i != SIGKILL) { + signal(i, SIG_IGN); + } + } + + signal(SIGKILL, handle_signal); + signal(SIGINT, handle_signal); + signal(SIGQUIT, handle_signal); +} diff --git a/sig.h b/sig.h new file mode 100644 index 0000000..2b2fc67 --- /dev/null +++ b/sig.h @@ -0,0 +1,43 @@ +/* + * inoclam - Inotify+ClamAV virus scanner + * Copyright (C) 2007 Vermont Department of Taxes + * + * This program 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 + * (at your option) any later version. + * + * This program 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 this program. If not, see . + * + * Contributor(s): + * Tom Cort + */ + +#ifndef __SIGNAL_H +#define __SIGNAL_H + +/** + * Signal handler for SIGKILL, SIGQUIT, SIGINT. + * Raises a SIGUSR1 signal to tell nanohttp to stop. + * @param sig signal to handle + */ +void handle_signal(int sig); + +/** + * installs signal handlers (mostly SIG_IGN) + */ +void install_signal_handlers(); + +/** + * Global variable used to determine if the program should halt. Will it ever halt? Only Alan Turing knows. + * @see handle_signal() + */ +int exit_now; + +#endif -- 2.11.4.GIT