69 |
if (fd != -1) |
if (fd != -1) |
70 |
{ |
{ |
71 |
/* We made a lock file... */ |
/* We made a lock file... */ |
72 |
sprintf (pid_string, "%10d\n", getpid ()); |
snprintf (pid_string, sizeof(pid_string), "%10d\n", getpid ()); |
73 |
write (fd, pid_string, strlen (pid_string)); |
write (fd, pid_string, strlen (pid_string)); |
74 |
} |
} |
75 |
else |
else |
78 |
sleep (1); /* preventing race condition... */ |
sleep (1); /* preventing race condition... */ |
79 |
|
|
80 |
fd = open (filename, O_RDONLY); |
fd = open (filename, O_RDONLY); |
81 |
r = read (fd, pid_string, 15); |
r = read (fd, pid_string, sizeof(pid_string) - 1); |
82 |
pid_string[r] = '\0'; |
pid_string[r] = '\0'; |
83 |
pid = atoi (pid_string); |
pid = atoi (pid_string); |
84 |
|
|
89 |
log (LOG_WARNING, gettext ("Removing stale lock file %s.\n"), filename); |
log (LOG_WARNING, gettext ("Removing stale lock file %s.\n"), filename); |
90 |
if (unlink (filename)) |
if (unlink (filename)) |
91 |
{ |
{ |
92 |
perror (filename); |
log (LOG_ERR, gettext("Can't remove %s: %s (%d).\n"), |
93 |
|
filename, strerror(errno), errno); |
94 |
return 0; /* cannot remove lockfile */ |
return 0; /* cannot remove lockfile */ |
95 |
} |
} |
96 |
fd = open (filename, O_RDWR | O_EXCL | O_CREAT, 0644); |
fd = open (filename, O_RDWR | O_EXCL | O_CREAT, 0644); |
97 |
sprintf (pid_string, "%10d\n", getpid ()); |
snprintf (pid_string, sizeof(pid_string), "%10d\n", getpid ()); |
98 |
write (fd, pid_string, strlen (pid_string)); |
write (fd, pid_string, strlen (pid_string)); |
99 |
} |
} |
100 |
else |
else |