diff -Nru lockdev-1.0.1.orig/src/lockdev.c lockdev-1.0.1/src/lockdev.c --- lockdev-1.0.1.orig/src/lockdev.c 2004-07-17 19:17:48.000000000 +0300 +++ lockdev-1.0.1/src/lockdev.c 2004-07-17 19:19:07.000000000 +0300 @@ -147,7 +147,7 @@ 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)) @@ -400,7 +400,7 @@ /* checks content's format */ if ( j == 1 ) { /* checks process existence */ - if ( kill( pid_read, 0) == 0 ) { + if ( _dl_pid_exists( pid_read)) { _debug( 2, "_dl_check_lock() locked by %d\n", (int)pid_read); return pid_read; } @@ -449,7 +449,7 @@ 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 */ @@ -501,6 +501,18 @@ return strcpy(m, p); } +/* for internal use */ +/* correctly check if a process with a given pid exists */ +static inline int +_dl_pid_exists( pid) + 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 */