39 |
void lockfile_check(void) |
void lockfile_check(void) |
40 |
{ |
{ |
41 |
pid_t n; |
pid_t n; |
42 |
|
char lockf[PATH_MAX]; |
43 |
|
|
44 |
|
snprintf(lockf, PATH_MAX, "%s/%s", home, ".imapfilter/lock"); |
45 |
|
lockfile = xstrdup(lockf); |
46 |
|
|
47 |
if ((n = lockfile_pid())) { |
if ((n = lockfile_pid())) { |
48 |
fprintf(stderr, |
errno = 0; |
49 |
"imapfilter: another imapfilter is running with pid %d\n", n); |
kill(n, 0); |
50 |
exit(ERROR_LOCKFILE); |
if (errno == ESRCH) { /* Process does not exist. */ |
51 |
|
fprintf(stderr, "imapfilter: removing stale lockfile\n"); |
52 |
|
lockfile_remove(); |
53 |
|
} else { |
54 |
|
fprintf(stderr, |
55 |
|
"imapfilter: another imapfilter" |
56 |
|
"is running with pid %d\n", n); |
57 |
|
exit(ERROR_LOCKFILE); |
58 |
|
} |
59 |
} |
} |
60 |
} |
} |
61 |
|
|
66 |
*/ |
*/ |
67 |
pid_t lockfile_pid(void) |
pid_t lockfile_pid(void) |
68 |
{ |
{ |
|
char lockf[PATH_MAX]; |
|
69 |
char line[LINE_MAX]; |
char line[LINE_MAX]; |
70 |
FILE *fd; |
FILE *fd; |
71 |
pid_t n = 0; |
pid_t n = 0; |
72 |
|
|
|
snprintf(lockf, PATH_MAX, "%s/%s", home, ".imapfilter/lock"); |
|
|
lockfile = xstrdup(lockf); |
|
|
|
|
73 |
if (exists_file(lockfile)) { |
if (exists_file(lockfile)) { |
74 |
fd = fopen(lockfile, "r"); |
fd = fopen(lockfile, "r"); |
75 |
if (!fd) |
if (!fd) |
99 |
error("imapfilter: removing lockfile; %s\n", strerror(errno)); |
error("imapfilter: removing lockfile; %s\n", strerror(errno)); |
100 |
return ERROR_FILE_OPEN; |
return ERROR_FILE_OPEN; |
101 |
} |
} |
|
xfree(lockfile); |
|
|
|
|
102 |
return 0; |
return 0; |
103 |
} |
} |
104 |
|
|