[6287] in Moira
Re: PATCH: Make update_server write out a PID file
daemon@ATHENA.MIT.EDU (Garry P Zacheiss)
Mon Apr 8 15:07:41 2013
From: Garry P Zacheiss <zacheiss@MIT.EDU>
To: Jonathan D Reed <jdreed@MIT.EDU>
CC: "<moiradev@mit.edu>" <moiradev@MIT.EDU>
Date: Mon, 8 Apr 2013 19:07:28 +0000
Message-ID: <7A06C2897958944188C59D5BE070539426A3122F@OC11EXPO24.exchange.mit.edu>
In-Reply-To: <alpine.DEB.2.02.1304081459140.29490@infinite-loop.mit.edu>
Content-Language: en-US
Content-Type: text/plain; charset="us-ascii"
Content-ID: <B37E7EEA82EBAF4AAF931376C6FE0D2E@exchange.mit.edu>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
I'd take something like it, although I'd rather we make use of the 'whoami' variable in the filename rather than hardcoding "update_server" in the filename. The PIDFILEPATH definition would also be better moved to update_server.h rather than the .c file.
Garry
On Apr 8, 2013, at 3:00 PM, Jonathan Reed <jdreed@MIT.EDU>
wrote:
> 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)
> {