Sophie

Sophie

distrib > Mandriva > 2011.0 > i586 > media > main-updates-src > by-pkgid > 6f0975685283594d0423c1032b8f371c > files > 7

lockdev-1.0.3-12.1.src.rpm

diff -p -up lockdev-1.0.3/src/lockdev.c.pidexists lockdev-1.0.3/src/lockdev.c
--- lockdev-1.0.3/src/lockdev.c.pidexists	2008-03-02 22:36:56.000000000 +0100
+++ lockdev-1.0.3/src/lockdev.c	2008-03-02 22:39:32.000000000 +0100
@@ -148,7 +148,7 @@ static inline	int	_dl_lock_semaphore	( v
 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
 			 */
@@ -501,6 +501,18 @@ _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)
+	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 */