39 |
void lockfile_check(void) |
void lockfile_check(void) |
40 |
{ |
{ |
41 |
pid_t n; |
pid_t n; |
|
char lockf[PATH_MAX]; |
|
|
|
|
|
snprintf(lockf, PATH_MAX, "%s/%s", home, ".imapfilter/lock"); |
|
|
lockfile = xstrdup(lockf); |
|
42 |
|
|
43 |
if ((n = lockfile_pid())) { |
if ((n = lockfile_pid())) { |
44 |
errno = 0; |
errno = 0; |
49 |
} else { |
} else { |
50 |
fprintf(stderr, |
fprintf(stderr, |
51 |
"imapfilter: another imapfilter" |
"imapfilter: another imapfilter" |
52 |
"is running with pid %d\n", n); |
"is running with pid %d\n", (int)(n)); |
53 |
exit(ERROR_LOCKFILE); |
exit(ERROR_LOCKFILE); |
54 |
} |
} |
55 |
} |
} |
63 |
pid_t lockfile_pid(void) |
pid_t lockfile_pid(void) |
64 |
{ |
{ |
65 |
char line[LINE_MAX]; |
char line[LINE_MAX]; |
66 |
|
char lockf[PATH_MAX]; |
67 |
FILE *fd; |
FILE *fd; |
68 |
pid_t n = 0; |
pid_t n = 0; |
69 |
|
|
70 |
|
snprintf(lockf, PATH_MAX, "%s/%s", home, ".imapfilter/lock"); |
71 |
|
lockfile = xstrdup(lockf); |
72 |
|
|
73 |
if (exists_file(lockfile)) { |
if (exists_file(lockfile)) { |
74 |
fd = fopen(lockfile, "r"); |
fd = fopen(lockfile, "r"); |
75 |
if (!fd) |
if (!fd) |
115 |
if (n > 0) { |
if (n > 0) { |
116 |
if (kill(n, SIGTERM)) |
if (kill(n, SIGTERM)) |
117 |
fprintf(stderr, "imapfilter: killing process with pid %d; %s\n", |
fprintf(stderr, "imapfilter: killing process with pid %d; %s\n", |
118 |
n, strerror(errno)); |
(int)(n), strerror(errno)); |
119 |
lockfile_remove(); |
lockfile_remove(); |
120 |
exit(0); |
exit(0); |
121 |
} else { |
} else { |