grim/guifications3

missed a few free's. This is pretty ugly how I'm doing it right now, but it works.

refs #69
/*
* Guifications - The end-all, be-all notification framework
* Copyright (C) 2003-2009 Gary Kramlich <grim@reaperworld.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
#ifdef HAVE_SIGNAL_H
# include <signal.h>
#endif /* HAVE_SIGNAL_H */
#include <stdlib.h>
#include <string.h>
#include <gflib/gf_lib.h>
#include "guifications-daemon.h"
#include "guifications-daemon-connections.h"
/******************************************************************************
* Globals
*****************************************************************************/
#ifdef HAVE_SIGNAL_H
static gint signals_caught[] = {
SIGSEGV,
SIGHUP,
SIGINT,
SIGTERM,
SIGQUIT,
SIGUSR1,
-1,
};
static gint signals_ignored[] = {
SIGPIPE,
-1,
};
#endif /* HAVE_SIGNAL_H */
/******************************************************************************
* Globals
*****************************************************************************/
#ifdef HAVE_SIGNAL_H
static void
gfd_signal_handler(gint signal) {
switch(signal) {
case SIGSEGV:
gf_log_critical("Guifications-Daemon",
"Guifications-Daemon has segfaulted and attempted to dump a "
"core file.\n");
abort();
break;
case SIGHUP:
/* reload prefs */
gf_log_event("Guifications-Daemon", "Caught signal SIGHUP\n");
break;
case SIGUSR1:
gf_log_event("Guifications-Daemon", "Caught signal SIGUSR1\n");
gfd_connections_debug();
break;
default:
gf_log_event("Guifications-Daemon", "Caught signal %d\n", signal);
gfd_quit();
exit(0);
break;
}
}
#endif /* HAVE_SIGNAL_H */
/******************************************************************************
* API
*****************************************************************************/
void
gfd_signals_init(void) {
#ifndef HAVE_SIGNAL_H
return;
#else
gint i;
sigset_t sigset;
if(sigemptyset(&sigset)) {
gf_log_critical("Guifications-Daemon",
"Failed to initialize an empty signal set.\n");
}
for(i = 0; signals_caught[i] != -1; i++) {
if(signal(signals_caught[i], gfd_signal_handler) == SIG_ERR) {
gf_log_critical("Guifications-Daemon",
"Failed to catch signal %d\n",
signals_caught[i]);
}
if(sigaddset(&sigset, signals_caught[i])) {
gf_log_critical("Guifications-Daemon",
"Failed to unblock signal %d\n",
signals_caught[i]);
}
}
for(i = 0; signals_ignored[i] != -1; i++) {
if(signal(signals_ignored[i], SIG_IGN) == SIG_ERR) {
gf_log_critical("Guifications-Daemon",
"Failed to ignore signal %d\n",
signals_ignored[i]);
}
}
if(sigprocmask(SIG_UNBLOCK, &sigset, NULL)) {
gf_log_critical("Guifications-Daemon",
"Failed to unblock signals.\n");
}
#endif /* HAVE_SIGNAL_H */
}
void
gfd_signals_uninit(void) {
}