- don't unlock files if pid still exists (#128104)

This commit is contained in:
havill 2004-10-22 16:33:51 +00:00
parent 22e00761a1
commit 303c5bf015
2 changed files with 55 additions and 1 deletions

View File

@ -0,0 +1,49 @@
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 */

View File

@ -1,7 +1,7 @@
Summary: A library for locking devices.
Name: lockdev
Version: 1.0.1
Release: 3
Release: 4
License: LGPL
Group: System Environment/Libraries
Source: http://ftp.debian.org/debian/pool/main/l/lockdev/%{name}_%{version}.orig.tar.gz
@ -10,6 +10,7 @@ Patch1: lockdev-1.0.0-shared.patch
Patch2: lockdev-1.0.0-signal.patch
Patch3: lockdev-1.0.0-cli.patch
Patch4: lockdev-1.0.1-checkname.patch
Patch5: lockdev-1.0.1-pidexists.patch
Prereq: shadow-utils, filesystem >= 2.1.4-1
BuildRoot: %{_tmppath}/%{name}-root
@ -34,6 +35,7 @@ package contains the development headers and a static library.
%patch2 -p1 -b .signal
%patch3 -p1 -b .jbj
%patch4 -p1 -b .checkname
%patch5 -p1 -b .pidexists
%build
make "CFLAGS=${RPM_OPT_FLAGS} -fPIC"
@ -73,6 +75,9 @@ rm -fr $RPM_BUILD_ROOT
%{_includedir}/*
%changelog
* Fri Oct 22 2004 Adrian Havill <havill@redhat.com> 1.0.1-4
- don't unlock files if pid still exists (#128104)
* Tue Jun 15 2004 Elliot Lee <sopwith@redhat.com>
- rebuilt