1 /* vi: set sw=4 ts=4: */
3 * Prints out the previous and the current runlevel.
5 * Version: @(#)runlevel 1.20 16-Apr-1997 MvS
7 * This file is part of the sysvinit suite,
8 * Copyright 1991-1997 Miquel van Smoorenburg.
10 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
12 * initially busyboxified by Bernhard Reutner-Fischer
14 //config:config RUNLEVEL
15 //config: bool "runlevel"
17 //config: depends on FEATURE_UTMP
19 //config: find the current and previous system runlevel.
21 //config: This applet uses utmp but does not rely on busybox supporing
22 //config: utmp on purpose. It is used by e.g. emdebian via /etc/init.d/rc.
24 //usage:#define runlevel_trivial_usage
26 //usage:#define runlevel_full_usage "\n\n"
27 //usage: "Find the current and previous system runlevel\n"
29 //usage: "If no utmp FILE exists or if no runlevel record can be found,\n"
30 //usage: "print \"unknown\""
32 //usage:#define runlevel_example_usage
33 //usage: "$ runlevel /var/run/utmp\n"
38 int runlevel_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
39 int runlevel_main(int argc UNUSED_PARAM, char **argv)
44 if (argv[1]) utmpxname(argv[1]);
47 while ((ut = getutxent()) != NULL) {
48 if (ut->ut_type == RUN_LVL) {
49 prev = ut->ut_pid / 256;
50 if (prev == 0) prev = 'N';
51 printf("%c %c\n", prev, ut->ut_pid % 256);
52 if (ENABLE_FEATURE_CLEAN_UP)
60 if (ENABLE_FEATURE_CLEAN_UP)