aboutsummaryrefslogtreecommitdiff
path: root/debianutils
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-04-20 01:27:59 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-04-20 01:27:59 +0000
commit25cfe4996ec967e19283f6b66c45cf220a615528 (patch)
treee8ff708534af65f0cdf6739d04496969d4a0ddb5 /debianutils
parent5b3adae7e844f87febdcae15e0f3a652839fe750 (diff)
downloadbusybox-w32-25cfe4996ec967e19283f6b66c45cf220a615528.tar.gz
busybox-w32-25cfe4996ec967e19283f6b66c45cf220a615528.tar.bz2
busybox-w32-25cfe4996ec967e19283f6b66c45cf220a615528.zip
libbb: prevent xmalloc_open_read_close from dying on seek failure
start_stop_daemon: use open_read_close instead of xmalloc_open_read_close start_stop_daemon: use local structure instead of global one function old new delta check 1620 1661 +41 xmalloc_open_read_close 171 190 +19 start_stop_daemon_main 976 954 -22 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 60/-22) Total: 38 bytes
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