[1965] in Moira Commits

home help back first fref pref prev next nref lref last post

/svn/moira r4104 - trunk/moira/update

daemon@ATHENA.MIT.EDU (Garry Zacheiss)
Mon Apr 8 16:35:51 2013

Date: Mon, 8 Apr 2013 16:35:44 -0400
From: Garry Zacheiss <zacheiss@MIT.EDU>
Message-Id: <201304082035.r38KZi9V028678@drugstore.mit.edu>
To: moira-commits@MIT.EDU
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Author: zacheiss
Date: 2013-04-08 16:35:44 -0400 (Mon, 08 Apr 2013)
New Revision: 4104

Modified:
   trunk/moira/update/update_server.c
   trunk/moira/update/update_server.h
Log:
Write out a pid file.

Modified: trunk/moira/update/update_server.c
===================================================================
--- trunk/moira/update/update_server.c	2013-04-08 18:27:39 UTC (rev 4103)
+++ trunk/moira/update/update_server.c	2013-04-08 20:35:44 UTC (rev 4104)
@@ -65,6 +65,8 @@
   struct utsname name;
   int s, conn;
   struct sigaction sa;
+  FILE *pid_file;
+  char *pid_path = NULL;
 
   whoami = strrchr(argv[0], '/');
   if (whoami)
@@ -128,6 +130,28 @@
   set_com_err_hook(syslog_com_err_proc);
   openlog(whoami, LOG_PID, LOG_DAEMON);
 
+  if ((pid_path = malloc(strlen(PIDFILEPATH) + strlen(whoami) + 6)) != NULL)
+    {
+      sprintf(pid_path, "%s/%s.pid", PIDFILEPATH, whoami);
+      pid_file = fopen(pid_path, "w");
+      if (pid_file)
+	{
+	  fprintf(pid_file, "%d\n", getpid ());
+	  fclose(pid_file);
+	}
+      else
+	{
+	  com_err(whoami, errno, "Unable to write PID file %s", pid_path);
+	  exit(1);
+	}
+      free(pid_path);
+    }
+  else 
+    {
+      com_err(whoami, errno, "Could not allocate memory for pidfile path");
+      exit(1);
+    }
+
   /* now loop waiting for connections */
   while (1)
     {

Modified: trunk/moira/update/update_server.h
===================================================================
--- trunk/moira/update/update_server.h	2013-04-08 18:27:39 UTC (rev 4103)
+++ trunk/moira/update/update_server.h	2013-04-08 20:35:44 UTC (rev 4104)
@@ -33,3 +33,7 @@
 
 extern char *whoami, *hostname;
 extern int have_authorization, uid;
+
+#ifndef PIDFILEPATH
+#define PIDFILEPATH "/var/run"
+#endif


home help back first fref pref prev next nref lref last post