tags 626752 patch
thanks

* Thus spake Zrin ?iborski (zrin+launch...@ziborski.net):
> 
> It uses L_PID which puts the PID of the lockfile-create process in
> the lock.
> It needs to use the L_PPID (2 places) to put the process id of the process
> executing lockfile-create.
> 
> Without this change lockfile-create is useless, as it succeeds every time.
> 
> Spectrum of latent problems and consequences is indeed massive,
> therefore severity grave.

Please be aware that using --use-pid breaks NFS. Anyway, please find attached
a patch for the issue.

Sebastian
>From cb7c25e73173dd12e7582bbcf66fded3ccd92736 Mon Sep 17 00:00:00 2001
From: Sebastian Andrzej Siewior <sebast...@breakpoint.cc>
Date: Sat, 16 Jul 2011 12:16:02 +0200
Subject: [PATCH] lockfile-progs: Use parents PID instead current PID for
 --use-pid

Right now --use-pid writes the PID of the current process i.e. of the
-create binary. This PID is gone once the process terminates. Therefore
the only sane PID to use is the PID of the parent which makes sense in shell
script use case.
There is no difference which of the two options is specified for the -check
variant as this one checks if this PID is alive.
Using --use-pid on -check makes things kinda worse because this is no longer
safe on a shared file system (or may lead to false positives if there happen
to be a process with the PID by chance) which is the oposite what the manpage
of lockfile_create() says.
This also updates the manpage.

Signed-off-by: Sebastian Andrzej Siewior <sebast...@breakpoint.cc>
---
 lockfile-progs.1 |    6 +++---
 lockfile-progs.c |    2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/lockfile-progs.1 b/lockfile-progs.1
index 44f01ca..bf7e1ee 100644
--- a/lockfile-progs.1
+++ b/lockfile-progs.1
@@ -81,11 +81,11 @@ or \fBlockfile-check\fR.
 .PP .\" --use-pid
 \fB\-p\fR, \fB\-\-use\-pid\fR
 .RS 4
-Write the current process id (PID) to the lockfile whenever a lockfile
+Write the parent process id (PPID) to the lockfile whenever a lockfile
 is created, and use that pid when checking a lock's validity.  See the
 \fBlockfile_create\fR(3) manpage for more information.  This option
-applies to \fBlockfile\-create\fR, \fBlockfile\-remove\fR,
-\fBlockfile-touch\fR, and \fBlockfile-check\fR.
+applies to \fBlockfile\-create\fR and \fBlockfile-check\fR. It may provide
+wrong results on a shared file system.
 .RE
 .PP .\" --oneshot
 \fB\-o\fR, \fB\-\-oneshot\fR
diff --git a/lockfile-progs.c b/lockfile-progs.c
index 4d98e7f..dfec125 100644
--- a/lockfile-progs.c
+++ b/lockfile-progs.c
@@ -327,7 +327,7 @@ cmd_unlock(const char *lockfilename)
 static int
 cmd_lock(const char *lockfilename, int retry_count)
 {
-  int rc = lockfile_create(lockfilename, retry_count, (use_pid ? L_PID : 0));
+  int rc = lockfile_create(lockfilename, retry_count, (use_pid ? L_PPID : 0));
   const char *rc_str = get_status_code_string(rc);
 
   if(rc != L_SUCCESS)
-- 
1.7.5.4

Reply via email to