[6286] in Moira
PATCH: Make update_server write out a PID file
daemon@ATHENA.MIT.EDU (Jonathan Reed)
Mon Apr 8 15:00:25 2013
Date: Mon, 8 Apr 2013 15:00:23 -0400 (EDT)
From: Jonathan Reed <jdreed@MIT.EDU>
To: moiradev@MIT.EDU
Message-ID: <alpine.DEB.2.02.1304081459140.29490@infinite-loop.mit.edu>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII
Hi Garry,
Would you consider a patch like the following so that update-server can
write out a pidfile and play nice with the various daemon tools on Ubuntu?
Thanks,
Jon
Index: moira/update/update_server.c
===================================================================
--- moira/update/update_server.c (revision 4103)
+++ moira/update/update_server.c (working copy)
@@ -30,6 +30,10 @@
#endif
#include "update.h"
+#ifndef PIDFILEPATH
+#define PIDFILEPATH "/var/run"
+#endif
+
RCSID("$HeadURL$ $Id$");
char *whoami, *hostname;
@@ -65,6 +69,8 @@
struct utsname name;
int s, conn;
struct sigaction sa;
+ FILE *pid_file;
+ const char *pid_path;
whoami = strrchr(argv[0], '/');
if (whoami)
@@ -128,6 +134,18 @@
set_com_err_hook(syslog_com_err_proc);
openlog(whoami, LOG_PID, LOG_DAEMON);
+ pid_path = PIDFILEPATH "/update_server.pid";
+ pid_file = fopen(pid_path, "w");
+ if (pid_file)
+ {
+ fprintf (pid_file, "%d\n", getpid ());
+ fclose (pid_file);
+ }
+ else
+ {
+ com_err(whoami, errno, "Could not write PID file");
+ }
+
/* now loop waiting for connections */
while (1)
{