summaryrefslogtreecommitdiff
path: root/debianutils
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-02-26 22:47:42 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-02-26 22:47:42 +0000
commitcce38586aee7fe892ca1c837ee08a96bd3454ee9 (patch)
tree2cce1db0f921fdc3e899641dd9c59f459ce4b07d /debianutils
parentf8ea0f3a66559a00c41fd7877bdc241973a60f8c (diff)
downloadbusybox-w32-cce38586aee7fe892ca1c837ee08a96bd3454ee9.tar.gz
busybox-w32-cce38586aee7fe892ca1c837ee08a96bd3454ee9.tar.bz2
busybox-w32-cce38586aee7fe892ca1c837ee08a96bd3454ee9.zip
start_stop_daemon: add -chuid support
Diffstat (limited to 'debianutils')
-rw-r--r--debianutils/start_stop_daemon.c51
1 files changed, 29 insertions, 22 deletions
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c
index eb2427a50..1862f113d 100644
--- a/debianutils/start_stop_daemon.c
+++ b/debianutils/start_stop_daemon.c
@@ -14,12 +14,11 @@
14 14
15static int signal_nr = 15; 15static int signal_nr = 15;
16static int user_id = -1; 16static int user_id = -1;
17static int quiet;
18static char *userspec; 17static char *userspec;
19static char *chuid;
20static char *cmdname; 18static char *cmdname;
21static char *execname; 19static char *execname;
22static char *pidfile; 20static char *pidfile;
21static smallint quiet;
23 22
24struct pid_list { 23struct pid_list {
25 struct pid_list *next; 24 struct pid_list *next;
@@ -222,20 +221,28 @@ static const struct option long_options[] = {
222enum { 221enum {
223 CTX_STOP = 0x1, 222 CTX_STOP = 0x1,
224 CTX_START = 0x2, 223 CTX_START = 0x2,
225 OPT_BACKGROUND = 0x4, 224 OPT_BACKGROUND = 0x4, // -b
226 OPT_QUIET = 0x8, 225 OPT_QUIET = 0x8, // -q
227 OPT_MAKEPID = 0x10, 226 OPT_MAKEPID = 0x10, // -m
228 OPT_OKNODO = 0x20 * ENABLE_FEATURE_START_STOP_DAEMON_FANCY, 227 OPT_a = 0x20, // -a
229 OPT_VERBOSE = 0x40 * ENABLE_FEATURE_START_STOP_DAEMON_FANCY, 228 OPT_n = 0x40, // -n
230 OPT_NICELEVEL = 0x80 * ENABLE_FEATURE_START_STOP_DAEMON_FANCY, 229 OPT_s = 0x80, // -s
230 OPT_u = 0x100, // -u
231 OPT_c = 0x200, // -c
232 OPT_x = 0x400, // -x
233 OPT_p = 0x800, // -p
234 OPT_OKNODO = 0x1000 * ENABLE_FEATURE_START_STOP_DAEMON_FANCY, // -o
235 OPT_VERBOSE = 0x2000 * ENABLE_FEATURE_START_STOP_DAEMON_FANCY, // -v
236 OPT_NICELEVEL = 0x4000 * ENABLE_FEATURE_START_STOP_DAEMON_FANCY, // -N
231}; 237};
232 238
233int start_stop_daemon_main(int argc, char **argv); 239int start_stop_daemon_main(int argc, char **argv);
234int start_stop_daemon_main(int argc, char **argv) 240int start_stop_daemon_main(int argc, char **argv)
235{ 241{
236 unsigned opt; 242 unsigned opt;
237 char *signame = NULL; 243 char *signame;
238 char *startas = NULL; 244 char *startas;
245 char *chuid;
239#if ENABLE_FEATURE_START_STOP_DAEMON_FANCY 246#if ENABLE_FEATURE_START_STOP_DAEMON_FANCY
240// char *retry_arg = NULL; 247// char *retry_arg = NULL;
241// int retries = -1; 248// int retries = -1;
@@ -247,22 +254,22 @@ int start_stop_daemon_main(int argc, char **argv)
247 254
248 /* Check required one context option was given */ 255 /* Check required one context option was given */
249 opt_complementary = "K:S:?:K--S:S--K:m?p:K?xpun:S?xa"; 256 opt_complementary = "K:S:?:K--S:S--K:m?p:K?xpun:S?xa";
250 opt = getopt32(argc, argv, "KSbqm" 257 opt = getopt32(argc, argv, "KSbqma:n:s:u:c:x:p:"
251// USE_FEATURE_START_STOP_DAEMON_FANCY("ovN:R:") 258 USE_FEATURE_START_STOP_DAEMON_FANCY("ovN:"),
252 USE_FEATURE_START_STOP_DAEMON_FANCY("ovN:") 259// USE_FEATURE_START_STOP_DAEMON_FANCY("ovN:R:"),
253 "a:n:s:u:c:x:p:" 260 &startas, &cmdname, &signame, &userspec, &chuid, &execname, &pidfile
254 USE_FEATURE_START_STOP_DAEMON_FANCY(,&opt_N) 261 USE_FEATURE_START_STOP_DAEMON_FANCY(,&opt_N)
255// USE_FEATURE_START_STOP_DAEMON_FANCY(,&retry_arg) 262// USE_FEATURE_START_STOP_DAEMON_FANCY(,&retry_arg)
256 ,&startas, &cmdname, &signame, &userspec, &chuid, &execname, &pidfile); 263 );
257 264
258 quiet = (opt & OPT_QUIET) && !(opt & OPT_VERBOSE); 265 quiet = (opt & OPT_QUIET) && !(opt & OPT_VERBOSE);
259 266
260 if (signame) { 267 if (opt & OPT_s) {
261 signal_nr = get_signum(signame); 268 signal_nr = get_signum(signame);
262 if (signal_nr < 0) bb_show_usage(); 269 if (signal_nr < 0) bb_show_usage();
263 } 270 }
264 271
265 if (!startas) 272 if (!(opt & OPT_a))
266 startas = execname; 273 startas = execname;
267 274
268// USE_FEATURE_START_STOP_DAEMON_FANCY( 275// USE_FEATURE_START_STOP_DAEMON_FANCY(
@@ -303,11 +310,11 @@ int start_stop_daemon_main(int argc, char **argv)
303 fprintf(pidf, "%d\n", pidt); 310 fprintf(pidf, "%d\n", pidt);
304 fclose(pidf); 311 fclose(pidf);
305 } 312 }
306 if (chuid) { 313 if (opt & OPT_c) {
307 user_id = bb_strtou(chuid, NULL, 10); 314 struct bb_uidgid_t ugid;
308 if (errno) 315 parse_chown_usergroup_or_die(&ugid, chuid);
309 user_id = xuname2uid(chuid); 316 if (ugid.gid != (gid_t) -1) xsetgid(ugid.gid);
310 xsetuid(user_id); 317 if (ugid.uid != (uid_t) -1) xsetuid(ugid.uid);
311 } 318 }
312#if ENABLE_FEATURE_START_STOP_DAEMON_FANCY 319#if ENABLE_FEATURE_START_STOP_DAEMON_FANCY
313 if (opt & OPT_NICELEVEL) { 320 if (opt & OPT_NICELEVEL) {