Revision 13fd9e7e
Added stop command and fixed pid file deletion
mainbox/util.c | ||
---|---|---|
20 | 20 |
|
21 | 21 |
fd = open(filename, O_RDONLY); |
22 | 22 |
if (fd < 0) { |
23 |
log_perror("open");
|
|
23 |
log_perror(filename);
|
|
24 | 24 |
return NULL; |
25 | 25 |
} |
26 | 26 |
|
... | ... | |
57 | 57 |
/* |
58 | 58 |
* create_pid_file |
59 | 59 |
* |
60 |
* Creates /var/run/tooltron.pid containing the PID of the current process. |
|
61 |
* Returns 0 if successful, or nonzero if there is an error or it already |
|
62 |
* exists. |
|
60 |
* Creates PIDFILE containing the PID of the current process. Returns 0 if |
|
61 |
* successful, or nonzero if there is an error or it already exists. |
|
63 | 62 |
*/ |
64 | 63 |
int create_pid_file() { |
65 | 64 |
int fd; |
66 | 65 |
FILE *file; |
67 | 66 |
|
68 |
fd = open("/var/run/tooltron.pid", O_CREAT | O_EXCL | O_WRONLY, 0644);
|
|
67 |
fd = open(PIDFILE, O_CREAT | O_EXCL | O_WRONLY, 0644);
|
|
69 | 68 |
if (fd < 0) { |
70 | 69 |
if (errno == EEXIST) |
71 | 70 |
fprintf(stderr, "ERROR: tooltron is already running, or the pidfile " |
72 |
"/var/run/tooltron.pid is stale");
|
|
71 |
PIDFILE "is stale");
|
|
73 | 72 |
else |
74 |
log_perror("open");
|
|
73 |
log_perror(PIDFILE);
|
|
75 | 74 |
return 1; |
76 | 75 |
} |
77 | 76 |
|
... | ... | |
90 | 89 |
/* |
91 | 90 |
* remove_pid_file |
92 | 91 |
* |
93 |
* Removes /var/run/tooltron.pid.
|
|
92 |
* Removes PIDFILE.
|
|
94 | 93 |
*/ |
95 | 94 |
void remove_pid_file() { |
96 |
if (unlink("/var/run/tooltron.pid"))
|
|
97 |
log_perror("unlink");
|
|
95 |
if (unlink(PIDFILE))
|
|
96 |
log_perror(PIDFILE);
|
|
98 | 97 |
} |
99 | 98 |
|
100 | 99 |
/* |
101 | 100 |
* read_pid_file |
102 | 101 |
* |
103 |
* Returns the integer found in /var/run/tooltron.pid, or 0 if there was an
|
|
102 |
* Returns the integer found in PIDFILE, or 0 if there was an
|
|
104 | 103 |
* error. |
105 | 104 |
*/ |
106 | 105 |
pid_t read_pid_file() { |
107 | 106 |
FILE *file; |
108 | 107 |
int pid; |
109 | 108 |
|
110 |
file = fopen("/var/run/tooltron.pid", "r");
|
|
109 |
file = fopen(PIDFILE, "r");
|
|
111 | 110 |
if (!file) { |
112 | 111 |
if (errno == ENOENT) |
113 | 112 |
fprintf(stderr, "ERROR: tooltron does not appear to be running\n"); |
114 | 113 |
else |
115 |
perror("fopen");
|
|
114 |
perror(PIDFILE);
|
|
116 | 115 |
return 0; |
117 | 116 |
} |
118 | 117 |
|
Also available in: Unified diff