Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/runit
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 deleted
- 7 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/runit/Config.src
r2725 r3621 8 8 INSERT 9 9 10 config RUNSV11 bool "runsv"12 default y13 help14 runsv starts and monitors a service and optionally an appendant log15 service.16 17 config RUNSVDIR18 bool "runsvdir"19 default y20 help21 runsvdir starts a runsv process for each subdirectory, or symlink to22 a directory, in the services directory dir, up to a limit of 100023 subdirectories, and restarts a runsv process if it terminates.24 25 config FEATURE_RUNSVDIR_LOG26 bool "Enable scrolling argument log"27 depends on RUNSVDIR28 default n29 help30 Enable feature where second parameter of runsvdir holds last error31 message (viewable via top/ps). Otherwise (feature is off32 or no parameter), error messages go to stderr only.33 34 config SV35 bool "sv"36 default y37 help38 sv reports the current status and controls the state of services39 monitored by the runsv supervisor.40 41 config SV_DEFAULT_SERVICE_DIR42 string "Default directory for services"43 default "/var/service"44 depends on SV45 help46 Default directory for services.47 Defaults to "/var/service"48 49 config SVLOGD50 bool "svlogd"51 default y52 help53 svlogd continuously reads log data from its standard input, optionally54 filters log messages, and writes the data to one or more automatically55 rotated logs.56 57 config CHPST58 bool "chpst"59 default y60 help61 chpst changes the process state according to the given options, and62 execs specified program.63 64 config SETUIDGID65 bool "setuidgid"66 default y67 help68 Sets soft resource limits as specified by options69 70 config ENVUIDGID71 bool "envuidgid"72 default y73 help74 Sets $UID to account's uid and $GID to account's gid75 76 config ENVDIR77 bool "envdir"78 default y79 help80 Sets various environment variables as specified by files81 in the given directory82 83 config SOFTLIMIT84 bool "softlimit"85 default y86 help87 Sets soft resource limits as specified by options88 89 10 endmenu -
branches/3.3/mindi-busybox/runit/Kbuild.src
r2725 r3621 8 8 9 9 INSERT 10 11 lib-$(CONFIG_RUNSV) += runsv.o12 lib-$(CONFIG_RUNSVDIR) += runsvdir.o13 lib-$(CONFIG_SV) += sv.o14 lib-$(CONFIG_SVLOGD) += svlogd.o15 lib-$(CONFIG_CHPST) += chpst.o16 17 lib-$(CONFIG_ENVDIR) += chpst.o18 lib-$(CONFIG_ENVUIDGID) += chpst.o19 lib-$(CONFIG_SETUIDGID) += chpst.o20 lib-$(CONFIG_SOFTLIMIT) += chpst.o -
branches/3.3/mindi-busybox/runit/chpst.c
r3232 r3621 27 27 28 28 /* Busyboxed by Denys Vlasenko <vda.linux@googlemail.com> */ 29 /* Dependencies on runit_lib.c removed */ 29 30 //config:config CHPST 31 //config: bool "chpst" 32 //config: default y 33 //config: help 34 //config: chpst changes the process state according to the given options, and 35 //config: execs specified program. 36 //config: 37 //config:config SETUIDGID 38 //config: bool "setuidgid" 39 //config: default y 40 //config: help 41 //config: Sets soft resource limits as specified by options 42 //config: 43 //config:config ENVUIDGID 44 //config: bool "envuidgid" 45 //config: default y 46 //config: help 47 //config: Sets $UID to account's uid and $GID to account's gid 48 //config: 49 //config:config ENVDIR 50 //config: bool "envdir" 51 //config: default y 52 //config: help 53 //config: Sets various environment variables as specified by files 54 //config: in the given directory 55 //config: 56 //config:config SOFTLIMIT 57 //config: bool "softlimit" 58 //config: default y 59 //config: help 60 //config: Sets soft resource limits as specified by options 61 62 //applet:IF_CHPST(APPLET(chpst, BB_DIR_USR_BIN, BB_SUID_DROP)) 63 //applet:IF_ENVDIR(APPLET_ODDNAME(envdir, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, envdir)) 64 //applet:IF_ENVUIDGID(APPLET_ODDNAME(envuidgid, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, envuidgid)) 65 //applet:IF_SETUIDGID(APPLET_ODDNAME(setuidgid, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, setuidgid)) 66 //applet:IF_SOFTLIMIT(APPLET_ODDNAME(softlimit, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, softlimit)) 67 68 //kbuild:lib-$(CONFIG_CHPST) += chpst.o 69 //kbuild:lib-$(CONFIG_ENVDIR) += chpst.o 70 //kbuild:lib-$(CONFIG_ENVUIDGID) += chpst.o 71 //kbuild:lib-$(CONFIG_SETUIDGID) += chpst.o 72 //kbuild:lib-$(CONFIG_SOFTLIMIT) += chpst.o 30 73 31 74 //usage:#define chpst_trivial_usage … … 213 256 } 214 257 closedir(dir); 215 if (fchdir(wdir) == -1) 216 bb_perror_msg_and_die("fchdir"); 258 xfchdir(wdir); 217 259 close(wdir); 218 260 } … … 237 279 struct bb_uidgid_t ugid; 238 280 char *set_user = set_user; /* for compiler */ 239 char *env_user = env_user;240 281 char *env_dir = env_dir; 241 282 char *root; … … 265 306 &limita, &limitc, &limitd, &limitf, &limitl, 266 307 &limitm, &limito, &limitp, &limitr, &limits, &limitt, 267 &set_user, & env_user, &env_dir308 &set_user, &set_user, &env_dir 268 309 IF_CHPST(, &root, &nicestr)); 269 310 argv += optind; … … 293 334 // envuidgid? 294 335 if (ENABLE_ENVUIDGID && applet_name[0] == 'e' && applet_name[3] == 'u') { 295 env_user = *argv++;336 set_user = *argv++; 296 337 opt |= OPT_U; 297 338 } -
branches/3.3/mindi-busybox/runit/runsv.c
r3232 r3621 27 27 28 28 /* Busyboxed by Denys Vlasenko <vda.linux@googlemail.com> */ 29 /* TODO: depends on runit_lib.c - review and reduce/eliminate */ 29 30 //config:config RUNSV 31 //config: bool "runsv" 32 //config: default y 33 //config: help 34 //config: runsv starts and monitors a service and optionally an appendant log 35 //config: service. 36 37 //applet:IF_RUNSV(APPLET(runsv, BB_DIR_USR_BIN, BB_SUID_DROP)) 38 39 //kbuild:lib-$(CONFIG_RUNSV) += runsv.o 30 40 31 41 //usage:#define runsv_trivial_usage … … 34 44 //usage: "Start and monitor a service and optionally an appendant log service" 35 45 36 #include <sys/poll.h>37 46 #include <sys/file.h> 38 47 #include "libbb.h" 48 #include "common_bufsiz.h" 39 49 #include "runit_lib.h" 40 50 … … 51 61 static void gettimeofday_ns(struct timespec *ts) 52 62 { 53 if (sizeof(struct timeval) == sizeof(struct timespec) 54 && sizeof(((struct timeval*)ts)->tv_usec) == sizeof(ts->tv_nsec) 55 ) { 56 /* Cheat */ 57 gettimeofday((void*)ts, NULL); 58 ts->tv_nsec *= 1000; 59 } else { 60 extern void BUG_need_to_implement_gettimeofday_ns(void); 61 BUG_need_to_implement_gettimeofday_ns(); 62 } 63 BUILD_BUG_ON(sizeof(struct timeval) != sizeof(struct timespec)); 64 BUILD_BUG_ON(sizeof(((struct timeval*)ts)->tv_usec) != sizeof(ts->tv_nsec)); 65 /* Cheat */ 66 gettimeofday((void*)ts, NULL); 67 ts->tv_nsec *= 1000; 63 68 } 64 69 #endif … … 102 107 struct svdir svd[2]; 103 108 } FIX_ALIASING; 104 #define G (*(struct globals*) &bb_common_bufsiz1)109 #define G (*(struct globals*)bb_common_bufsiz1) 105 110 #define haslog (G.haslog ) 106 111 #define sigterm (G.sigterm ) … … 111 116 #define svd (G.svd ) 112 117 #define INIT_G() do { \ 118 setup_common_bufsiz(); \ 113 119 pidchanged = 1; \ 114 120 } while (0) … … 116 122 static void fatal2_cannot(const char *m1, const char *m2) 117 123 { 118 bb_perror_msg_and_die("%s: fatal: can not %s%s", dir, m1, m2);124 bb_perror_msg_and_die("%s: fatal: can't %s%s", dir, m1, m2); 119 125 /* was exiting 111 */ 120 126 } … … 126 132 static void fatal2x_cannot(const char *m1, const char *m2) 127 133 { 128 bb_error_msg_and_die("%s: fatal: can not %s%s", dir, m1, m2);134 bb_error_msg_and_die("%s: fatal: can't %s%s", dir, m1, m2); 129 135 /* was exiting 111 */ 130 136 } -
branches/3.3/mindi-busybox/runit/runsvdir.c
r3232 r3621 27 27 28 28 /* Busyboxed by Denys Vlasenko <vda.linux@googlemail.com> */ 29 /* TODO: depends on runit_lib.c - review and reduce/eliminate */ 29 30 //config:config RUNSVDIR 31 //config: bool "runsvdir" 32 //config: default y 33 //config: help 34 //config: runsvdir starts a runsv process for each subdirectory, or symlink to 35 //config: a directory, in the services directory dir, up to a limit of 1000 36 //config: subdirectories, and restarts a runsv process if it terminates. 37 //config: 38 //config:config FEATURE_RUNSVDIR_LOG 39 //config: bool "Enable scrolling argument log" 40 //config: depends on RUNSVDIR 41 //config: default n 42 //config: help 43 //config: Enable feature where second parameter of runsvdir holds last error 44 //config: message (viewable via top/ps). Otherwise (feature is off 45 //config: or no parameter), error messages go to stderr only. 46 47 //applet:IF_RUNSVDIR(APPLET(runsvdir, BB_DIR_USR_BIN, BB_SUID_DROP)) 48 49 //kbuild:lib-$(CONFIG_RUNSVDIR) += runsvdir.o 30 50 31 51 //usage:#define runsvdir_trivial_usage … … 36 56 //usage: "\n -s SCRIPT Run SCRIPT <signo> after signal is processed" 37 57 38 #include <sys/poll.h>39 58 #include <sys/file.h> 40 59 #include "libbb.h" 60 #include "common_bufsiz.h" 41 61 #include "runit_lib.h" 42 62 … … 61 81 #if ENABLE_FEATURE_RUNSVDIR_LOG 62 82 char *rplog; 63 int rploglen;64 83 struct fd_pair logpipe; 65 84 struct pollfd pfd[1]; … … 67 86 #endif 68 87 } FIX_ALIASING; 69 #define G (*(struct globals*) &bb_common_bufsiz1)88 #define G (*(struct globals*)bb_common_bufsiz1) 70 89 #define sv (G.sv ) 71 90 #define svdir (G.svdir ) 72 91 #define svnum (G.svnum ) 73 92 #define rplog (G.rplog ) 74 #define rploglen (G.rploglen )75 93 #define logpipe (G.logpipe ) 76 94 #define pfd (G.pfd ) 77 95 #define stamplog (G.stamplog ) 78 #define INIT_G() do { } while (0)96 #define INIT_G() do { setup_common_bufsiz(); } while (0) 79 97 80 98 static void fatal2_cannot(const char *m1, const char *m2) … … 221 239 dev_t last_dev = last_dev; /* for gcc */ 222 240 ino_t last_ino = last_ino; /* for gcc */ 223 time_t last_mtime = 0; 224 int wstat; 241 time_t last_mtime; 225 242 int curdir; 226 pid_t pid;227 unsigned deadline;228 unsigned now;229 243 unsigned stampcheck; 230 244 int i; 231 int need_rescan = 1; 245 int need_rescan; 246 bool i_am_init; 232 247 char *opt_s_argv[3]; 233 248 … … 240 255 argv += optind; 241 256 257 i_am_init = (getpid() == 1); 242 258 bb_signals(0 243 259 | (1 << SIGTERM) 244 260 | (1 << SIGHUP) 245 261 /* For busybox's init, SIGTERM == reboot, 246 * SIGUSR1 == halt 247 * SIGUSR2 == poweroff 248 * so we need to intercept SIGUSRn too. 262 * SIGUSR1 == halt, 263 * SIGUSR2 == poweroff, 264 * Ctlr-ALt-Del sends SIGINT to init, 265 * so we need to intercept SIGUSRn and SIGINT too. 249 266 * Note that we do not implement actual reboot 250 267 * (killall(TERM) + umount, etc), we just pause 251 268 * respawing and avoid exiting (-> making kernel oops). 252 * The user is responsible for the rest. */ 253 | (getpid() == 1 ? ((1 << SIGUSR1) | (1 << SIGUSR2)) : 0) 269 * The user is responsible for the rest. 270 */ 271 | (i_am_init ? ((1 << SIGUSR1) | (1 << SIGUSR2) | (1 << SIGINT)) : 0) 254 272 , record_signo); 255 273 svdir = *argv++; … … 259 277 if (*argv) { 260 278 rplog = *argv; 261 rploglen = strlen(rplog); 262 if (rploglen < 7) { 279 if (strlen(rplog) < 7) { 263 280 warnx("log must have at least seven characters"); 264 281 } else if (piped_pair(logpipe)) { … … 289 306 290 307 stampcheck = monotonic_sec(); 308 need_rescan = 1; 309 last_mtime = 0; 291 310 292 311 for (;;) { 312 unsigned now; 313 unsigned sig; 314 293 315 /* collect children */ 294 316 for (;;) { 295 pid = wait_any_nohang(&wstat);317 pid_t pid = wait_any_nohang(NULL); 296 318 if (pid <= 0) 297 319 break; … … 347 369 pfd[0].revents = 0; 348 370 #endif 349 deadline = (need_rescan ? 1 : 5);350 sig_block(SIGCHLD);351 #if ENABLE_FEATURE_RUNSVDIR_LOG 352 if (rplog)353 poll(pfd, 1, deadline*1000);354 else355 #endif 356 sleep(deadline);357 sig_unblock(SIGCHLD);371 { 372 unsigned deadline = (need_rescan ? 1 : 5); 373 #if ENABLE_FEATURE_RUNSVDIR_LOG 374 if (rplog) 375 poll(pfd, 1, deadline*1000); 376 else 377 #endif 378 sleep(deadline); 379 } 358 380 359 381 #if ENABLE_FEATURE_RUNSVDIR_LOG … … 363 385 if (ch < ' ') 364 386 ch = ' '; 365 for (i = 6; i < rploglen; i++)387 for (i = 6; rplog[i] != '\0'; i++) 366 388 rplog[i-1] = rplog[i]; 367 rplog[rploglen-1] = ch; 368 } 369 } 370 #endif 371 if (!bb_got_signal) 389 rplog[i-1] = ch; 390 } 391 } 392 #endif 393 sig = bb_got_signal; 394 if (!sig) 372 395 continue; 396 bb_got_signal = 0; 373 397 374 398 /* -s SCRIPT: useful if we are init. … … 376 400 * it halts/powers off/reboots the system. */ 377 401 if (opt_s_argv[0]) { 402 pid_t pid; 403 378 404 /* Single parameter: signal# */ 379 opt_s_argv[1] = utoa( bb_got_signal);405 opt_s_argv[1] = utoa(sig); 380 406 pid = spawn(opt_s_argv); 381 407 if (pid > 0) { … … 387 413 } 388 414 389 if ( bb_got_signal== SIGHUP) {415 if (sig == SIGHUP) { 390 416 for (i = 0; i < svnum; i++) 391 417 if (sv[i].pid) … … 394 420 /* SIGHUP or SIGTERM (or SIGUSRn if we are init) */ 395 421 /* Exit unless we are init */ 396 if ( getpid() != 1)397 return (SIGHUP == bb_got_signal) ? 111 : EXIT_SUCCESS;422 if (!i_am_init) 423 return (SIGHUP == sig) ? 111 : EXIT_SUCCESS; 398 424 399 425 /* init continues to monitor services forever */ 400 bb_got_signal = 0;401 426 } /* for (;;) */ 402 427 } -
branches/3.3/mindi-busybox/runit/sv.c
r3232 r3621 152 152 153 153 /* Busyboxed by Denys Vlasenko <vda.linux@googlemail.com> */ 154 /* TODO: depends on runit_lib.c - review and reduce/eliminate */ 154 155 //config:config SV 156 //config: bool "sv" 157 //config: default y 158 //config: help 159 //config: sv reports the current status and controls the state of services 160 //config: monitored by the runsv supervisor. 161 //config: 162 //config:config SV_DEFAULT_SERVICE_DIR 163 //config: string "Default directory for services" 164 //config: default "/var/service" 165 //config: depends on SV 166 //config: help 167 //config: Default directory for services. 168 //config: Defaults to "/var/service" 169 170 //applet:IF_SV(APPLET(sv, BB_DIR_USR_BIN, BB_SUID_DROP)) 171 172 //kbuild:lib-$(CONFIG_SV) += sv.o 155 173 156 174 //usage:#define sv_trivial_usage … … 170 188 //usage: "STOP, CONT, HUP, ALRM, INT, QUIT, USR1, USR2, TERM, KILL signal to service" 171 189 172 #include <sys/poll.h>173 190 #include <sys/file.h> 174 191 #include "libbb.h" 192 #include "common_bufsiz.h" 175 193 #include "runit_lib.h" 176 194 … … 183 201 svstatus_t svstatus; 184 202 } FIX_ALIASING; 185 #define G (*(struct globals*) &bb_common_bufsiz1)203 #define G (*(struct globals*)bb_common_bufsiz1) 186 204 #define acts (G.acts ) 187 205 #define service (G.service ) … … 190 208 #define tnow (G.tnow ) 191 209 #define svstatus (G.svstatus ) 192 #define INIT_G() do { } while (0)210 #define INIT_G() do { setup_common_bufsiz(); } while (0) 193 211 194 212 -
branches/3.3/mindi-busybox/runit/svlogd.c
r3232 r3621 27 27 28 28 /* Busyboxed by Denys Vlasenko <vda.linux@googlemail.com> */ 29 /* TODO: depends on runit_lib.c - review and reduce/eliminate */30 29 31 30 /* … … 126 125 */ 127 126 127 //config:config SVLOGD 128 //config: bool "svlogd" 129 //config: default y 130 //config: help 131 //config: svlogd continuously reads log data from its standard input, optionally 132 //config: filters log messages, and writes the data to one or more automatically 133 //config: rotated logs. 134 135 //applet:IF_SVLOGD(APPLET(svlogd, BB_DIR_USR_SBIN, BB_SUID_DROP)) 136 137 //kbuild:lib-$(CONFIG_SVLOGD) += svlogd.o 138 128 139 //usage:#define svlogd_trivial_usage 129 140 //usage: "[-ttv] [-r C] [-R CHARS] [-l MATCHLEN] [-b BUFLEN] DIR..." … … 143 154 //usage: "\n""E,ePATTERN - (de)select line for stderr" 144 155 145 #include <sys/poll.h>146 156 #include <sys/file.h> 147 157 #include "libbb.h" 158 #include "common_bufsiz.h" 148 159 #include "runit_lib.h" 149 160 … … 224 235 #define fl_flag_0 (G.fl_flag_0 ) 225 236 #define dirn (G.dirn ) 237 #define line bb_common_bufsiz1 226 238 #define INIT_G() do { \ 239 setup_common_bufsiz(); \ 227 240 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ 228 241 linemax = 1000; \ … … 231 244 replace = ""; \ 232 245 } while (0) 233 234 #define line bb_common_bufsiz1235 246 236 247 … … 746 757 break; 747 758 case 's': { 748 static const struct suffix_mult km_suffixes[] = {749 { "k", 1024 },750 { "m", 1024*1024 },751 { "", 0 }752 };753 759 ld->sizemax = xatou_sfx(&s[1], km_suffixes); 754 760 break; … … 1041 1047 if (opt & 2) if (!repl) repl = '_'; // -R 1042 1048 if (opt & 4) { // -l 1043 linemax = xatou_range(l, 0, BUFSIZ-26);1049 linemax = xatou_range(l, 0, COMMON_BUFSIZE-26); 1044 1050 if (linemax == 0) 1045 linemax = BUFSIZ-26;1051 linemax = COMMON_BUFSIZE-26; 1046 1052 if (linemax < 256) 1047 1053 linemax = 256;
Note:
See TracChangeset
for help on using the changeset viewer.