chiark / gitweb /
info in lockfile
[inn-innduct.git] / backends / innduct.c
index 620354f01c2d45b36889ee1be37b471b5ef23537..1fd382835ec9c1355bcd70827585a2bba703e7d1 100644 (file)
@@ -1903,8 +1903,10 @@ static void statemc_init(void) {
   path_defer=       xasprintf("%s_defer",     feedfile);
   globpat_backlog=  xasprintf("%s_backlog*",  feedfile);
 
+  int lockfd;
+  
   for (;;) {
-    int lockfd= open(path_lock, O_CREAT|O_RDWR, 0600);
+    lockfd= open(path_lock, O_CREAT|O_RDWR, 0600);
     if (lockfd<0) sysfatal("open lockfile %s", path_lock);
 
     struct flock fl;
@@ -1929,6 +1931,20 @@ static void statemc_init(void) {
 
     xclose(lockfd, "stale lockfile ", path_lock);
   }
+  pid_t self= getpid();
+  if (self==-1) sysdie("getpid");
+
+  FILE *lockfile= fdopen(lockfd, "w");
+  if (!lockfile) sysdie("fdopen lockfile");
+
+  int r= ftruncate(lockfd, 0);
+  if (r) sysdie("truncate lockfile to write new info");
+
+  if (fprintf(lockfile, "pid %ld\nsite %s\nfeedfile %s\nfqdn %s\n",
+             (unsigned long)self, sitename, feedfile, remote_host) == EOF ||
+      fflush(lockfile))
+    sysfatal("write info to lockfile %s", path_lock);
+
   debug("startup: locked");
 
   search_backlog_file();