Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/debianutils/start_stop_daemon.c
- Timestamp:
- Jan 1, 2014, 12:47:38 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi-busybox/debianutils/start_stop_daemon.c
r2725 r3232 32 32 with /proc/$PID/exe or argv[0] (comm can't be matched, it never contains path)] 33 33 -x,--exec EXECUTABLE Look for processes that were started with this 34 command in /proc/$PID/cmdline. 34 command in /proc/$PID/exe and /proc/$PID/cmdline 35 (/proc/$PID/cmdline is a bbox extension) 35 36 Unlike -n, we match against the full path: 36 37 "ntpd" != "./ntpd" != "/path/to/ntpd" … … 56 57 -v,--verbose Verbose 57 58 */ 59 60 //usage:#define start_stop_daemon_trivial_usage 61 //usage: "[OPTIONS] [-S|-K] ... [-- ARGS...]" 62 //usage:#define start_stop_daemon_full_usage "\n\n" 63 //usage: "Search for matching processes, and then\n" 64 //usage: "-K: stop all matching processes.\n" 65 //usage: "-S: start a process unless a matching process is found.\n" 66 //usage: IF_FEATURE_START_STOP_DAEMON_LONG_OPTIONS( 67 //usage: "\nProcess matching:" 68 //usage: "\n -u,--user USERNAME|UID Match only this user's processes" 69 //usage: "\n -n,--name NAME Match processes with NAME" 70 //usage: "\n in comm field in /proc/PID/stat" 71 //usage: "\n -x,--exec EXECUTABLE Match processes with this command" 72 //usage: "\n in /proc/PID/{exe,cmdline}" 73 //usage: "\n -p,--pidfile FILE Match a process with PID from the file" 74 //usage: "\n All specified conditions must match" 75 //usage: "\n-S only:" 76 //usage: "\n -x,--exec EXECUTABLE Program to run" 77 //usage: "\n -a,--startas NAME Zeroth argument" 78 //usage: "\n -b,--background Background" 79 //usage: IF_FEATURE_START_STOP_DAEMON_FANCY( 80 //usage: "\n -N,--nicelevel N Change nice level" 81 //usage: ) 82 //usage: "\n -c,--chuid USER[:[GRP]] Change to user/group" 83 //usage: "\n -m,--make-pidfile Write PID to the pidfile specified by -p" 84 //usage: "\n-K only:" 85 //usage: "\n -s,--signal SIG Signal to send" 86 //usage: "\n -t,--test Match only, exit with 0 if a process is found" 87 //usage: "\nOther:" 88 //usage: IF_FEATURE_START_STOP_DAEMON_FANCY( 89 //usage: "\n -o,--oknodo Exit with status 0 if nothing is done" 90 //usage: "\n -v,--verbose Verbose" 91 //usage: ) 92 //usage: "\n -q,--quiet Quiet" 93 //usage: ) 94 //usage: IF_NOT_FEATURE_START_STOP_DAEMON_LONG_OPTIONS( 95 //usage: "\nProcess matching:" 96 //usage: "\n -u USERNAME|UID Match only this user's processes" 97 //usage: "\n -n NAME Match processes with NAME" 98 //usage: "\n in comm field in /proc/PID/stat" 99 //usage: "\n -x EXECUTABLE Match processes with this command" 100 //usage: "\n command in /proc/PID/cmdline" 101 //usage: "\n -p FILE Match a process with PID from the file" 102 //usage: "\n All specified conditions must match" 103 //usage: "\n-S only:" 104 //usage: "\n -x EXECUTABLE Program to run" 105 //usage: "\n -a NAME Zeroth argument" 106 //usage: "\n -b Background" 107 //usage: IF_FEATURE_START_STOP_DAEMON_FANCY( 108 //usage: "\n -N N Change nice level" 109 //usage: ) 110 //usage: "\n -c USER[:[GRP]] Change to user/group" 111 //usage: "\n -m Write PID to the pidfile specified by -p" 112 //usage: "\n-K only:" 113 //usage: "\n -s SIG Signal to send" 114 //usage: "\n -t Match only, exit with 0 if a process is found" 115 //usage: "\nOther:" 116 //usage: IF_FEATURE_START_STOP_DAEMON_FANCY( 117 //usage: "\n -o Exit with status 0 if nothing is done" 118 //usage: "\n -v Verbose" 119 //usage: ) 120 //usage: "\n -q Quiet" 121 //usage: ) 58 122 59 123 #include <sys/resource.h> … … 136 200 ssize_t bytes; 137 201 char buf[sizeof("/proc/%u/cmdline") + sizeof(int)*3]; 138 139 sprintf(buf, "/proc/%u/cmdline", (unsigned)pid); 202 char *procname, *exelink; 203 int match; 204 205 procname = buf + sprintf(buf, "/proc/%u/exe", (unsigned)pid) - 3; 206 207 exelink = xmalloc_readlink(buf); 208 match = (exelink && strcmp(execname, exelink) == 0); 209 free(exelink); 210 if (match) 211 return match; 212 213 strcpy(procname, "cmdline"); 140 214 bytes = open_read_close(buf, G.execname_cmpbuf, G.execname_sizeof); 141 215 if (bytes > 0) { … … 275 349 } 276 350 for (p = G.found_procs; p; p = p->next) { 277 if ( TEST || kill(p->pid,signal_nr) == 0) {351 if (kill(p->pid, TEST ? 0 : signal_nr) == 0) { 278 352 killed++; 279 353 } else { 354 bb_perror_msg("warning: killing process %u", (unsigned)p->pid); 280 355 p->pid = 0; 281 bb_perror_msg("warning: killing process %u", (unsigned)p->pid); 356 if (TEST) { 357 /* Example: -K --test --pidfile PIDFILE detected 358 * that PIDFILE's pid doesn't exist */ 359 killed = -1; 360 goto ret; 361 } 282 362 } 283 363 } … … 406 486 if (opt & OPT_BACKGROUND) { 407 487 #if BB_MMU 408 bb_daemonize(DAEMON_DEVNULL_STDIO + DAEMON_CLOSE_EXTRA_FDS );488 bb_daemonize(DAEMON_DEVNULL_STDIO + DAEMON_CLOSE_EXTRA_FDS + DAEMON_DOUBLE_FORK); 409 489 /* DAEMON_DEVNULL_STDIO is superfluous - 410 490 * it's always done by bb_daemonize() */ … … 434 514 struct bb_uidgid_t ugid = { -1, -1 }; 435 515 parse_chown_usergroup_or_die(&ugid, chuid); 436 if (ugid.gid != (gid_t) -1) xsetgid(ugid.gid); 437 if (ugid.uid != (uid_t) -1) xsetuid(ugid.uid); 516 if (ugid.uid != (uid_t) -1) { 517 struct passwd *pw = xgetpwuid(ugid.uid); 518 if (ugid.gid != (gid_t) -1) 519 pw->pw_gid = ugid.gid; 520 /* initgroups, setgid, setuid: */ 521 change_identity(pw); 522 } else if (ugid.gid != (gid_t) -1) { 523 xsetgid(ugid.gid); 524 setgroups(1, &ugid.gid); 525 } 438 526 } 439 527 #if ENABLE_FEATURE_START_STOP_DAEMON_FANCY
Note:
See TracChangeset
for help on using the changeset viewer.