[lockdev-devel] [PATCH 05/10] RedHat patch 5
Ludwig Nussel
ludwig.nussel at suse.de
Wed Feb 10 11:45:35 UTC 2010
- fix detection of stale pid files (brc#128104)
---
src/lockdev.c | 17 ++++++++++++++---
1 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/src/lockdev.c b/src/lockdev.c
index afaba57..c065cfa 100644
--- a/src/lockdev.c
+++ b/src/lockdev.c
@@ -148,7 +148,7 @@ static inline int _dl_lock_semaphore ( void);
static inline int _dl_block_semaphore ( void);
static pid_t _dl_check_lock ( const char * lockname);
static char * _dl_check_devname ( const char * devname);
-
+static inline int _dl_pid_exists ( pid_t pid );
#define SEMAPHORE "LOCKDEV"
#define close_n_return( v) return( _dl_unlock_semaphore( v))
@@ -394,7 +394,7 @@ _dl_check_lock(const char *lockname)
/* checks content's format */
if ( j == 1 ) {
/* checks process existence */
- if ( ( kill( pid_read, 0) == 0 ) || (errno == EPERM) ) {
+ if ( _dl_pid_exists( pid_read) || (errno == EPERM) ) {
_debug( 2, "_dl_check_lock() locked by %d\n", (int)pid_read);
return pid_read;
}
@@ -443,7 +443,7 @@ _dl_check_lock(const char *lockname)
return -1;
}
fscanf( fd, "%d", &pid2);
- if ( pid2 && (pid2 != pid_read) && ( kill( pid2, 0) == 0 )) {
+ if ( pid2 && (pid2 != pid_read) && _dl_pid_exists(pid2) ) {
/* lock file was changed! let us quickly
* put it back again
*/
@@ -502,6 +502,17 @@ _dl_check_devname (const char *devname)
return strcpy(m, p);
}
+/* for internal use */
+/* correctly check if a process with a given pid exists */
+static inline int
+_dl_pid_exists(pid_t pid)
+{
+ if ( !kill( pid, 0))
+ return 1;
+ if ( errno == ESRCH)
+ return 0;
+ return 1;
+}
/* exported by the interface file lockdev.h */
/* ZERO means that the device wasn't locked, but could have been locked later */
--
1.6.4.2
More information about the lockdev-devel
mailing list