10 |
|
|
11 |
|
|
12 |
extern char *home; |
extern char *home; |
13 |
|
|
14 |
static char *lockfile = NULL; /* Lock file to stop new |
static char *lockfile = NULL; /* Lock file to stop new imapfilter |
15 |
imapfilter processes. */ |
processes. */ |
16 |
|
|
17 |
|
|
18 |
/* |
/* |
28 |
if (!fd) |
if (!fd) |
29 |
fatal(ERROR_FILE_OPEN, "imapfilter: opening lockfile; %s\n", |
fatal(ERROR_FILE_OPEN, "imapfilter: opening lockfile; %s\n", |
30 |
strerror(errno)); |
strerror(errno)); |
31 |
fputs(ultostr(getpid(), 10), fd); |
fprintf(fd, "%s\n", ultostr(getpid(), 10)); |
32 |
fclose(fd); |
fclose(fd); |
33 |
} |
} |
34 |
|
|
42 |
|
|
43 |
if ((n = lockfile_pid())) { |
if ((n = lockfile_pid())) { |
44 |
fprintf(stderr, |
fprintf(stderr, |
45 |
"imapfilter: another imapfilter is running with pid %d\n", n); |
"imapfilter: another imapfilter is running with pid %d\n", n); |
46 |
exit(ERROR_LOCKFILE); |
exit(ERROR_LOCKFILE); |
47 |
} |
} |
48 |
} |
} |
58 |
char line[LINE_MAX]; |
char line[LINE_MAX]; |
59 |
FILE *fd; |
FILE *fd; |
60 |
pid_t n = 0; |
pid_t n = 0; |
61 |
|
|
62 |
snprintf(lockf, PATH_MAX, "%s/%s", home, ".imapfilter/lock"); |
snprintf(lockf, PATH_MAX, "%s/%s", home, ".imapfilter/lock"); |
63 |
lockfile = xstrdup(lockf); |
lockfile = xstrdup(lockf); |
64 |
|
|
65 |
if (exists_file(lockfile)) { |
if (exists_file(lockfile)) { |
66 |
fd = fopen(lockfile, "r"); |
fd = fopen(lockfile, "r"); |
67 |
if (!fd) |
if (!fd) |
75 |
} |
} |
76 |
fclose(fd); |
fclose(fd); |
77 |
} |
} |
|
|
|
78 |
return n; |
return n; |
79 |
} |
} |
80 |
|
|
86 |
{ |
{ |
87 |
if (!lockfile) |
if (!lockfile) |
88 |
return 0; |
return 0; |
89 |
|
|
90 |
if (remove(lockfile)) { |
if (remove(lockfile)) { |
91 |
error("imapfilter: removing lockfile; %s\n", strerror(errno)); |
error("imapfilter: removing lockfile; %s\n", strerror(errno)); |
92 |
return ERROR_FILE_OPEN; |
return ERROR_FILE_OPEN; |
93 |
} |
} |
|
|
|
94 |
xfree(lockfile); |
xfree(lockfile); |
95 |
|
|
96 |
return 0; |
return 0; |
97 |
} |
} |
98 |
|
|
105 |
pid_t n; |
pid_t n; |
106 |
|
|
107 |
n = lockfile_pid(); |
n = lockfile_pid(); |
108 |
|
|
109 |
if (n > 0) { |
if (n > 0) { |
110 |
if (kill(n, SIGTERM)) |
if (kill(n, SIGTERM)) |
111 |
fprintf(stderr, "imapfilter: killing process with pid %d; %s\n", |
fprintf(stderr, "imapfilter: killing process with pid %d; %s\n", |