1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
| | From 67d7308ba52d2c605d0175c14c34ff09c9d322fb Mon Sep 17 00:00:00 2001
From: Yin Kangkai <yinkangkai@xiaomi.com>
Date: Sat, 1 Oct 2016 13:52:58 +0800
Subject: [PATCH] Fix segfault when run as normal user
Also exit immediately when "restartd -h"
---
restartd.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/restartd.c b/restartd.c
index 2aa720c..1d46fe1 100644
--- a/restartd.c
+++ b/restartd.c
@@ -118,6 +118,7 @@ int main(int argc, char *argv[])
" -i <interval_sec>: the check interval in second\n"
" -l : list configuration options\n"
" -h : help\n\n", VERSION);
+ exit(0);
}
}
@@ -187,6 +188,10 @@ int main(int argc, char *argv[])
}
out_proc = fopen("/var/run/restartd.pid", "wt");
+ if (!out_proc) {
+ syslog(LOG_ERR, "Failed to open /var/run/restartd.pid");
+ return -1;
+ }
fprintf(out_proc, "%d", getpid());
fclose(out_proc);
@@ -244,9 +249,9 @@ int main(int argc, char *argv[])
if (strlen(config_process[i].processes) > 0) {
if (strlen(config_process[i].running) > 0) {
strcpy(config_process[i].status, "running");
- syslog(LOG_INFO, "%s is running, executing '%s'",
+ /* syslog(LOG_INFO, "%s is running, executing '%s'",
config_process[i].name,
- config_process[i].running);
+ config_process[i].running); */
system(config_process[i].running);
} else {
strcpy(config_process[i].status, "running");
|