aboutsummaryrefslogtreecommitdiff
path: root/runit/sv.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2021-03-24 11:55:30 +0000
committerRon Yorston <rmy@pobox.com>2021-03-24 12:43:15 +0000
commit355a7a6c1e9626b7afe8758a6095f3cf275c52e1 (patch)
tree6dab679c15b049cab97212e0b43077132eec1fbe /runit/sv.c
parent71ecc8033e6989996057b32577e71148fd544596 (diff)
parent889425812b5cda8b3394d73253cbde7355fb1115 (diff)
downloadbusybox-w32-w32_1_26_2.tar.gz
busybox-w32-w32_1_26_2.tar.bz2
busybox-w32-w32_1_26_2.zip
Merge tag '1_26_2' into w32_1_26_2w32_1_26_2
Diffstat (limited to 'runit/sv.c')
-rw-r--r--runit/sv.c112
1 files changed, 94 insertions, 18 deletions
diff --git a/runit/sv.c b/runit/sv.c
index 42abbbbb5..9e2132259 100644
--- a/runit/sv.c
+++ b/runit/sv.c
@@ -166,26 +166,19 @@ Exit Codes
166//config: help 166//config: help
167//config: Default directory for services. 167//config: Default directory for services.
168//config: Defaults to "/var/service" 168//config: Defaults to "/var/service"
169//config:
170//config:config SVC
171//config: bool "svc"
172//config: default y
173//config: help
174//config: svc controls the state of services monitored by the runsv supervisor.
175//config: It is comaptible with daemontools command with the same name.
169 176
170//applet:IF_SV(APPLET(sv, BB_DIR_USR_BIN, BB_SUID_DROP)) 177//applet:IF_SV(APPLET(sv, BB_DIR_USR_BIN, BB_SUID_DROP))
178//applet:IF_SVC(APPLET(svc, BB_DIR_USR_BIN, BB_SUID_DROP))
171 179
172//kbuild:lib-$(CONFIG_SV) += sv.o 180//kbuild:lib-$(CONFIG_SV) += sv.o
173 181//kbuild:lib-$(CONFIG_SVC) += sv.o
174//usage:#define sv_trivial_usage
175//usage: "[-v] [-w SEC] CMD SERVICE_DIR..."
176//usage:#define sv_full_usage "\n\n"
177//usage: "Control services monitored by runsv supervisor.\n"
178//usage: "Commands (only first character is enough):\n"
179//usage: "\n"
180//usage: "status: query service status\n"
181//usage: "up: if service isn't running, start it. If service stops, restart it\n"
182//usage: "once: like 'up', but if service stops, don't restart it\n"
183//usage: "down: send TERM and CONT signals. If ./run exits, start ./finish\n"
184//usage: " if it exists. After it stops, don't restart service\n"
185//usage: "exit: send TERM and CONT signals to service and log service. If they exit,\n"
186//usage: " runsv exits too\n"
187//usage: "pause, cont, hup, alarm, interrupt, quit, 1, 2, term, kill: send\n"
188//usage: "STOP, CONT, HUP, ALRM, INT, QUIT, USR1, USR2, TERM, KILL signal to service"
189 182
190#include <sys/file.h> 183#include <sys/file.h>
191#include "libbb.h" 184#include "libbb.h"
@@ -452,8 +445,22 @@ static int control(const char *a)
452 return 1; 445 return 1;
453} 446}
454 447
455int sv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 448//usage:#define sv_trivial_usage
456int sv_main(int argc UNUSED_PARAM, char **argv) 449//usage: "[-v] [-w SEC] CMD SERVICE_DIR..."
450//usage:#define sv_full_usage "\n\n"
451//usage: "Control services monitored by runsv supervisor.\n"
452//usage: "Commands (only first character is enough):\n"
453//usage: "\n"
454//usage: "status: query service status\n"
455//usage: "up: if service isn't running, start it. If service stops, restart it\n"
456//usage: "once: like 'up', but if service stops, don't restart it\n"
457//usage: "down: send TERM and CONT signals. If ./run exits, start ./finish\n"
458//usage: " if it exists. After it stops, don't restart service\n"
459//usage: "exit: send TERM and CONT signals to service and log service. If they exit,\n"
460//usage: " runsv exits too\n"
461//usage: "pause, cont, hup, alarm, interrupt, quit, 1, 2, term, kill: send\n"
462//usage: "STOP, CONT, HUP, ALRM, INT, QUIT, USR1, USR2, TERM, KILL signal to service"
463static int sv(char **argv)
457{ 464{
458 char *x; 465 char *x;
459 char *action; 466 char *action;
@@ -634,3 +641,72 @@ int sv_main(int argc UNUSED_PARAM, char **argv)
634 } 641 }
635 return rc > 99 ? 99 : rc; 642 return rc > 99 ? 99 : rc;
636} 643}
644
645#if ENABLE_SV
646int sv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
647int sv_main(int argc UNUSED_PARAM, char **argv)
648{
649 return sv(argv);
650}
651#endif
652
653//usage:#define svc_trivial_usage
654//usage: "[-udopchaitkx] SERVICE_DIR..."
655//usage:#define svc_full_usage "\n\n"
656//usage: "Control services monitored by runsv supervisor"
657//usage: "\n"
658//usage: "\n"" -u If service is not running, start it; restart if it stops"
659//usage: "\n"" -d If service is running, send TERM+CONT signals; do not restart it"
660//usage: "\n"" -o Once: if service is not running, start it; do not restart it"
661//usage: "\n"" -pchaitk Send STOP, CONT, HUP, ALRM, INT, TERM, KILL signal to service"
662//usage: "\n"" -x Exit: runsv will exit as soon as the service is down"
663#if ENABLE_SVC
664int svc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
665int svc_main(int argc UNUSED_PARAM, char **argv)
666{
667 char command[2];
668 const char *optstring;
669 unsigned opts;
670
671 INIT_G();
672
673 optstring = "udopchaitkx";
674 opts = getopt32(argv, optstring);
675 argv += optind;
676 if (!argv[0] || !opts)
677 bb_show_usage();
678
679 argv -= 2;
680 if (optind > 2) {
681 argv--;
682 argv[2] = (char*)"--";
683 }
684 argv[0] = (char*)"sv";
685 argv[1] = command;
686 command[1] = '\0';
687
688 /* getopt32() was already called:
689 * reset the libc getopt() function, which keeps internal state.
690 */
691#ifdef __GLIBC__
692 optind = 0;
693#else /* BSD style */
694 optind = 1;
695 /* optreset = 1; */
696#endif
697
698 do {
699 if (opts & 1) {
700 int r;
701 command[0] = *optstring;
702 r = sv(argv);
703 if (r)
704 return 1;
705 }
706 optstring++;
707 opts >>= 1;
708 } while (opts);
709
710 return 0;
711}
712#endif