blob: 83b5a77d49599a2dac1fe3d0187703b0977022a1 [file] [log] [blame]
Bernhard Reutner-Fischerc89982d2006-06-03 19:49:21 +00001/* vi: set sw=4 ts=4: */
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +00002/*
3 * runlevel Prints out the previous and the current runlevel.
4 *
5 * Version: @(#)runlevel 1.20 16-Apr-1997 MvS
6 *
7 * This file is part of the sysvinit suite,
8 * Copyright 1991-1997 Miquel van Smoorenburg.
9 *
10 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
11 *
Bernhard Reutner-Fischer6c4dade2008-09-25 12:13:34 +000012 * initially busyboxified by Bernhard Reutner-Fischer
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000013 */
Denis Vlasenko9a7d38f2007-05-31 22:42:12 +000014#include "libbb.h"
Denys Vlasenko1e113602009-11-26 15:26:14 +010015#include <utmp.h>
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000016
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000017int runlevel_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denys Vlasenko1e113602009-11-26 15:26:14 +010018int runlevel_main(int argc UNUSED_PARAM, char **argv)
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000019{
Denis Vlasenkoc2905632006-09-23 16:01:09 +000020 struct utmp *ut;
21 char prev;
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000022
Denys Vlasenko1e113602009-11-26 15:26:14 +010023 if (argv[1]) utmpname(argv[1]);
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000024
Denis Vlasenkoc2905632006-09-23 16:01:09 +000025 setutent();
26 while ((ut = getutent()) != NULL) {
27 if (ut->ut_type == RUN_LVL) {
28 prev = ut->ut_pid / 256;
29 if (prev == 0) prev = 'N';
30 printf("%c %c\n", prev, ut->ut_pid % 256);
Denis Vlasenko9a7d38f2007-05-31 22:42:12 +000031 if (ENABLE_FEATURE_CLEAN_UP)
32 endutent();
Denis Vlasenkoc2905632006-09-23 16:01:09 +000033 return 0;
34 }
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000035 }
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000036
Denis Vlasenkoc2905632006-09-23 16:01:09 +000037 puts("unknown");
Denis Vlasenko2f6ae432007-07-19 22:50:47 +000038
Denis Vlasenko9a7d38f2007-05-31 22:42:12 +000039 if (ENABLE_FEATURE_CLEAN_UP)
40 endutent();
Denis Vlasenkoc2905632006-09-23 16:01:09 +000041 return 1;
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000042}