+#endif
+
+#if ENABLE_SV
+int sv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int sv_main(int argc UNUSED_PARAM, char **argv)
+{
+ return sv(argv);
+}
+#endif
+
+//usage:#define svc_trivial_usage
+//usage: "[-udopchaitkx] SERVICE_DIR..."
+//usage:#define svc_full_usage "\n\n"
+//usage: "Control services monitored by runsv supervisor"
+//usage: "\n"
+//usage: "\n"" -u If service is not running, start it; restart if it stops"
+//usage: "\n"" -d If service is running, send TERM+CONT signals; do not restart it"
+//usage: "\n"" -o Once: if service is not running, start it; do not restart it"
+//usage: "\n"" -pchaitk Send STOP, CONT, HUP, ALRM, INT, TERM, KILL signal to service"
+//usage: "\n"" -x Exit: runsv will exit as soon as the service is down"
+#if ENABLE_SVC
+int svc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int svc_main(int argc UNUSED_PARAM, char **argv)
+{
+ char command[2];
+ const char *optstring;
+ unsigned opts;
+
+ optstring = "udopchaitkx";
+ opts = getopt32(argv, optstring);
+ argv += optind;
+ if (!argv[0] || !opts)
+ bb_show_usage();
+
+ argv -= 2;
+ if (optind > 2) {
+ argv--;
+ argv[2] = (char*)"--";
+ }
+ argv[0] = (char*)"sv";
+ argv[1] = command;
+ command[1] = '\0';
+
+ do {
+ if (opts & 1) {
+ int r;
+
+ command[0] = *optstring;
+
+ /* getopt() was already called by getopt32():
+ * reset the libc getopt() function's internal state.
+ */
+ GETOPT_RESET();
+ r = sv(argv);
+ if (r)
+ return 1;
+ }
+ optstring++;
+ opts >>= 1;
+ } while (opts);
+
+ return 0;
+}
+#endif
+
+//usage:#define svok_trivial_usage
+//usage: "SERVICE_DIR"
+//usage:#define svok_full_usage "\n\n"
+//usage: "Check whether runsv supervisor is running.\n"
+//usage: "Exit code is 0 if it does, 100 if it does not,\n"
+//usage: "111 (with error message) if SERVICE_DIR does not exist."
+#if ENABLE_SVOK
+int svok_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int svok_main(int argc UNUSED_PARAM, char **argv)
+{
+ const char *dir = argv[1];
+
+ if (!dir)
+ bb_show_usage();
+
+ xfunc_error_retval = 111;
+
+ /*
+ * daemontools has no concept of "default service dir", runit does.
+ * Let's act as runit.
+ */
+ if (dir[0] != '/' && dir[0] != '.'
+ && !last_char_is(dir, '/')
+ ) {
+ xchdir(CONFIG_SV_DEFAULT_SERVICE_DIR);
+ }
+
+ xchdir(dir);
+ if (open("supervise/ok", O_WRONLY) < 0) {
+ if (errno == ENOENT || errno == ENXIO)
+ return 100;
+ bb_perror_msg_and_die("can't open '%s'", "supervise/ok");
+ }
+
+ return 0;
+}
+#endif