On Sun, Oct 02, 2005 at 05:40:18PM +0100, Roger Leigh wrote: > > Attached is a patch to do this. It > > 1) If the device name starts with "/dev/", it strips off "/dev" rather > than all directories. > 2) When creating the lock name, it replaces any '/'s with '.'s. Thus > /dev/pts/2 would become /pts/2, which would be written as > /var/lock/LCK...pts/2 which would be transformed to > /var/lock/LCK...pts.2
Sorry, the patch is really attached this time.
--
Roger Leigh
Printing on GNU/Linux? http://gimp-print.sourceforge.net/
Debian GNU/Linux http://www.debian.org/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
--- lockdev-1.0.1.original/src/lockdev.c 2005-10-02 10:39:56.000000000
+0100
+++ lockdev-1.0.1/src/lockdev.c 2005-10-02 17:08:14.661905805 +0100
@@ -235,11 +235,15 @@
char * name;
const char * dev;
{
- int l;
+ int l, i;
_debug( 3, "_dl_filename_2 (dev=%s)\n", dev);
/* lockfile of type /var/lock/LCK..ttyS2 */
l = sprintf( name, "%s/LCK..%s", LOCK_PATH, dev);
_debug( 2, "_dl_filename_2 () -> len=%d, name=%s<\n", l, name);
+ for (i=strlen(LOCK_PATH)+1; name[i] != '\0'; ++i) {
+ if (name[i] == '/')
+ name[i] = '.';
+ }
return l;
}
@@ -477,11 +481,19 @@
* maybe we should check it and do something if not?
*/
p = devname; /* only a filename */
- while ( (m=strrchr( p, '/')) != 0 ) {
- p = m+1; /* was pointing to the slash */
- _debug( 3, "_dl_check_devname(%s) name = %s\n", devname, p);
- if ( strcmp( p, "tty") == 0 )
- p = ttyname( 0); /* this terminal, if it exists */
+ /* If the device is located under /dev/, strip off /dev. */
+ _debug( 3, "_dl_check_devname(%s) strip name = %s\n", devname,
DEV_PATH);
+ if (strncmp(DEV_PATH, p, strlen(DEV_PATH)) == 0) {
+ p += 4;
+ _debug( 3, "_dl_check_devname(%s) stripped name = %s\n",
devname, p);
+ } else {
+ /* Otherwise, strip of everything but the device name. */
+ while ( (m=strrchr( p, '/')) != 0 ) {
+ p = m+1; /* was pointing to the slash */
+ _debug( 3, "_dl_check_devname(%s) name = %s\n",
devname, p);
+ if ( strcmp( p, "tty") == 0 )
+ p = ttyname( 0); /* this terminal, if it exists
*/
+ }
}
if ( ((l=strlen( p)) == 0 ) || ( l > (MAXPATHLEN - strlen(LOCK_PATH)) ))
return 0;
signature.asc
Description: Digital signature

