diff --git a/lockdev-1.0.0-rh.patch b/lockdev-1.0.0-rh.patch new file mode 100644 index 0000000..b71c652 --- /dev/null +++ b/lockdev-1.0.0-rh.patch @@ -0,0 +1,336 @@ +--- lockdev-1.0.0/src/sample.c.rh Wed Dec 1 06:50:09 1999 ++++ lockdev-1.0.0/src/sample.c Thu Aug 9 22:46:37 2001 +@@ -3,27 +3,26 @@ + + void + usage() { +- fprintf( stderr, "Usage: sample [-lurd] \n" ); +- exit( -1 ); ++ fprintf(stderr, "Usage: %s [-lud] \n", "lockdev"); ++ exit(-1); + } + + int debug; + + + int +-main( int argc, char *argv[] ) ++main(int argc, char *argv[]) + { + int i, chld; +- char *p, *dev, ch; ++ char *p = NULL, *dev = NULL, ch; + + ch = '\0'; +- for( i = argc - 1; i > 0; i-- ) { ++ for(i = argc - 1; i > 0; i--) { + p = argv[i]; +- if( *p == '-' ) { +- switch( *++p ) { ++ if (*p == '-') { ++ switch(*++p) { + case 'l': +- case 'u': +- case 'r': ch = *p; break; ++ case 'u': ch = *p; break; + case 'd': + debug = atoi(++p); + break; +@@ -32,31 +31,20 @@ + } + else dev = p; + } +- fprintf( stderr, "option %c, device %s\n", ch, dev ); + i = 0; +- switch( ch ) { ++ (void) dev_setpid(getppid()); ++ switch(ch) { + case 'l': +- i = dev_lock( dev); ++ i = dev_lock(dev); + break; + case 'u': +- i = dev_unlock( dev, 0); +- break; +- case 'r': +- dev_lock( dev); +- if(( chld = fork()) == 0 ) { +- sleep(5); +- } +- else { +- sleep( 1); +- if (( i = dev_relock( dev, chld)) < 0 ) { +- fprintf( stderr, "Relock failed in parent.\n" ); +- } +- } ++ i = dev_unlock(dev, 0); + break; + default: +- i = dev_testlock( dev); ++ if (dev) ++ i = dev_testlock(dev); + break; + } +- exit( i); ++ exit(i); + } + +--- lockdev-1.0.0/src/lockdev.c.rh Wed Dec 1 06:43:47 1999 ++++ lockdev-1.0.0/src/lockdev.c Thu Aug 9 22:48:42 2001 +@@ -176,6 +176,19 @@ + liblockdev_debug = 0; + } + ++static pid_t dev_pid = 0; ++ ++pid_t dev_getpid(void) ++{ ++ return (dev_pid ? dev_pid : getpid()); ++} ++ ++pid_t dev_setpid(pid_t newpid) ++{ ++ pid_t oldpid = dev_pid; ++ dev_pid = newpid; ++ return oldpid; ++} + + /* + * for internal use * +@@ -429,7 +442,7 @@ + * maybe also this sprintf should be added to the + * conditional part, as the others + */ +- sprintf( tpname, "%s/.%d", LOCK_PATH, (int)getpid()); ++ sprintf( tpname, "%s/.%d", LOCK_PATH, (int)dev_getpid()); + unlink( tpname); /* in case there was */ + rename( lockname, tpname); + if ( ! (fd=fopen( tpname, "r")) ) { +@@ -586,7 +599,7 @@ + #endif /* DEBUG */ + _debug( 3, "dev_lock(%s)\n", devname); + if (oldmask == -1 ) +- oldmask = umask( 0); /* give full permissions to files created */ ++ oldmask = umask( 002); + if ( ! (p=_dl_check_devname( devname)) ) + close_n_return( -1); + strcpy( device, DEV_PATH); +@@ -599,9 +612,12 @@ + if ( stat( device, &statbuf) == -1 ) { + close_n_return( -1); + } ++ if ( access( device, W_OK ) == -1 ) { ++ close_n_return( -1); ++ } + + /* now get our own pid */ +- our_pid = getpid(); ++ our_pid = dev_getpid(); + _debug( 2, "dev_lock() our own pid = %d\n", (int)our_pid); + + /* We will use this algorithm: +@@ -742,7 +758,7 @@ + #endif /* DEBUG */ + _debug( 3, "dev_relock(%s, %d)\n", devname, (int)old_pid); + if (oldmask == -1 ) +- oldmask = umask( 0); /* give full permissions to files created */ ++ oldmask = umask( 002); + if ( ! (p=_dl_check_devname( devname)) ) + close_n_return( -1); + strcpy( device, DEV_PATH); +@@ -755,9 +771,11 @@ + if ( stat( device, &statbuf) == -1 ) { + close_n_return( -1); + } +- ++ if ( access( device, W_OK ) == -1 ) { ++ close_n_return( -1); ++ } + /* now get our own pid */ +- our_pid = getpid(); ++ our_pid = dev_getpid(); + _debug( 2, "dev_relock() our own pid = %d\n", (int)our_pid); + + /* first check for the FSSTND-1.2 lock, get the pid of the +@@ -828,7 +846,7 @@ + #endif /* DEBUG */ + _debug( 3, "dev_unlock(%s, %d)\n", devname, (int)pid); + if (oldmask == -1 ) +- oldmask = umask( 0); /* give full permissions to files created */ ++ oldmask = umask( 002); + if ( ! (p=_dl_check_devname( devname)) ) + close_n_return( -1); + strcpy( device, DEV_PATH); +@@ -841,7 +859,10 @@ + if ( stat( device, &statbuf) == -1 ) { + close_n_return( -1); + } +- ++ if ( access( device, W_OK ) == -1 ) { ++ close_n_return( -1); ++ } ++ + /* first remove the FSSTND-1.2 lock, get the pid of the + * owner of the lock and test for its existence; in case, + * return the pid of the owner of the lock. +--- lockdev-1.0.0/src/lockdev.h.rh Wed Dec 1 06:39:42 1999 ++++ lockdev-1.0.0/src/lockdev.h Thu Aug 9 22:46:37 2001 +@@ -60,6 +60,9 @@ + void liblockdev_incr_debug __P(()); + void liblockdev_reset_debug __P(()); + ++pid_t dev_getpid __P(( void )); ++pid_t dev_setpid __P(( pid_t pid )); ++ + pid_t dev_testlock __P(( const char * devname)); + + pid_t dev_lock __P(( const char * devname)); +--- lockdev-1.0.0/src/baudboy.h.rh Thu Aug 9 22:46:37 2001 ++++ lockdev-1.0.0/src/baudboy.h Thu Aug 9 22:46:37 2001 +@@ -0,0 +1,82 @@ ++#ifndef _BADUBOY_H_ ++#define _BAUDBOY_H_ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#ifdef __cplusplus ++extern "C" { ++#endif ++ ++#define LOCKDEV_PATH "/usr/sbin/lockdev" ++ ++static inline int doit(const char * argv[]) ++{ ++ pid_t child; ++ int status; ++ void (*osig) (int) = signal(SIGCHLD, SIG_IGN); ++ int rc; ++ ++ if (!(child = fork())) { ++ int fd; ++ /* these have to be open to something */ ++ if ((fd = open("/dev/null", 2)) < 0) ++ exit(-1); ++ dup2(fd, 0); ++ dup2(fd, 1); ++ dup2(fd, 2); ++ execv(argv[0], (char *const *)argv); ++ exit(-1); ++ } ++ ++ rc = (int) waitpid(child, &status, 0); ++ signal(SIGCHLD, osig); ++ if (rc == child && WIFEXITED(status)) { ++ rc = WEXITSTATUS(status); ++ if (rc == 255) rc = -1; ++ } else ++ rc = -1; ++ ++ return rc; ++ ++} ++ ++static inline int ttylock(const char * devname) ++{ ++ const char * argv[] = { LOCKDEV_PATH, "-l", NULL, NULL}; ++ argv[2] = devname; ++ return doit(argv); ++} ++ ++static inline int ttyunlock(const char * devname) ++{ ++ const char * argv[] = { LOCKDEV_PATH, "-u", NULL, NULL}; ++ argv[2] = devname; ++ return doit(argv); ++} ++ ++static inline int ttylocked(const char * devname) ++{ ++ const char * argv[] = { LOCKDEV_PATH, NULL, NULL}; ++ argv[1] = devname; ++ return doit(argv); ++} ++ ++static inline int ttywait(const char * devname) ++{ ++ int rc; ++ while((rc = ttylocked(devname)) == 0) ++ sleep(1); ++ return rc; ++} ++ ++#ifdef __cplusplus ++}; ++#endif ++ ++#endif /* _BAUDBOY_H_ */ +--- lockdev-1.0.0/Makefile.rh Wed Dec 1 05:56:22 1999 ++++ lockdev-1.0.0/Makefile Thu Aug 9 22:46:37 2001 +@@ -6,6 +6,8 @@ + + objs = src/lockdev.o + ++lockdev = src/sample.c ++ + + VER = $(shell expr `pwd` : '.*-\([0-9.]*\)') + MVER = ${shell expr `pwd` : '.*-\([0-9]*\).[0-9]*'} +@@ -18,17 +20,18 @@ + basedir = /usr/local + srcdir=. + ++sbindir = ${basedir}/sbin + libdir = ${basedir}/lib + incdir = ${basedir}/include + mandir = ${basedir}/share/man + + CC = gcc +-LCFLAGS = -g -O2 -fPIC -Wall -pipe -D_REENTRANT +-CFLAGS = -g ++CFLAGS = -g -O2 -Wall -pipe ++LCFLAGS = ${CFLAGS} -fPIC -D_REENTRANT + LDLIBS = -llockdev + + .PHONY: shared static perl-lib +-ALL: shared static perl-lib ++ALL: shared static lockdev perl-lib + + static ${static}: ${objs} + $(AR) $(ARFLAGS) ${static} $^ +@@ -36,6 +39,11 @@ + shared ${shared}: ${objs} + ${CC} ${LCFLAGS} -shared -Wl,-soname,${soname} $^ -lc -o ${shared} + ++lockdev.o: ${lockdev} ++ ${CC} ${CFLAGS} -I./src -o $@ -c $^ ++ ++lockdev: lockdev.o ${static} ++ ${CC} -o $@ $^ + + perl-lib: static + cd LockDev && perl Makefile.PL INSTALLDIRS=perl +@@ -51,6 +59,7 @@ + install -m755 -d ${incdir} + install -m644 src/lockdev.h ${incdir} + install -m644 src/ttylock.h ${incdir} ++ install -m644 src/baudboy.h ${incdir} + + install_debug: ${static} ${shared} + install -m755 -d ${libdir}/debug +@@ -68,7 +77,9 @@ + + install_run: ${shared} + install -m755 -d ${libdir} +- install -m644 ${shared} ${libdir} ++ install -m755 ${shared} ${libdir} ++ install -m755 -d ${sbindir} ++ install -m755 lockdev ${sbindir} + + .PHONY: clean distclean perl-clean mostyclean + perl-clean: clean diff --git a/lockdev.spec b/lockdev.spec index 524195e..8ab8b23 100644 --- a/lockdev.spec +++ b/lockdev.spec @@ -1,41 +1,48 @@ -Summary: A library for locking devices +Summary: A library for locking devices. Name: lockdev Version: 1.0.0 -Release: 6 +Release: 10 Copyright: LGPL -Group: System Environment/Libraries +Group: System Environment/Libraries Source: ftp://ftp.debian.org/debian/dists/woody/main/source/libs/lockdev_1.0.0.tar.gz -Buildroot: %{_tmppath}/%{name}-%{version}-root +Patch0: lockdev-1.0.0-rh.patch +Prereq: shadow-utils, filesystem >= 2.1.4-1 +BuildRoot: %{_tmppath}/%{name}-root %description - Lockdev provides a reliable way to put an exclusive lock to devices -using both FSSTND and SVr4 methods. - +using both FSSTND and SVr4 methods. %package -n lockdev-devel -Summary: headers and a static library for lockdev -Group: System Environment/Libraries +Summary: The header files and a static library for the lockdev library. +Group: System Environment/Libraries +Requires: lockdev = %{version} %description -n lockdev-devel -Lockdev provides a reliable way to put an exclusive lock to devices -using both FSSTND and SVr4 methods. The -devel package contains the -development headers and a static library. - +The lockdev library provides a reliable way to put an exclusive lock +on devices using both FSSTND and SVr4 methods. The lockdev-devel +package contains the development headers and a static library. %prep - %setup -q +%patch0 -p1 -b .rh %build -make +make "CFLAGS=${RPM_OPT_FLAGS}" %install rm -fr $RPM_BUILD_ROOT -make basedir=$RPM_BUILD_ROOT/usr mandir=$RPM_BUILD_ROOT/%{_mandir} install -mkdir -p $RPM_BUILD_ROOT/lib -mv $RPM_BUILD_ROOT/usr/lib/*so* $RPM_BUILD_ROOT/lib/ +make \ + sbindir=${RPM_BUILD_ROOT}%{_sbindir} \ + libdir=${RPM_BUILD_ROOT}%{_libdir} \ + incdir=${RPM_BUILD_ROOT}%{_includedir} \ + mandir=${RPM_BUILD_ROOT}%{_mandir} \ + install +mkdir -p $RPM_BUILD_ROOT/var/lock + +%pre +groupadd -g 54 -r -f lock %post -p /sbin/ldconfig %postun -p /sbin/ldconfig @@ -45,15 +52,32 @@ rm -fr $RPM_BUILD_ROOT %files %defattr(-,root,root) -%{_mandir}/*/* -/lib/* +%attr(2755,root,lock) %{_sbindir}/lockdev +%dir %attr(775,root,lock) /var/lock +%{_libdir}/*so* -%files -n lockdev-devel +%files devel %defattr(-,root,root) -/usr/include/* -/usr/lib/* +%{_libdir}/*.a +%{_mandir}/man*/* +%{_includedir}/* %changelog +* Thu Aug 9 2001 Bill Nottingham +- check that we can open the device r/w before locking +- fix calling lockdev without any arguments +- fix waitpid() call in baudboy.h +- use umask(002), not umask(0) + +* Wed Aug 8 2001 Bill Nottingham +- add lock group here, own /var/lock as well + +* Sun Aug 5 2001 Jeff Johnson +- include setgid helper binary and baudboy.h. + +* Mon Jun 18 2001 Trond Eivind Glomsrød +- Make the -devel depend on the main package + * Sun Aug 06 2000 Trond Eivind Glomsrød - rebuild