diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-18 19:15:29 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-18 19:15:29 +0200 |
commit | ab77e81a8527fa11a4f9392d97c2da037d6f4f98 (patch) | |
tree | d11608662dd14b776a4c4d30a6039d476231ca58 | |
parent | 79747415d6db1f85389247522304c941b4287f9b (diff) | |
download | busybox-w32-ab77e81a8527fa11a4f9392d97c2da037d6f4f98.tar.gz busybox-w32-ab77e81a8527fa11a4f9392d97c2da037d6f4f98.tar.bz2 busybox-w32-ab77e81a8527fa11a4f9392d97c2da037d6f4f98.zip |
klibc-utils: new applets: resume, nuke, minips
minips is a pure alias to ps, just in case someone needs 100% klibc-utils compat.
nuke is a primitive version of "rm -rf" without options and error checks. ~30 bytes.
resume is a tool for initramfs which resumes from a given block device.
function old new delta
resume_main - 582 +582
packed_usage 31640 31712 +72
nuke_main - 28 +28
xstrtoull - 24 +24
applet_names 2646 2665 +19
applet_main 1532 1544 +12
applet_suid 96 97 +1
applet_install_loc 192 193 +1
applet_flags 96 97 +1
------------------------------------------------------------------------------
(add/remove: 5/0 grow/shrink: 6/0 up/down: 740/0) Total: 740 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | Config.in | 1 | ||||
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | klibc-utils/Config.src | 10 | ||||
-rw-r--r-- | klibc-utils/Kbuild.src | 9 | ||||
-rw-r--r-- | klibc-utils/minips.c | 12 | ||||
-rw-r--r-- | klibc-utils/nuke.c | 46 | ||||
-rw-r--r-- | klibc-utils/resume.c | 115 | ||||
-rw-r--r-- | procps/ps.c | 5 | ||||
-rw-r--r-- | scripts/Makefile.IMA | 3 |
9 files changed, 201 insertions, 1 deletions
@@ -691,6 +691,7 @@ source archival/Config.in | |||
691 | source coreutils/Config.in | 691 | source coreutils/Config.in |
692 | source console-tools/Config.in | 692 | source console-tools/Config.in |
693 | source debianutils/Config.in | 693 | source debianutils/Config.in |
694 | source klibc-utils/Config.in | ||
694 | source editors/Config.in | 695 | source editors/Config.in |
695 | source findutils/Config.in | 696 | source findutils/Config.in |
696 | source init/Config.in | 697 | source init/Config.in |
@@ -470,6 +470,7 @@ libs-y := \ | |||
470 | coreutils/ \ | 470 | coreutils/ \ |
471 | coreutils/libcoreutils/ \ | 471 | coreutils/libcoreutils/ \ |
472 | debianutils/ \ | 472 | debianutils/ \ |
473 | klibc-utils/ \ | ||
473 | e2fsprogs/ \ | 474 | e2fsprogs/ \ |
474 | editors/ \ | 475 | editors/ \ |
475 | findutils/ \ | 476 | findutils/ \ |
diff --git a/klibc-utils/Config.src b/klibc-utils/Config.src new file mode 100644 index 000000000..fe7cb1315 --- /dev/null +++ b/klibc-utils/Config.src | |||
@@ -0,0 +1,10 @@ | |||
1 | # | ||
2 | # For a description of the syntax of this configuration file, | ||
3 | # see scripts/kbuild/config-language.txt. | ||
4 | # | ||
5 | |||
6 | menu "klibc-utils" | ||
7 | |||
8 | INSERT | ||
9 | |||
10 | endmenu | ||
diff --git a/klibc-utils/Kbuild.src b/klibc-utils/Kbuild.src new file mode 100644 index 000000000..6b4fb7470 --- /dev/null +++ b/klibc-utils/Kbuild.src | |||
@@ -0,0 +1,9 @@ | |||
1 | # Makefile for busybox | ||
2 | # | ||
3 | # Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org> | ||
4 | # | ||
5 | # Licensed under GPLv2, see file LICENSE in this source tree. | ||
6 | |||
7 | lib-y:= | ||
8 | |||
9 | INSERT | ||
diff --git a/klibc-utils/minips.c b/klibc-utils/minips.c new file mode 100644 index 000000000..96ce8868d --- /dev/null +++ b/klibc-utils/minips.c | |||
@@ -0,0 +1,12 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2017 Denys Vlasenko <vda.linux@googlemail.com> | ||
3 | * | ||
4 | * Licensed under GPLv2, see file LICENSE in this source tree. | ||
5 | */ | ||
6 | //config:config MINIPS | ||
7 | //config: bool "minips (11 kb)" | ||
8 | //config: default n # for god's sake, just use "ps" name in your scripts | ||
9 | //config: help | ||
10 | //config: Alias to "ps". | ||
11 | |||
12 | /* applet abd kbuild hooks are in ps.c */ | ||
diff --git a/klibc-utils/nuke.c b/klibc-utils/nuke.c new file mode 100644 index 000000000..363e03cce --- /dev/null +++ b/klibc-utils/nuke.c | |||
@@ -0,0 +1,46 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2017 Denys Vlasenko <vda.linux@googlemail.com> | ||
3 | * | ||
4 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. | ||
5 | */ | ||
6 | //config:config NUKE | ||
7 | //config: bool "nuke" | ||
8 | //config: default y | ||
9 | //config: help | ||
10 | //config: Alias to "rm -rf". | ||
11 | |||
12 | //applet:IF_NUKE(APPLET_NOEXEC(nuke, nuke, BB_DIR_BIN, BB_SUID_DROP, nuke)) | ||
13 | |||
14 | //kbuild:lib-$(CONFIG_NUKE) += nuke.o | ||
15 | |||
16 | //usage:#define nuke_trivial_usage | ||
17 | //usage: "DIR..." | ||
18 | //usage:#define nuke_full_usage "\n\n" | ||
19 | //usage: "Resursively remove DIRs" | ||
20 | |||
21 | #include "libbb.h" | ||
22 | |||
23 | /* This is a NOEXEC applet. Be very careful! */ | ||
24 | |||
25 | int nuke_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||
26 | int nuke_main(int argc UNUSED_PARAM, char **argv) | ||
27 | { | ||
28 | // klibc-utils do not check opts, will try to delete "-dir" args | ||
29 | //opt = getopt32(argv, ""); | ||
30 | //argv += optind; | ||
31 | |||
32 | while (*++argv) { | ||
33 | #if 0 | ||
34 | // klibc-utils do not check this, will happily operate on ".." | ||
35 | const char *base = bb_get_last_path_component_strip(*argv); | ||
36 | if (DOT_OR_DOTDOT(base)) { | ||
37 | bb_error_msg("can't remove '.' or '..'"); | ||
38 | continue; | ||
39 | } | ||
40 | #endif | ||
41 | remove_file(*argv, FILEUTILS_FORCE | FILEUTILS_RECUR); | ||
42 | } | ||
43 | |||
44 | // klibc-utils do not indicate errors | ||
45 | return EXIT_SUCCESS; | ||
46 | } | ||
diff --git a/klibc-utils/resume.c b/klibc-utils/resume.c new file mode 100644 index 000000000..de142f350 --- /dev/null +++ b/klibc-utils/resume.c | |||
@@ -0,0 +1,115 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2017 Denys Vlasenko <vda.linux@googlemail.com> | ||
3 | * | ||
4 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. | ||
5 | */ | ||
6 | //config:config RESUME | ||
7 | //config: bool "resume" | ||
8 | //config: default y | ||
9 | //config: help | ||
10 | //config: Resume from saved "suspend-to-disk" image | ||
11 | |||
12 | //applet:IF_RESUME(APPLET_NOEXEC(resume, resume, BB_DIR_BIN, BB_SUID_DROP, resume)) | ||
13 | |||
14 | //kbuild:lib-$(CONFIG_RESUME) += resume.o | ||
15 | |||
16 | #include "libbb.h" | ||
17 | |||
18 | /* This is a NOEXEC applet. Be very careful! */ | ||
19 | |||
20 | /* name_to_dev_t() in klibc-utils supports extended device name formats, | ||
21 | * apart from the usual case where /dev/NAME already exists. | ||
22 | * | ||
23 | * - device number in hexadecimal represents itself (in dev_t layout). | ||
24 | * - device number in major:minor decimal represents itself. | ||
25 | * - if block device (or partition) with this name is found in sysfs. | ||
26 | * - if /dev/ prefix is not given, it is assumed. | ||
27 | * | ||
28 | * klibc-utils also recognizes these, but they don't work | ||
29 | * for "resume" tool purposes (thus we don't support them (yet?)): | ||
30 | * - /dev/nfs | ||
31 | * - /dev/ram (alias to /dev/ram0) | ||
32 | * - /dev/mtd | ||
33 | */ | ||
34 | static dev_t name_to_dev_t(const char *devname) | ||
35 | { | ||
36 | char devfile[sizeof(int)*3 * 2 + 4]; | ||
37 | char *sysname; | ||
38 | unsigned major_num, minor_num; | ||
39 | struct stat st; | ||
40 | int r; | ||
41 | |||
42 | if (strncmp(devname, "/dev/", 5) != 0) { | ||
43 | char *cptr; | ||
44 | |||
45 | cptr = strchr(devname, ':'); | ||
46 | if (cptr) { | ||
47 | /* Colon-separated decimal device number? */ | ||
48 | *cptr = '\0'; | ||
49 | major_num = bb_strtou(devname, NULL, 10); | ||
50 | if (!errno) | ||
51 | minor_num = bb_strtou(cptr + 1, NULL, 10); | ||
52 | *cptr = ':'; | ||
53 | if (!errno) | ||
54 | return makedev(major_num, minor_num); | ||
55 | } else { | ||
56 | /* Hexadecimal device number? */ | ||
57 | dev_t res = (dev_t) bb_strtoul(devname, NULL, 16); | ||
58 | if (!errno) | ||
59 | return res; | ||
60 | } | ||
61 | |||
62 | devname = xasprintf("/dev/%s", devname); | ||
63 | } | ||
64 | /* Now devname is always "/dev/FOO" */ | ||
65 | |||
66 | if (stat(devname, &st) == 0 && S_ISBLK(st.st_mode)) | ||
67 | return st.st_rdev; | ||
68 | |||
69 | /* Full blockdevs as well as partitions may be visible | ||
70 | * in /sys/class/block/ even if /dev is not populated. | ||
71 | */ | ||
72 | sysname = xasprintf("/sys/class/block/%s/dev", devname + 5); | ||
73 | r = open_read_close(sysname, devfile, sizeof(devfile) - 1); | ||
74 | //free(sysname); | ||
75 | if (r > 0) { | ||
76 | devfile[r] = '\0'; | ||
77 | if (sscanf(devfile, "%u:%u", &major_num, &minor_num) == 2) { | ||
78 | return makedev(major_num, minor_num); | ||
79 | } | ||
80 | } | ||
81 | |||
82 | return (dev_t) 0; | ||
83 | } | ||
84 | |||
85 | //usage:#define resume_trivial_usage | ||
86 | //usage: "BLOCKDEV [OFFSET]" | ||
87 | //usage:#define resume_full_usage "\n" | ||
88 | //usage: "\n""Restore system state from 'suspend-to-disk' data in BLOCKDEV" | ||
89 | |||
90 | int resume_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||
91 | int resume_main(int argc UNUSED_PARAM, char **argv) | ||
92 | { | ||
93 | unsigned long long ofs; | ||
94 | dev_t resume_device; | ||
95 | char *s; | ||
96 | int fd; | ||
97 | |||
98 | argv++; | ||
99 | if (!argv[0]) | ||
100 | bb_show_usage(); | ||
101 | |||
102 | resume_device = name_to_dev_t(argv[0]); | ||
103 | if (major(resume_device) == 0) { | ||
104 | bb_error_msg_and_die("invalid resume device: %s", argv[0]); | ||
105 | } | ||
106 | ofs = (argv[1] ? xstrtoull(argv[1], 0) : 0); | ||
107 | |||
108 | fd = xopen("/sys/power/resume", O_WRONLY); | ||
109 | s = xasprintf("%u:%u:%llu", major(resume_device), minor(resume_device), ofs); | ||
110 | |||
111 | xwrite_str(fd, s); | ||
112 | /* if write() returns, resume did not succeed */ | ||
113 | |||
114 | return EXIT_FAILURE; /* klibc-utils exits -1 aka 255 */ | ||
115 | } | ||
diff --git a/procps/ps.c b/procps/ps.c index 646b1144e..7edf6dbd1 100644 --- a/procps/ps.c +++ b/procps/ps.c | |||
@@ -50,9 +50,12 @@ | |||
50 | //config: Include support for measuring HZ on old kernels and non-ELF systems | 50 | //config: Include support for measuring HZ on old kernels and non-ELF systems |
51 | //config: (if you are on Linux 2.4.0+ and use ELF, you don't need this) | 51 | //config: (if you are on Linux 2.4.0+ and use ELF, you don't need this) |
52 | 52 | ||
53 | //applet:IF_PS(APPLET_NOEXEC(ps, ps, BB_DIR_BIN, BB_SUID_DROP, ps)) | 53 | // APPLET_NOEXEC:name main location suid_type help |
54 | //applet:IF_PS( APPLET_NOEXEC(ps, ps, BB_DIR_BIN, BB_SUID_DROP, ps)) | ||
55 | //applet:IF_MINIPS(APPLET_NOEXEC(minips, ps, BB_DIR_BIN, BB_SUID_DROP, ps)) | ||
54 | 56 | ||
55 | //kbuild:lib-$(CONFIG_PS) += ps.o | 57 | //kbuild:lib-$(CONFIG_PS) += ps.o |
58 | //kbuild:lib-$(CONFIG_MINIPS) += ps.o | ||
56 | 59 | ||
57 | //usage:#if ENABLE_DESKTOP | 60 | //usage:#if ENABLE_DESKTOP |
58 | //usage: | 61 | //usage: |
diff --git a/scripts/Makefile.IMA b/scripts/Makefile.IMA index 0eced2982..f155108d7 100644 --- a/scripts/Makefile.IMA +++ b/scripts/Makefile.IMA | |||
@@ -115,6 +115,9 @@ lib-y:= | |||
115 | include debianutils/Kbuild | 115 | include debianutils/Kbuild |
116 | lib-all-y += $(patsubst %,debianutils/%,$(sort $(lib-y))) | 116 | lib-all-y += $(patsubst %,debianutils/%,$(sort $(lib-y))) |
117 | lib-y:= | 117 | lib-y:= |
118 | include klibc-utils/Kbuild | ||
119 | lib-all-y += $(patsubst %,klibc-utils/%,$(sort $(lib-y))) | ||
120 | lib-y:= | ||
118 | include runit/Kbuild | 121 | include runit/Kbuild |
119 | lib-all-y += $(patsubst %,runit/%,$(sort $(lib-y))) | 122 | lib-all-y += $(patsubst %,runit/%,$(sort $(lib-y))) |
120 | lib-y:= | 123 | lib-y:= |