From 4051a99f5fe4b1e1914e26924d166a629bf3c71e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 5 Dec 2016 13:56:40 +0100 Subject: svc: new applet (daemontools-compatible version of "sv") function old new delta sv - 1199 +1199 svc_main - 145 +145 packed_usage 30255 30364 +109 applet_names 2437 2441 +4 applet_main 1420 1424 +4 find_applet_by_name 125 126 +1 sv_main 1201 9 -1192 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 4/1 up/down: 1462/-1192) Total: 270 bytes Signed-off-by: Denys Vlasenko --- runit/sv.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 94 insertions(+), 18 deletions(-) (limited to 'runit') diff --git a/runit/sv.c b/runit/sv.c index 42abbbbb5..71865bd4f 100644 --- a/runit/sv.c +++ b/runit/sv.c @@ -166,26 +166,19 @@ Exit Codes //config: help //config: Default directory for services. //config: Defaults to "/var/service" +//config: +//config:config SVC +//config: bool "svc" +//config: default y +//config: help +//config: svc controls the state of services monitored by the runsv supervisor. +//config: It is comaptible with daemontools command with the same name. //applet:IF_SV(APPLET(sv, BB_DIR_USR_BIN, BB_SUID_DROP)) +//applet:IF_SV(APPLET(svc, BB_DIR_USR_BIN, BB_SUID_DROP)) //kbuild:lib-$(CONFIG_SV) += sv.o - -//usage:#define sv_trivial_usage -//usage: "[-v] [-w SEC] CMD SERVICE_DIR..." -//usage:#define sv_full_usage "\n\n" -//usage: "Control services monitored by runsv supervisor.\n" -//usage: "Commands (only first character is enough):\n" -//usage: "\n" -//usage: "status: query service status\n" -//usage: "up: if service isn't running, start it. If service stops, restart it\n" -//usage: "once: like 'up', but if service stops, don't restart it\n" -//usage: "down: send TERM and CONT signals. If ./run exits, start ./finish\n" -//usage: " if it exists. After it stops, don't restart service\n" -//usage: "exit: send TERM and CONT signals to service and log service. If they exit,\n" -//usage: " runsv exits too\n" -//usage: "pause, cont, hup, alarm, interrupt, quit, 1, 2, term, kill: send\n" -//usage: "STOP, CONT, HUP, ALRM, INT, QUIT, USR1, USR2, TERM, KILL signal to service" +//kbuild:lib-$(CONFIG_SVC) += sv.o #include #include "libbb.h" @@ -452,8 +445,22 @@ static int control(const char *a) return 1; } -int sv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; -int sv_main(int argc UNUSED_PARAM, char **argv) +//usage:#define sv_trivial_usage +//usage: "[-v] [-w SEC] CMD SERVICE_DIR..." +//usage:#define sv_full_usage "\n\n" +//usage: "Control services monitored by runsv supervisor.\n" +//usage: "Commands (only first character is enough):\n" +//usage: "\n" +//usage: "status: query service status\n" +//usage: "up: if service isn't running, start it. If service stops, restart it\n" +//usage: "once: like 'up', but if service stops, don't restart it\n" +//usage: "down: send TERM and CONT signals. If ./run exits, start ./finish\n" +//usage: " if it exists. After it stops, don't restart service\n" +//usage: "exit: send TERM and CONT signals to service and log service. If they exit,\n" +//usage: " runsv exits too\n" +//usage: "pause, cont, hup, alarm, interrupt, quit, 1, 2, term, kill: send\n" +//usage: "STOP, CONT, HUP, ALRM, INT, QUIT, USR1, USR2, TERM, KILL signal to service" +static int sv(char **argv) { char *x; char *action; @@ -634,3 +641,72 @@ int sv_main(int argc UNUSED_PARAM, char **argv) } return rc > 99 ? 99 : rc; } + +#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; + + INIT_G(); + + 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'; + + /* getopt32() was already called: + * reset the libc getopt() function, which keeps internal state. + */ +#ifdef __GLIBC__ + optind = 0; +#else /* BSD style */ + optind = 1; + /* optreset = 1; */ +#endif + + do { + if (opts & 1) { + int r; + command[0] = *optstring; + r = sv(argv); + if (r) + return 1; + } + optstring++; + opts >>= 1; + } while (opts); + + return 0; +} +#endif -- cgit v1.2.3-55-g6feb From 548620c18b1f0988dbeab1009788daf9f002e927 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 8 Dec 2016 12:24:48 +0100 Subject: randomconfig fixes Signed-off-by: Denys Vlasenko --- archival/bbunzip.c | 7 ++++++- archival/libarchive/Kbuild.src | 9 ++++++++- include/libbb.h | 12 ++++++++++-- libbb/Kbuild.src | 5 +++++ runit/sv.c | 2 +- 5 files changed, 30 insertions(+), 5 deletions(-) (limited to 'runit') diff --git a/archival/bbunzip.c b/archival/bbunzip.c index 7d5402e8d..d5db4627f 100644 --- a/archival/bbunzip.c +++ b/archival/bbunzip.c @@ -9,6 +9,8 @@ /* lzop_main() uses bbunpack(), need this: */ //kbuild:lib-$(CONFIG_LZOP) += bbunzip.o +/* bzip2_main() too: */ +//kbuild:lib-$(CONFIG_BZIP2) += bbunzip.o /* Note: must be kept in sync with archival/lzop.c */ enum { @@ -190,7 +192,10 @@ int FAST_FUNC bbunpack(char **argv, return exitcode; } -#if ENABLE_UNCOMPRESS || ENABLE_BUNZIP2 || ENABLE_UNLZMA || ENABLE_UNXZ +#if ENABLE_UNCOMPRESS \ + || ENABLE_BUNZIP2 || ENABLE_BZCAT \ + || ENABLE_UNLZMA || ENABLE_LZCAT || ENABLE_LZMA \ + || ENABLE_UNXZ || ENABLE_XZCAT || ENABLE_XZ static char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext) { diff --git a/archival/libarchive/Kbuild.src b/archival/libarchive/Kbuild.src index b159a786a..ad5c5c42d 100644 --- a/archival/libarchive/Kbuild.src +++ b/archival/libarchive/Kbuild.src @@ -48,16 +48,23 @@ lib-$(CONFIG_CPIO) += get_header_cpio.o lib-$(CONFIG_TAR) += get_header_tar.o unsafe_prefix.o lib-$(CONFIG_FEATURE_TAR_TO_COMMAND) += data_extract_to_command.o lib-$(CONFIG_LZOP) += lzo1x_1.o lzo1x_1o.o lzo1x_d.o +lib-$(CONFIG_UNLZOP) += lzo1x_1.o lzo1x_1o.o lzo1x_d.o +lib-$(CONFIG_LZOPCAT) += lzo1x_1.o lzo1x_1o.o lzo1x_d.o lib-$(CONFIG_LZOP_COMPR_HIGH) += lzo1x_9x.o lib-$(CONFIG_BUNZIP2) += open_transformer.o decompress_bunzip2.o +lib-$(CONFIG_BZCAT) += open_transformer.o decompress_bunzip2.o lib-$(CONFIG_UNLZMA) += open_transformer.o decompress_unlzma.o +lib-$(CONFIG_LZCAT) += open_transformer.o decompress_unlzma.o +lib-$(CONFIG_LZMA) += open_transformer.o decompress_unlzma.o lib-$(CONFIG_UNXZ) += open_transformer.o decompress_unxz.o +lib-$(CONFIG_XZCAT) += open_transformer.o decompress_unxz.o +lib-$(CONFIG_XZ) += open_transformer.o decompress_unxz.o lib-$(CONFIG_GUNZIP) += open_transformer.o decompress_gunzip.o +lib-$(CONFIG_ZCAT) += open_transformer.o decompress_gunzip.o lib-$(CONFIG_UNCOMPRESS) += open_transformer.o decompress_uncompress.o lib-$(CONFIG_UNZIP) += open_transformer.o decompress_gunzip.o unsafe_prefix.o lib-$(CONFIG_RPM2CPIO) += open_transformer.o decompress_gunzip.o get_header_cpio.o lib-$(CONFIG_RPM) += open_transformer.o decompress_gunzip.o get_header_cpio.o - lib-$(CONFIG_GZIP) += open_transformer.o lib-$(CONFIG_BZIP2) += open_transformer.o lib-$(CONFIG_LZOP) += open_transformer.o diff --git a/include/libbb.h b/include/libbb.h index bdafcf5a6..a42a2fba8 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1191,8 +1191,16 @@ int bb_cat(char** argv); /* If shell needs them, they exist even if not enabled as applets */ int echo_main(int argc, char** argv) IF_ECHO(MAIN_EXTERNALLY_VISIBLE); int printf_main(int argc, char **argv) IF_PRINTF(MAIN_EXTERNALLY_VISIBLE); -int test_main(int argc, char **argv) IF_TEST(MAIN_EXTERNALLY_VISIBLE); -int kill_main(int argc, char **argv) IF_KILL(MAIN_EXTERNALLY_VISIBLE); +int test_main(int argc, char **argv) +#if ENABLE_TEST || ENABLE_TEST1 || ENABLE_TEST2 + MAIN_EXTERNALLY_VISIBLE +#endif +; +int kill_main(int argc, char **argv) +#if ENABLE_KILL || ENABLE_KILLALL || ENABLE_KILLALL5 + MAIN_EXTERNALLY_VISIBLE +#endif +; /* Similar, but used by chgrp, not shell */ int chown_main(int argc, char **argv) IF_CHOWN(MAIN_EXTERNALLY_VISIBLE); /* Used by ftpd */ diff --git a/libbb/Kbuild.src b/libbb/Kbuild.src index 52a90e9a1..7440974b0 100644 --- a/libbb/Kbuild.src +++ b/libbb/Kbuild.src @@ -132,6 +132,7 @@ lib-$(CONFIG_TFTPD) += udp_io.o lib-$(CONFIG_TCPSVD) += udp_io.o lib-$(CONFIG_UDPSVD) += udp_io.o lib-$(CONFIG_TRACEROUTE) += udp_io.o +lib-$(CONFIG_TRACEROUTE6) += udp_io.o lib-$(CONFIG_LOSETUP) += loop.o lib-$(CONFIG_FEATURE_MOUNT_LOOP) += loop.o @@ -156,6 +157,7 @@ lib-$(CONFIG_FEATURE_FTP_AUTHENTICATION) += pw_encrypt.o lib-$(CONFIG_DF) += find_mount_point.o lib-$(CONFIG_MKFS_MINIX) += find_mount_point.o lib-$(CONFIG_MKFS_EXT2) += find_mount_point.o +lib-$(CONFIG_MKE2FS) += find_mount_point.o lib-$(CONFIG_MKFS_REISER) += find_mount_point.o lib-$(CONFIG_FSCK_MINIX) += find_mount_point.o lib-$(CONFIG_MOUNT) += find_mount_point.o @@ -168,6 +170,7 @@ lib-$(CONFIG_MPSTAT) += get_cpu_count.o lib-$(CONFIG_POWERTOP) += get_cpu_count.o lib-$(CONFIG_PING) += inet_cksum.o +lib-$(CONFIG_PING6) += inet_cksum.o lib-$(CONFIG_TRACEROUTE) += inet_cksum.o lib-$(CONFIG_TRACEROUTE6) += inet_cksum.o lib-$(CONFIG_UDHCPC) += inet_cksum.o @@ -181,6 +184,8 @@ lib-$(CONFIG_UDHCPD) += inet_cksum.o lib-$(CONFIG_AWK) += xregcomp.o lib-$(CONFIG_SED) += xregcomp.o lib-$(CONFIG_GREP) += xregcomp.o +lib-$(CONFIG_EGREP) += xregcomp.o +lib-$(CONFIG_FGREP) += xregcomp.o lib-$(CONFIG_EXPR) += xregcomp.o lib-$(CONFIG_MDEV) += xregcomp.o lib-$(CONFIG_LESS) += xregcomp.o diff --git a/runit/sv.c b/runit/sv.c index 71865bd4f..9e2132259 100644 --- a/runit/sv.c +++ b/runit/sv.c @@ -175,7 +175,7 @@ Exit Codes //config: It is comaptible with daemontools command with the same name. //applet:IF_SV(APPLET(sv, BB_DIR_USR_BIN, BB_SUID_DROP)) -//applet:IF_SV(APPLET(svc, BB_DIR_USR_BIN, BB_SUID_DROP)) +//applet:IF_SVC(APPLET(svc, BB_DIR_USR_BIN, BB_SUID_DROP)) //kbuild:lib-$(CONFIG_SV) += sv.o //kbuild:lib-$(CONFIG_SVC) += sv.o -- cgit v1.2.3-55-g6feb