aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-04-19 21:30:52 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-04-19 21:30:52 +0000
commit85d788e491a1678f5aa5eb0392445c61b218e19b (patch)
tree0e39571b59b8e8d4c5f7070565a734870d9e62e0
parentdaeddee442e1cd7be15da6be472a637b8547fde7 (diff)
downloadbusybox-w32-85d788e491a1678f5aa5eb0392445c61b218e19b.tar.gz
busybox-w32-85d788e491a1678f5aa5eb0392445c61b218e19b.tar.bz2
busybox-w32-85d788e491a1678f5aa5eb0392445c61b218e19b.zip
start_stop_daemon: optimization - do not pass paramenter, use
existing globals instead function old new delta start_stop_daemon_main 792 976 +184 check 1618 1620 +2 do_procinit 196 - -196 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 2/0 up/down: 186/-196) Total: -10 bytes
-rw-r--r--debianutils/start_stop_daemon.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c
index b6b30e7cc..c5c4059a1 100644
--- a/debianutils/start_stop_daemon.c
+++ b/debianutils/start_stop_daemon.c
@@ -65,7 +65,7 @@ static int pid_is_exec(pid_t pid)
65 return 0; 65 return 0;
66} 66}
67 67
68static int pid_is_user(int pid, int uid) 68static int pid_is_user(int pid)
69{ 69{
70 struct stat sb; 70 struct stat sb;
71 char buf[sizeof("/proc/") + sizeof(int)*3]; 71 char buf[sizeof("/proc/") + sizeof(int)*3];
@@ -73,10 +73,10 @@ static int pid_is_user(int pid, int uid)
73 sprintf(buf, "/proc/%u", pid); 73 sprintf(buf, "/proc/%u", pid);
74 if (stat(buf, &sb) != 0) 74 if (stat(buf, &sb) != 0)
75 return 0; 75 return 0;
76 return (sb.st_uid == uid); 76 return (sb.st_uid == user_id);
77} 77}
78 78
79static int pid_is_cmd(pid_t pid, const char *name) 79static int pid_is_cmd(pid_t pid)
80{ 80{
81 char fname[sizeof("/proc//stat") + sizeof(int)*3]; 81 char fname[sizeof("/proc//stat") + sizeof(int)*3];
82 char *buf; 82 char *buf;
@@ -90,7 +90,7 @@ static int pid_is_cmd(pid_t pid, const char *name)
90 char *pe = strrchr(++p, ')'); 90 char *pe = strrchr(++p, ')');
91 if (pe) { 91 if (pe) {
92 *pe = '\0'; 92 *pe = '\0';
93 r = !strcmp(p, name); 93 r = !strcmp(p, cmdname);
94 } 94 }
95 } 95 }
96 free(buf); 96 free(buf);
@@ -105,10 +105,10 @@ static void check(int pid)
105 if (execname && !pid_is_exec(pid)) { 105 if (execname && !pid_is_exec(pid)) {
106 return; 106 return;
107 } 107 }
108 if (userspec && !pid_is_user(pid, user_id)) { 108 if (userspec && !pid_is_user(pid)) {
109 return; 109 return;
110 } 110 }
111 if (cmdname && !pid_is_cmd(pid, cmdname)) { 111 if (cmdname && !pid_is_cmd(pid)) {
112 return; 112 return;
113 } 113 }
114 p = xmalloc(sizeof(*p)); 114 p = xmalloc(sizeof(*p));
@@ -169,8 +169,6 @@ static int do_stop(void)
169 struct pid_list *p; 169 struct pid_list *p;
170 int killed = 0; 170 int killed = 0;
171 171
172 do_procinit();
173
174 if (cmdname) { 172 if (cmdname) {
175 if (ENABLE_FEATURE_CLEAN_UP) what = xstrdup(cmdname); 173 if (ENABLE_FEATURE_CLEAN_UP) what = xstrdup(cmdname);
176 if (!ENABLE_FEATURE_CLEAN_UP) what = cmdname; 174 if (!ENABLE_FEATURE_CLEAN_UP) what = cmdname;
@@ -308,13 +306,13 @@ int start_stop_daemon_main(int argc ATTRIBUTE_UNUSED, char **argv)
308 if (execname) 306 if (execname)
309 xstat(execname, &execstat); 307 xstat(execname, &execstat);
310 308
309 do_procinit(); /* Both start and stop needs to know current processes */
310
311 if (opt & CTX_STOP) { 311 if (opt & CTX_STOP) {
312 int i = do_stop(); 312 int i = do_stop();
313 return (opt & OPT_OKNODO) ? 0 : (i <= 0); 313 return (opt & OPT_OKNODO) ? 0 : (i <= 0);
314 } 314 }
315 315
316 do_procinit();
317
318 if (found) { 316 if (found) {
319 if (!quiet) 317 if (!quiet)
320 printf("%s already running\n%d\n", execname, found->pid); 318 printf("%s already running\n%d\n", execname, found->pid);