From ce184a14861ea3ec7d74e1767fed785b253b0d29 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ale=C5=A1=20K=C5=99enek?= Date: Thu, 26 Nov 2009 15:44:32 +0000 Subject: [PATCH] write pid into file (bug #52451) --- org.glite.lb.logger/src/interlogd.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/org.glite.lb.logger/src/interlogd.c b/org.glite.lb.logger/src/interlogd.c index e6ebded..220470e 100644 --- a/org.glite.lb.logger/src/interlogd.c +++ b/org.glite.lb.logger/src/interlogd.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "interlogd.h" #include "glite/lb/log_proto.h" @@ -22,12 +23,15 @@ #if defined(IL_NOTIFICATIONS) #define DEFAULT_PREFIX "/tmp/notif_events" #define DEFAULT_SOCKET "/tmp/notif_interlogger.sock" +#define DEFAULT_PIDFILE "/var/glite/glite-lb-notif-interlogd.pid" #else #define DEFAULT_PREFIX EDG_WLL_LOG_PREFIX_DEFAULT #define DEFAULT_SOCKET "/tmp/interlogger.sock" +#define DEFAULT_PIDFILE "/var/glite/glite-lb-interlogd.pid" #endif + /* The name the program was run with, stripped of any leading path. */ char *program_name; int killflg = 0; @@ -39,6 +43,8 @@ pthread_mutex_t cred_handle_lock = PTHREAD_MUTEX_INITIALIZER; time_t key_mtime = 0, cert_mtime = 0; +static char *pidfile = DEFAULT_PIDFILE; + static void usage (int status) { printf("%s - \n" @@ -54,6 +60,7 @@ static void usage (int status) " -k, --key location of server private key\n" " -C, --CAdir directory containing CA certificates\n" " -b, --book send events to bookkeeping server only\n" + " -i, --pidfile pid file\n" " -l, --log-server specify address of log server\n" " -s, --socket non-default path of local socket\n" " -L, --lazy [] be lazy when closing connections to servers (default, timeout==0 means turn lazy off)\n" @@ -105,6 +112,7 @@ static struct option const long_options[] = {"key", required_argument, 0, 'k'}, {"book", no_argument, 0, 'b'}, {"CAdir", required_argument, 0, 'C'}, + {"pidfile", required_argument, 0, 'i'}, {"log-server", required_argument, 0, 'l'}, {"socket", required_argument, 0, 's'}, {"lazy", optional_argument, 0, 'L'}, @@ -143,6 +151,7 @@ decode_switches (int argc, char **argv) "k:" /* key */ "C:" /* CA dir */ "b" /* only bookeeping */ + "i:" /* pidfile*/ "l:" /* log server */ "d" /* debug */ "p" /* parallel */ @@ -198,6 +207,10 @@ decode_switches (int argc, char **argv) log_server = strdup(optarg); break; + case 'i': + pidfile = strdup(optarg); + break; + case 'C': CAcert_dir = strdup(optarg); break; @@ -279,6 +292,7 @@ main (int argc, char **argv) char *p; edg_wll_GssStatus gss_stat; int ret; + FILE *pidf; program_name = argv[0]; @@ -308,12 +322,23 @@ main (int argc, char **argv) exit(EXIT_FAILURE); } +/* just try it before deamonizing to be able to complain aloud */ + if (!(pidf = fopen(pidfile,"w"))) { + perror(pidfile); + exit(EXIT_FAILURE); + } + fclose(pidf); + if(!debug && (daemon(0,0) < 0)) { perror("daemon"); exit(EXIT_FAILURE); } + pidf = fopen(pidfile,"w"); assert(pidf); /* XXX */ + fprintf(pidf,"%d\n",getpid()); + fclose(pidf); + #ifdef LB_PERF /* this must be called after installing signal handlers */ glite_wll_perftest_init(NULL, /* host */ -- 1.8.2.3