Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * Mini start-stop-daemon implementation(s) for busybox |
| 4 | * |
| 5 | * Written by Marek Michalkiewicz <marekm@i17linuxb.ists.pwr.wroc.pl>, |
| 6 | * public domain. |
| 7 | * Adapted for busybox David Kimdon <dwhedon@gordian.com> |
| 8 | */ |
| 9 | |
| 10 | #include <stdio.h> |
| 11 | #include <stdlib.h> |
| 12 | #include <string.h> |
| 13 | #include <stdarg.h> |
| 14 | #include <signal.h> |
| 15 | #include <errno.h> |
| 16 | #include <sys/stat.h> |
| 17 | #include <dirent.h> |
| 18 | #include <unistd.h> |
Rob Landley | b7128c6 | 2005-09-11 01:05:30 +0000 | [diff] [blame] | 19 | #include <getopt.h> /* struct option */ |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 20 | |
| 21 | #include "busybox.h" |
Eric Andersen | 887ca79 | 2002-07-03 23:19:26 +0000 | [diff] [blame] | 22 | #include "pwd_.h" |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 23 | |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 24 | static int signal_nr = 15; |
| 25 | static int user_id = -1; |
Eric Andersen | 63a1a7a | 2004-03-13 08:33:10 +0000 | [diff] [blame] | 26 | static int quiet = 0; |
Eric Andersen | aa820db | 2003-07-26 09:10:35 +0000 | [diff] [blame] | 27 | static char *userspec = NULL; |
| 28 | static char *cmdname = NULL; |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 29 | static char *execname = NULL; |
Eric Andersen | 63a1a7a | 2004-03-13 08:33:10 +0000 | [diff] [blame] | 30 | static char *pidfile = NULL; |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 31 | |
Eric Andersen | 63a1a7a | 2004-03-13 08:33:10 +0000 | [diff] [blame] | 32 | struct pid_list { |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 33 | struct pid_list *next; |
Eric Andersen | 63a1a7a | 2004-03-13 08:33:10 +0000 | [diff] [blame] | 34 | pid_t pid; |
| 35 | }; |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 36 | |
Eric Andersen | 63a1a7a | 2004-03-13 08:33:10 +0000 | [diff] [blame] | 37 | static struct pid_list *found = NULL; |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 38 | |
Eric Andersen | 950d8b4 | 2001-10-31 09:55:39 +0000 | [diff] [blame] | 39 | static inline void |
Eric Andersen | 63a1a7a | 2004-03-13 08:33:10 +0000 | [diff] [blame] | 40 | push(pid_t pid) |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 41 | { |
Eric Andersen | 63a1a7a | 2004-03-13 08:33:10 +0000 | [diff] [blame] | 42 | struct pid_list *p; |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 43 | |
| 44 | p = xmalloc(sizeof(*p)); |
Eric Andersen | 950d8b4 | 2001-10-31 09:55:39 +0000 | [diff] [blame] | 45 | p->next = found; |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 46 | p->pid = pid; |
Eric Andersen | 950d8b4 | 2001-10-31 09:55:39 +0000 | [diff] [blame] | 47 | found = p; |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 50 | static int |
Eric Andersen | 63a1a7a | 2004-03-13 08:33:10 +0000 | [diff] [blame] | 51 | pid_is_exec(pid_t pid, const char *name) |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 52 | { |
Eric Andersen | 63a1a7a | 2004-03-13 08:33:10 +0000 | [diff] [blame] | 53 | char buf[32]; |
| 54 | struct stat sb, exec_stat; |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 55 | |
Rob Landley | c5b1d4d | 2006-03-13 15:45:16 +0000 | [diff] [blame] | 56 | if (name) |
| 57 | xstat(name, &exec_stat); |
Eric Andersen | 63a1a7a | 2004-03-13 08:33:10 +0000 | [diff] [blame] | 58 | |
| 59 | sprintf(buf, "/proc/%d/exe", pid); |
| 60 | if (stat(buf, &sb) != 0) |
| 61 | return 0; |
| 62 | return (sb.st_dev == exec_stat.st_dev && sb.st_ino == exec_stat.st_ino); |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 65 | static int |
| 66 | pid_is_user(int pid, int uid) |
| 67 | { |
| 68 | struct stat sb; |
| 69 | char buf[32]; |
| 70 | |
| 71 | sprintf(buf, "/proc/%d", pid); |
| 72 | if (stat(buf, &sb) != 0) |
| 73 | return 0; |
| 74 | return (sb.st_uid == uid); |
| 75 | } |
| 76 | |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 77 | static int |
Eric Andersen | 63a1a7a | 2004-03-13 08:33:10 +0000 | [diff] [blame] | 78 | pid_is_cmd(pid_t pid, const char *name) |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 79 | { |
| 80 | char buf[32]; |
| 81 | FILE *f; |
| 82 | int c; |
| 83 | |
| 84 | sprintf(buf, "/proc/%d/stat", pid); |
| 85 | f = fopen(buf, "r"); |
| 86 | if (!f) |
| 87 | return 0; |
| 88 | while ((c = getc(f)) != EOF && c != '(') |
| 89 | ; |
| 90 | if (c != '(') { |
| 91 | fclose(f); |
| 92 | return 0; |
| 93 | } |
| 94 | /* this hopefully handles command names containing ')' */ |
| 95 | while ((c = getc(f)) != EOF && c == *name) |
| 96 | name++; |
| 97 | fclose(f); |
| 98 | return (c == ')' && *name == '\0'); |
| 99 | } |
| 100 | |
| 101 | |
| 102 | static void |
| 103 | check(int pid) |
| 104 | { |
| 105 | if (execname && !pid_is_exec(pid, execname)) { |
| 106 | return; |
| 107 | } |
| 108 | if (userspec && !pid_is_user(pid, user_id)) { |
| 109 | return; |
| 110 | } |
| 111 | if (cmdname && !pid_is_cmd(pid, cmdname)) { |
| 112 | return; |
| 113 | } |
Eric Andersen | 950d8b4 | 2001-10-31 09:55:39 +0000 | [diff] [blame] | 114 | push(pid); |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | |
Eric Andersen | 63a1a7a | 2004-03-13 08:33:10 +0000 | [diff] [blame] | 118 | static void |
Eric Andersen | 625da9d | 2004-04-13 18:28:46 +0000 | [diff] [blame] | 119 | do_pidfile(void) |
Eric Andersen | 63a1a7a | 2004-03-13 08:33:10 +0000 | [diff] [blame] | 120 | { |
| 121 | FILE *f; |
| 122 | pid_t pid; |
| 123 | |
Eric Andersen | 625da9d | 2004-04-13 18:28:46 +0000 | [diff] [blame] | 124 | f = fopen(pidfile, "r"); |
Eric Andersen | 63a1a7a | 2004-03-13 08:33:10 +0000 | [diff] [blame] | 125 | if (f) { |
| 126 | if (fscanf(f, "%d", &pid) == 1) |
| 127 | check(pid); |
| 128 | fclose(f); |
| 129 | } else if (errno != ENOENT) |
Eric Andersen | 625da9d | 2004-04-13 18:28:46 +0000 | [diff] [blame] | 130 | bb_perror_msg_and_die("open pidfile %s", pidfile); |
Eric Andersen | 63a1a7a | 2004-03-13 08:33:10 +0000 | [diff] [blame] | 131 | |
| 132 | } |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 133 | |
| 134 | static void |
Eric Andersen | 63a1a7a | 2004-03-13 08:33:10 +0000 | [diff] [blame] | 135 | do_procinit(void) |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 136 | { |
| 137 | DIR *procdir; |
| 138 | struct dirent *entry; |
| 139 | int foundany, pid; |
| 140 | |
Eric Andersen | 625da9d | 2004-04-13 18:28:46 +0000 | [diff] [blame] | 141 | if (pidfile) { |
| 142 | do_pidfile(); |
| 143 | return; |
| 144 | } |
| 145 | |
Bernhard Reutner-Fischer | cb44816 | 2006-04-12 07:35:12 +0000 | [diff] [blame] | 146 | procdir = bb_xopendir("/proc"); |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 147 | |
| 148 | foundany = 0; |
| 149 | while ((entry = readdir(procdir)) != NULL) { |
| 150 | if (sscanf(entry->d_name, "%d", &pid) != 1) |
| 151 | continue; |
| 152 | foundany++; |
| 153 | check(pid); |
| 154 | } |
| 155 | closedir(procdir); |
| 156 | if (!foundany) |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 157 | bb_error_msg_and_die ("nothing in /proc - not mounted?"); |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | |
| 161 | static void |
| 162 | do_stop(void) |
| 163 | { |
| 164 | char what[1024]; |
Eric Andersen | 63a1a7a | 2004-03-13 08:33:10 +0000 | [diff] [blame] | 165 | struct pid_list *p; |
Eric Andersen | 950d8b4 | 2001-10-31 09:55:39 +0000 | [diff] [blame] | 166 | int killed = 0; |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 167 | |
Eric Andersen | 625da9d | 2004-04-13 18:28:46 +0000 | [diff] [blame] | 168 | do_procinit(); |
Eric Andersen | 63a1a7a | 2004-03-13 08:33:10 +0000 | [diff] [blame] | 169 | |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 170 | if (cmdname) |
| 171 | strcpy(what, cmdname); |
| 172 | else if (execname) |
| 173 | strcpy(what, execname); |
Eric Andersen | 625da9d | 2004-04-13 18:28:46 +0000 | [diff] [blame] | 174 | else if (pidfile) |
| 175 | sprintf(what, "process in pidfile `%.200s'", pidfile); |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 176 | else if (userspec) |
| 177 | sprintf(what, "process(es) owned by `%s'", userspec); |
| 178 | else |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 179 | bb_error_msg_and_die ("internal error, please report"); |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 180 | |
| 181 | if (!found) { |
Eric Andersen | 63a1a7a | 2004-03-13 08:33:10 +0000 | [diff] [blame] | 182 | if (!quiet) |
| 183 | printf("no %s found; none killed.\n", what); |
Eric Andersen | 950d8b4 | 2001-10-31 09:55:39 +0000 | [diff] [blame] | 184 | return; |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 185 | } |
| 186 | for (p = found; p; p = p->next) { |
Eric Andersen | 950d8b4 | 2001-10-31 09:55:39 +0000 | [diff] [blame] | 187 | if (kill(p->pid, signal_nr) == 0) { |
| 188 | p->pid = -p->pid; |
| 189 | killed++; |
| 190 | } else { |
Eric Andersen | 625da9d | 2004-04-13 18:28:46 +0000 | [diff] [blame] | 191 | bb_perror_msg("warning: failed to kill %d", p->pid); |
Eric Andersen | 950d8b4 | 2001-10-31 09:55:39 +0000 | [diff] [blame] | 192 | } |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 193 | } |
Eric Andersen | 63a1a7a | 2004-03-13 08:33:10 +0000 | [diff] [blame] | 194 | if (!quiet && killed) { |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 195 | printf("stopped %s (pid", what); |
Eric Andersen | 950d8b4 | 2001-10-31 09:55:39 +0000 | [diff] [blame] | 196 | for (p = found; p; p = p->next) |
| 197 | if(p->pid < 0) |
| 198 | printf(" %d", -p->pid); |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 199 | printf(").\n"); |
| 200 | } |
| 201 | } |
| 202 | |
Bernhard Reutner-Fischer | 01d23ad | 2006-05-26 20:19:22 +0000 | [diff] [blame^] | 203 | #if ENABLE_FEATURE_START_STOP_DAEMON_LONG_OPTIONS |
Eric Andersen | aa820db | 2003-07-26 09:10:35 +0000 | [diff] [blame] | 204 | static const struct option ssd_long_options[] = { |
"Vladimir N. Oleynik" | 064f04e | 2005-10-11 14:38:01 +0000 | [diff] [blame] | 205 | { "stop", 0, NULL, 'K' }, |
| 206 | { "start", 0, NULL, 'S' }, |
Eric Andersen | 625da9d | 2004-04-13 18:28:46 +0000 | [diff] [blame] | 207 | { "background", 0, NULL, 'b' }, |
"Vladimir N. Oleynik" | 064f04e | 2005-10-11 14:38:01 +0000 | [diff] [blame] | 208 | { "quiet", 0, NULL, 'q' }, |
Eric Andersen | 625da9d | 2004-04-13 18:28:46 +0000 | [diff] [blame] | 209 | { "make-pidfile", 0, NULL, 'm' }, |
| 210 | { "startas", 1, NULL, 'a' }, |
"Vladimir N. Oleynik" | 064f04e | 2005-10-11 14:38:01 +0000 | [diff] [blame] | 211 | { "name", 1, NULL, 'n' }, |
| 212 | { "signal", 1, NULL, 's' }, |
| 213 | { "user", 1, NULL, 'u' }, |
| 214 | { "exec", 1, NULL, 'x' }, |
Eric Andersen | 625da9d | 2004-04-13 18:28:46 +0000 | [diff] [blame] | 215 | { "pidfile", 1, NULL, 'p' }, |
"Vladimir N. Oleynik" | 064f04e | 2005-10-11 14:38:01 +0000 | [diff] [blame] | 216 | { 0, 0, 0, 0 } |
Eric Andersen | aa820db | 2003-07-26 09:10:35 +0000 | [diff] [blame] | 217 | }; |
Bernhard Reutner-Fischer | 01d23ad | 2006-05-26 20:19:22 +0000 | [diff] [blame^] | 218 | #endif |
Eric Andersen | aa820db | 2003-07-26 09:10:35 +0000 | [diff] [blame] | 219 | |
Eric Andersen | 625da9d | 2004-04-13 18:28:46 +0000 | [diff] [blame] | 220 | #define SSD_CTX_STOP 1 |
| 221 | #define SSD_CTX_START 2 |
Glenn L McGrath | 8d44178 | 2004-01-22 09:04:58 +0000 | [diff] [blame] | 222 | #define SSD_OPT_BACKGROUND 4 |
Eric Andersen | 625da9d | 2004-04-13 18:28:46 +0000 | [diff] [blame] | 223 | #define SSD_OPT_QUIET 8 |
| 224 | #define SSD_OPT_MAKEPID 16 |
Glenn L McGrath | 8d44178 | 2004-01-22 09:04:58 +0000 | [diff] [blame] | 225 | |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 226 | int |
| 227 | start_stop_daemon_main(int argc, char **argv) |
| 228 | { |
Glenn L McGrath | 8d44178 | 2004-01-22 09:04:58 +0000 | [diff] [blame] | 229 | unsigned long opt; |
Eric Andersen | 08804ce | 2003-07-30 08:29:56 +0000 | [diff] [blame] | 230 | char *signame = NULL; |
Glenn L McGrath | 8d44178 | 2004-01-22 09:04:58 +0000 | [diff] [blame] | 231 | char *startas = NULL; |
| 232 | |
Bernhard Reutner-Fischer | 01d23ad | 2006-05-26 20:19:22 +0000 | [diff] [blame^] | 233 | #if ENABLE_FEATURE_START_STOP_DAEMON_LONG_OPTIONS |
Eric Andersen | aa820db | 2003-07-26 09:10:35 +0000 | [diff] [blame] | 234 | bb_applet_long_options = ssd_long_options; |
Bernhard Reutner-Fischer | 01d23ad | 2006-05-26 20:19:22 +0000 | [diff] [blame^] | 235 | #endif |
Eric Andersen | aa820db | 2003-07-26 09:10:35 +0000 | [diff] [blame] | 236 | |
"Vladimir N. Oleynik" | 064f04e | 2005-10-11 14:38:01 +0000 | [diff] [blame] | 237 | /* Check required one context option was given */ |
"Vladimir N. Oleynik" | f704b27 | 2005-10-14 09:56:52 +0000 | [diff] [blame] | 238 | bb_opt_complementally = "K:S:?:K--S:S--K"; |
Eric Andersen | 625da9d | 2004-04-13 18:28:46 +0000 | [diff] [blame] | 239 | opt = bb_getopt_ulflags(argc, argv, "KSbqma:n:s:u:x:p:", |
"Vladimir N. Oleynik" | f704b27 | 2005-10-14 09:56:52 +0000 | [diff] [blame] | 240 | &startas, &cmdname, &signame, &userspec, &execname, &pidfile); |
Eric Andersen | aa820db | 2003-07-26 09:10:35 +0000 | [diff] [blame] | 241 | |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 242 | |
"Vladimir N. Oleynik" | 064f04e | 2005-10-11 14:38:01 +0000 | [diff] [blame] | 243 | quiet = opt & SSD_OPT_QUIET; |
Paul Fox | bb9a0ad | 2005-07-29 14:58:09 +0000 | [diff] [blame] | 244 | |
Eric Andersen | 08804ce | 2003-07-30 08:29:56 +0000 | [diff] [blame] | 245 | if (signame) { |
| 246 | signal_nr = bb_xgetlarg(signame, 10, 0, NSIG); |
| 247 | } |
Eric Andersen | aa820db | 2003-07-26 09:10:35 +0000 | [diff] [blame] | 248 | |
Eric Andersen | 625da9d | 2004-04-13 18:28:46 +0000 | [diff] [blame] | 249 | if (!execname && !pidfile && !userspec && !cmdname) |
| 250 | bb_error_msg_and_die ("need at least one of -x, -p, -u, or -n"); |
Eric Andersen | aa820db | 2003-07-26 09:10:35 +0000 | [diff] [blame] | 251 | |
| 252 | if (!startas) |
| 253 | startas = execname; |
| 254 | |
Glenn L McGrath | 8d44178 | 2004-01-22 09:04:58 +0000 | [diff] [blame] | 255 | if ((opt & SSD_CTX_START) && !startas) |
Eric Andersen | aa820db | 2003-07-26 09:10:35 +0000 | [diff] [blame] | 256 | bb_error_msg_and_die ("-S needs -x or -a"); |
| 257 | |
Eric Andersen | 625da9d | 2004-04-13 18:28:46 +0000 | [diff] [blame] | 258 | if ((opt & SSD_OPT_MAKEPID) && pidfile == NULL) |
| 259 | bb_error_msg_and_die ("-m needs -p"); |
| 260 | |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 261 | argc -= optind; |
| 262 | argv += optind; |
| 263 | |
Eric Andersen | 950d8b4 | 2001-10-31 09:55:39 +0000 | [diff] [blame] | 264 | if (userspec && sscanf(userspec, "%d", &user_id) != 1) |
Bernhard Reutner-Fischer | d5bd137 | 2005-09-20 21:06:17 +0000 | [diff] [blame] | 265 | user_id = bb_xgetpwnam(userspec); |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 266 | |
Glenn L McGrath | 8d44178 | 2004-01-22 09:04:58 +0000 | [diff] [blame] | 267 | if (opt & SSD_CTX_STOP) { |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 268 | do_stop(); |
Eric Andersen | 950d8b4 | 2001-10-31 09:55:39 +0000 | [diff] [blame] | 269 | return EXIT_SUCCESS; |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 270 | } |
| 271 | |
Eric Andersen | 625da9d | 2004-04-13 18:28:46 +0000 | [diff] [blame] | 272 | do_procinit(); |
| 273 | |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 274 | if (found) { |
Eric Andersen | 63a1a7a | 2004-03-13 08:33:10 +0000 | [diff] [blame] | 275 | if (!quiet) |
| 276 | printf("%s already running.\n%d\n", execname ,found->pid); |
Eric Andersen | 950d8b4 | 2001-10-31 09:55:39 +0000 | [diff] [blame] | 277 | return EXIT_SUCCESS; |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 278 | } |
| 279 | *--argv = startas; |
Glenn L McGrath | 8d44178 | 2004-01-22 09:04:58 +0000 | [diff] [blame] | 280 | if (opt & SSD_OPT_BACKGROUND) { |
Bernhard Reutner-Fischer | 2c99851 | 2006-04-12 18:09:26 +0000 | [diff] [blame] | 281 | bb_xdaemon(0, 0); |
Eric Andersen | 625da9d | 2004-04-13 18:28:46 +0000 | [diff] [blame] | 282 | setsid(); |
Eric Andersen | 53a2299 | 2002-01-26 09:04:45 +0000 | [diff] [blame] | 283 | } |
Eric Andersen | 625da9d | 2004-04-13 18:28:46 +0000 | [diff] [blame] | 284 | if (opt & SSD_OPT_MAKEPID) { |
| 285 | /* user wants _us_ to make the pidfile */ |
| 286 | FILE *pidf = fopen(pidfile, "w"); |
| 287 | pid_t pidt = getpid(); |
| 288 | if (pidf == NULL) |
| 289 | bb_perror_msg_and_die("Unable to write pidfile '%s'", pidfile); |
| 290 | fprintf(pidf, "%d\n", pidt); |
| 291 | fclose(pidf); |
| 292 | } |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 293 | execv(startas, argv); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 294 | bb_perror_msg_and_die ("unable to start %s", startas); |
Eric Andersen | c2af1ee | 2001-10-18 19:33:06 +0000 | [diff] [blame] | 295 | } |