summaryrefslogtreecommitdiff
path: root/server/monitor
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2009-05-05 13:36:17 +0200
committerSimo Sorce <ssorce@redhat.com>2009-05-08 10:11:11 -0400
commitb348e98e47d3ef287fed4d2e272bbf08540e0295 (patch)
tree64f63094d6c8e947c163fba0f69a62c290b554b6 /server/monitor
parent4146c660af61cca7f3c4bcd89d810de1d34bae0a (diff)
downloadsssd-b348e98e47d3ef287fed4d2e272bbf08540e0295.tar.gz
sssd-b348e98e47d3ef287fed4d2e272bbf08540e0295.tar.bz2
sssd-b348e98e47d3ef287fed4d2e272bbf08540e0295.zip
Use tevent for shutdown signals, remove old pidfile, make sssd single-instance.
Use tevent signal handling facilities for handlong SIGTERM and SIGINT in the monitor. Remove pidfile on SIGTERM and SIGINT. Make sssd single-instance by checking if we suceeded in signaling the process in the pidfile.
Diffstat (limited to 'server/monitor')
-rw-r--r--server/monitor/monitor.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/server/monitor/monitor.c b/server/monitor/monitor.c
index 1404858d..fbc3b880 100644
--- a/server/monitor/monitor.c
+++ b/server/monitor/monitor.c
@@ -24,6 +24,7 @@
#include <sys/wait.h>
#include <sys/time.h>
#include <time.h>
+#include <string.h>
#include "config.h"
#ifdef HAVE_SYS_INOTIFY_H
#include <sys/inotify.h>
@@ -121,6 +122,7 @@ static int add_new_provider(struct mt_ctx *ctx, const char *name);
static int monitor_signal_reconf(struct confdb_ctx *cdb, void *pvt);
static int update_monitor_config(struct mt_ctx *ctx);
+static int monitor_cleanup();
/* dbus_get_monitor_version
* Return the monitor version over D-BUS */
@@ -987,6 +989,55 @@ static void monitor_hup(struct tevent_context *ev,
update_monitor_config(ctx);
}
+static int monitor_cleanup(void)
+{
+ char *file;
+ int ret;
+ TALLOC_CTX *tmp_ctx;
+
+ tmp_ctx = talloc_new(NULL);
+ if (!tmp_ctx) return;
+
+ file = talloc_asprintf(tmp_ctx, "%s/%s.pid", PID_PATH, "sssd");
+ if (file == NULL) {
+ return ENOMEM;
+ }
+
+ errno = 0;
+ ret = unlink(file);
+ if (ret == -1) {
+ ret = errno;
+ DEBUG(0, ("Error removing pidfile! (%d [%s])\n",
+ ret, strerror(ret)));
+ talloc_free(file);
+ return errno;
+ }
+
+ talloc_free(file);
+ return EOK;
+}
+
+static void monitor_quit(struct tevent_context *ev,
+ struct tevent_signal *se,
+ int signum,
+ int count,
+ void *siginfo,
+ void *private_data)
+{
+ struct mt_ctx *ctx = talloc_get_type(private_data, struct mt_ctx);
+
+ monitor_cleanup();
+
+#if HAVE_GETPGRP
+ if (getpgrp() == getpid()) {
+ DEBUG(0,("%s: killing children\n", strsignal(signum)));
+ kill(-getpgrp(), SIGTERM);
+ }
+#endif
+
+ exit(0);
+}
+
#ifdef HAVE_SYS_INOTIFY_H
static void config_file_changed(struct tevent_context *ev,
struct tevent_fd *fde,
@@ -1319,6 +1370,22 @@ int monitor_process_init(TALLOC_CTX *mem_ctx,
return EIO;
}
+ /* Set up an event handler for a SIGINT */
+ tes = tevent_add_signal(ctx->ev, ctx, SIGINT, 0,
+ monitor_quit, ctx);
+ if (tes == NULL) {
+ talloc_free(ctx);
+ return EIO;
+ }
+
+ /* Set up an event handler for a SIGTERM */
+ tes = tevent_add_signal(ctx->ev, ctx, SIGTERM, 0,
+ monitor_quit, ctx);
+ if (tes == NULL) {
+ talloc_free(ctx);
+ return EIO;
+ }
+
return EOK;
}
@@ -1902,6 +1969,9 @@ int main(int argc, const char *argv[])
/* loop on main */
server_loop(main_ctx);
+ ret = monitor_cleanup();
+ if (ret != EOK) return 5;
+
return 0;
}