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 |
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 |
|
|
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 |
|
|
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 |
} |
} |