12 #include <sys/types.h>
17 WvLockDev::WvLockDev(
WvString _devicename)
18 : devicename(_devicename)
20 const char *p = strrchr(devicename,
'/');
27 filename =
WvString(
"/var/lock/serial/LCK..%s", p);
31 WvLockDev::~WvLockDev()
45 bool WvLockDev::lock()
53 if (dev_lock(devicename))
61 void WvLockDev::unlock()
63 if (!lock_count)
return;
66 dev_unlock(devicename, getpid());
79 bool WvLockDev::lock()
89 WvFile fd(filename, O_RDWR | O_EXCL | O_CREAT, 0644);
94 fd.print(
"%10s\n", getpid());
96 else if (fd.geterr() == EEXIST)
103 fd.open(filename, O_RDONLY);
115 if (pid && pid != -1 && kill(pid, 0) == -1 && errno == ESRCH)
119 if (unlink(filename))
121 fd.open(filename, O_RDWR | O_EXCL | O_CREAT, 0644);
122 fd.print(
"%10s\n", getpid());
136 void WvLockDev::unlock()
138 if (!lock_count)
return;