aboutsummaryrefslogtreecommitdiff
path: root/debianutils
diff options
context:
space:
mode:
Diffstat (limited to 'debianutils')
-rw-r--r--debianutils/start_stop_daemon.c40
1 files changed, 17 insertions, 23 deletions
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c
index c5c4059a1..9150763cb 100644
--- a/debianutils/start_stop_daemon.c
+++ b/debianutils/start_stop_daemon.c
@@ -32,7 +32,6 @@ struct globals {
32 int user_id; 32 int user_id;
33 smallint quiet; 33 smallint quiet;
34 smallint signal_nr; 34 smallint signal_nr;
35 struct stat execstat;
36}; 35};
37#define G (*(struct globals*)&bb_common_bufsiz1) 36#define G (*(struct globals*)&bb_common_bufsiz1)
38#define found (G.found ) 37#define found (G.found )
@@ -43,7 +42,6 @@ struct globals {
43#define user_id (G.user_id ) 42#define user_id (G.user_id )
44#define quiet (G.quiet ) 43#define quiet (G.quiet )
45#define signal_nr (G.signal_nr ) 44#define signal_nr (G.signal_nr )
46#define execstat (G.execstat )
47#define INIT_G() \ 45#define INIT_G() \
48 do { \ 46 do { \
49 user_id = -1; \ 47 user_id = -1; \
@@ -53,12 +51,13 @@ struct globals {
53 51
54static int pid_is_exec(pid_t pid) 52static int pid_is_exec(pid_t pid)
55{ 53{
56 struct stat st; 54 struct stat st, execstat;
57 char buf[sizeof("/proc//exe") + sizeof(int)*3]; 55 char buf[sizeof("/proc//exe") + sizeof(int)*3];
58 56
59 sprintf(buf, "/proc/%u/exe", pid); 57 sprintf(buf, "/proc/%u/exe", pid);
60 if (stat(buf, &st) < 0) 58 if (stat(buf, &st) < 0)
61 return 0; 59 return 0;
60 xstat(execname, &execstat);
62 if (st.st_dev == execstat.st_dev 61 if (st.st_dev == execstat.st_dev
63 && st.st_ino == execstat.st_ino) 62 && st.st_ino == execstat.st_ino)
64 return 1; 63 return 1;
@@ -78,24 +77,21 @@ static int pid_is_user(int pid)
78 77
79static int pid_is_cmd(pid_t pid) 78static int pid_is_cmd(pid_t pid)
80{ 79{
81 char fname[sizeof("/proc//stat") + sizeof(int)*3]; 80 char buf[256]; /* is it big enough? */
82 char *buf; 81 char *p, *pe;
83 int r = 0; 82
84 83 sprintf(buf, "/proc/%u/stat", pid);
85 sprintf(fname, "/proc/%u/stat", pid); 84 if (open_read_close(buf, buf, sizeof(buf) - 1) < 0)
86 buf = xmalloc_open_read_close(fname, NULL); 85 return 0;
87 if (buf) { 86 buf[sizeof(buf) - 1] = '\0'; /* paranoia */
88 char *p = strchr(buf, '('); 87 p = strchr(buf, '(');
89 if (p) { 88 if (!p)
90 char *pe = strrchr(++p, ')'); 89 return 0;
91 if (pe) { 90 pe = strrchr(++p, ')');
92 *pe = '\0'; 91 if (!pe)
93 r = !strcmp(p, cmdname); 92 return 0;
94 } 93 *pe = '\0';
95 } 94 return !strcmp(p, cmdname);
96 free(buf);
97 }
98 return r;
99} 95}
100 96
101static void check(int pid) 97static void check(int pid)
@@ -303,8 +299,6 @@ int start_stop_daemon_main(int argc ATTRIBUTE_UNUSED, char **argv)
303 if (errno) 299 if (errno)
304 user_id = xuname2uid(userspec); 300 user_id = xuname2uid(userspec);
305 } 301 }
306 if (execname)
307 xstat(execname, &execstat);
308 302
309 do_procinit(); /* Both start and stop needs to know current processes */ 303 do_procinit(); /* Both start and stop needs to know current processes */
310 304