From: Ian Jackson Date: Tue, 27 Apr 2010 20:29:42 +0000 (+0100) Subject: info in lockfile X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=inn-innduct.git;a=commitdiff_plain;h=6bae4265aedaee30cb0b92c757dd14d2ed39b6e1;ds=sidebyside info in lockfile --- diff --git a/backends/innduct.c b/backends/innduct.c index 620354f..1fd3828 100644 --- a/backends/innduct.c +++ b/backends/innduct.c @@ -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(); diff --git a/doc/man/innduct.8 b/doc/man/innduct.8 index d5f6be0..72ee35f 100644 --- a/doc/man/innduct.8 +++ b/doc/man/innduct.8 @@ -344,6 +344,16 @@ feed. A process holds this lock after it has opened the lockfile, made an fcntl F_SETLK call, and then checked with stat and fstat that the file it now has open and has locked still has the name \fIfeedfile\fR_lock. (Only) the lockholder may delete the lockfile. +For your convenience, after the lockfile is locked, +.IR innfeed 's +pid, the +.IR site , +.IR feedfile +and +.IR fqdn +are all written to the lockfile. NB that stale lockfiles may contain +stale data so this information should not be relied on other than for +troubleshooting. .IP \fIfeedfile\fR_flushing .IX Item "flushing file" Batch file: the main feedfile is renamed to this filename by innduct