summaryrefslogtreecommitdiffhomepage
path: root/klibc-utils/nuke.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-08-18 19:15:29 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-08-18 19:15:29 +0200
commitab77e81a8527fa11a4f9392d97c2da037d6f4f98 (patch)
treed11608662dd14b776a4c4d30a6039d476231ca58 /klibc-utils/nuke.c
parent79747415d6db1f85389247522304c941b4287f9b (diff)
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>
Diffstat (limited to 'klibc-utils/nuke.c')
-rw-r--r--klibc-utils/nuke.c46
1 files changed, 46 insertions, 0 deletions
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 @@
+/*
+ * Copyright (c) 2017 Denys Vlasenko <vda.linux@googlemail.com>
+ *
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
+ */
+//config:config NUKE
+//config: bool "nuke"
+//config: default y
+//config: help
+//config: Alias to "rm -rf".
+
+//applet:IF_NUKE(APPLET_NOEXEC(nuke, nuke, BB_DIR_BIN, BB_SUID_DROP, nuke))
+
+//kbuild:lib-$(CONFIG_NUKE) += nuke.o
+
+//usage:#define nuke_trivial_usage
+//usage: "DIR..."
+//usage:#define nuke_full_usage "\n\n"
+//usage: "Resursively remove DIRs"
+
+#include "libbb.h"
+
+/* This is a NOEXEC applet. Be very careful! */
+
+int nuke_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int nuke_main(int argc UNUSED_PARAM, char **argv)
+{
+// klibc-utils do not check opts, will try to delete "-dir" args
+ //opt = getopt32(argv, "");
+ //argv += optind;
+
+ while (*++argv) {
+#if 0
+// klibc-utils do not check this, will happily operate on ".."
+ const char *base = bb_get_last_path_component_strip(*argv);
+ if (DOT_OR_DOTDOT(base)) {
+ bb_error_msg("can't remove '.' or '..'");
+ continue;
+ }
+#endif
+ remove_file(*argv, FILEUTILS_FORCE | FILEUTILS_RECUR);
+ }
+
+// klibc-utils do not indicate errors
+ return EXIT_SUCCESS;
+}