aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/applets.h3
-rw-r--r--include/usage.h12
-rw-r--r--miscutils/Config.in9
-rw-r--r--miscutils/Makefile.in1
-rw-r--r--miscutils/runlevel.c43
5 files changed, 68 insertions, 0 deletions
diff --git a/include/applets.h b/include/applets.h
index 2b2c45d67..ec3a892d0 100644
--- a/include/applets.h
+++ b/include/applets.h
@@ -565,6 +565,9 @@
565#ifdef CONFIG_RUN_PARTS 565#ifdef CONFIG_RUN_PARTS
566 APPLET_ODDNAME("run-parts", run_parts_main, _BB_DIR_BIN, _BB_SUID_NEVER, run_parts) 566 APPLET_ODDNAME("run-parts", run_parts_main, _BB_DIR_BIN, _BB_SUID_NEVER, run_parts)
567#endif 567#endif
568#if BB_APPLET_RUNLEVEL
569 APPLET(runlevel, runlevel_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
570#endif
568#ifdef CONFIG_RX 571#ifdef CONFIG_RX
569 APPLET(rx, rx_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) 572 APPLET(rx, rx_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
570#endif 573#endif
diff --git a/include/usage.h b/include/usage.h
index 79a61d20a..a82230e41 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -2450,6 +2450,18 @@
2450 "\t-a ARG\tPass ARG as an argument for every program invoked\n" \ 2450 "\t-a ARG\tPass ARG as an argument for every program invoked\n" \
2451 "\t-u MASK\tSet the umask to MASK before executing every program" 2451 "\t-u MASK\tSet the umask to MASK before executing every program"
2452 2452
2453#if BB_APPLET_RUNLEVEL
2454#define runlevel_trivial_usage \
2455 "[utmp]"
2456#define runlevel_full_usage \
2457 "Find the current and previous system runlevel.\n\n" \
2458 "If no utmp file exists or if no runlevel record can be found,\n" \
2459 "runlevel prints \"unknown\""
2460#define runlevel_example_usage \
2461 "$ runlevel /var/run/utmp\n" \
2462 "N 2"
2463#endif
2464
2453#define rx_trivial_usage \ 2465#define rx_trivial_usage \
2454 "FILE" 2466 "FILE"
2455#define rx_full_usage \ 2467#define rx_full_usage \
diff --git a/miscutils/Config.in b/miscutils/Config.in
index f07ca36b3..4d81dde0d 100644
--- a/miscutils/Config.in
+++ b/miscutils/Config.in
@@ -255,6 +255,15 @@ config CONFIG_MT
255 to advance or rewind a tape past a specified number of archive 255 to advance or rewind a tape past a specified number of archive
256 files on the tape. 256 files on the tape.
257 257
258config BB_APPLET_RUNLEVEL
259 bool "runlevel"
260 default n
261 help
262 find the current and previous system runlevel.
263
264 This applet uses utmp but does not rely on busybox supporing
265 utmp on purpose. It is used by e.g. emdebian via /etc/init.d/rc.
266
258config CONFIG_RX 267config CONFIG_RX
259 bool "rx" 268 bool "rx"
260 default n 269 default n
diff --git a/miscutils/Makefile.in b/miscutils/Makefile.in
index 808ce36de..5bd522c11 100644
--- a/miscutils/Makefile.in
+++ b/miscutils/Makefile.in
@@ -24,6 +24,7 @@ MISCUTILS-${CONFIG_LESS} += less.o
24MISCUTILS-$(CONFIG_MAKEDEVS) += makedevs.o 24MISCUTILS-$(CONFIG_MAKEDEVS) += makedevs.o
25MISCUTILS-$(CONFIG_MOUNTPOINT) += mountpoint.o 25MISCUTILS-$(CONFIG_MOUNTPOINT) += mountpoint.o
26MISCUTILS-$(CONFIG_MT) += mt.o 26MISCUTILS-$(CONFIG_MT) += mt.o
27MISCUTILS-$(BB_APPLET_RUNLEVEL) += runlevel.o
27MISCUTILS-$(CONFIG_RX) += rx.o 28MISCUTILS-$(CONFIG_RX) += rx.o
28MISCUTILS-$(CONFIG_SETSID) += setsid.o 29MISCUTILS-$(CONFIG_SETSID) += setsid.o
29MISCUTILS-$(CONFIG_STRINGS) += strings.o 30MISCUTILS-$(CONFIG_STRINGS) += strings.o
diff --git a/miscutils/runlevel.c b/miscutils/runlevel.c
new file mode 100644
index 000000000..dfa846f81
--- /dev/null
+++ b/miscutils/runlevel.c
@@ -0,0 +1,43 @@
1/*
2 * runlevel Prints out the previous and the current runlevel.
3 *
4 * Version: @(#)runlevel 1.20 16-Apr-1997 MvS
5 *
6 * This file is part of the sysvinit suite,
7 * Copyright 1991-1997 Miquel van Smoorenburg.
8 *
9 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
10 *
11 * initially busyboxified by Bernhard Fischer
12 */
13
14#include <stdio.h>
15#include <utmp.h>
16#include <time.h>
17#include <stdlib.h>
18
19#include "busybox.h"
20
21int runlevel_main(int argc, char *argv[])
22{
23 struct utmp *ut;
24 char prev;
25
26 if (argc > 1) utmpname(argv[1]);
27
28 setutent();
29 while ((ut = getutent()) != NULL) {
30 if (ut->ut_type == RUN_LVL) {
31 prev = ut->ut_pid / 256;
32 if (prev == 0) prev = 'N';
33 printf("%c %c\n", prev, ut->ut_pid % 256);
34 endutent();
35 return (0);
36 }
37 }
38
39 printf("unknown\n");
40 endutent();
41 return (1);
42}
43