/[pengfork]/pengfork/src/modem/devlock.c
ViewVC logotype

Diff of /pengfork/src/modem/devlock.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by chupa, Sun Dec 1 01:19:07 2002 UTC revision 1.4 by chupa, Mon Dec 2 15:57:12 2002 UTC
# Line 31  Line 31 
31  #include <unistd.h>  #include <unistd.h>
32  #include <fcntl.h>  #include <fcntl.h>
33  #include <signal.h>  #include <signal.h>
34    #include <errno.h>
35    
36  #include "modem/devlock.h"  #include "modem/devlock.h"
37  #include "log.h"  #include "log.h"
38  #include "gettext.h"  #include "gettext.h"
39    
40    int fd=-1;
41    
42  /* note: this function uses the O_EXCL flag to open(), and thus assumes  /* note: this function uses the O_EXCL flag to open(), and thus assumes
43     that /var/lock is not an NFS-mounted drive (according to the open() man     that /var/lock is not an NFS-mounted drive (according to the open() man
44     page, you need to follow a special procedure to ensure successful NFS     page, you need to follow a special procedure to ensure successful NFS
# Line 49  device_lock (devicename) Line 52  device_lock (devicename)
52  {  {
53    char *p;    char *p;
54    pid_t pid;    pid_t pid;
55    int fd, r;    int r;
56    char pid_string[15];    char pid_string[15];
57    char filename[256];    char filename[256];
58    
# Line 59  device_lock (devicename) Line 62  device_lock (devicename)
62    else    else
63      p = devicename;      p = devicename;
64    
65    snprintf (filename, 255, "/var/lock/LCK..%s", p);    snprintf (filename, sizeof(filename), "/var/lock/LCK..%s", p);
66    
67    fd = open (filename, O_RDWR | O_EXCL | O_CREAT, 0644);    fd = open (filename, O_RDWR | O_EXCL | O_CREAT, 0644);
68    
# Line 114  device_unlock (devicename) Line 117  device_unlock (devicename)
117    else    else
118      p = devicename;      p = devicename;
119    
120    snprintf (filename, 255, "/var/lock/LCK..%s", p);    snprintf (filename, sizeof(filename), "/var/lock/LCK..%s", p);
121      if( fd != -1)
122        close(fd);
123      fd=-1;
124    
125    if (unlink (filename))    if (unlink (filename))
126      return 0;      {
127          log (LOG_WARNING, gettext ("Couldn't remove lock file %s: %s (%d)..\n"),
128             filename, strerror(errno), errno);
129          return 0;
130        }
131    return 1;    return 1;
132  }  }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26