blob: f51a647be50c18df165cc71a5212aaa61f3b9abb [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 *
12 * initially busyboxified by Bernhard Fischer
13 */
14
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000015#include <utmp.h>
Denis Vlasenko9a7d38f2007-05-31 22:42:12 +000016#include "libbb.h"
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000017
Bernhard Reutner-Fischerfebe3c42007-04-04 20:52:03 +000018int runlevel_main(int argc, char **argv);
19int runlevel_main(int argc, char **argv)
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000020{
Denis Vlasenkoc2905632006-09-23 16:01:09 +000021 struct utmp *ut;
22 char prev;
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000023
Denis Vlasenkoc2905632006-09-23 16:01:09 +000024 if (argc > 1) utmpname(argv[1]);
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000025
Denis Vlasenkoc2905632006-09-23 16:01:09 +000026 setutent();
27 while ((ut = getutent()) != NULL) {
28 if (ut->ut_type == RUN_LVL) {
29 prev = ut->ut_pid / 256;
30 if (prev == 0) prev = 'N';
31 printf("%c %c\n", prev, ut->ut_pid % 256);
Denis Vlasenko9a7d38f2007-05-31 22:42:12 +000032 if (ENABLE_FEATURE_CLEAN_UP)
33 endutent();
Denis Vlasenkoc2905632006-09-23 16:01:09 +000034 return 0;
35 }
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000036 }
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000037
Denis Vlasenkoc2905632006-09-23 16:01:09 +000038 puts("unknown");
Denis Vlasenko2f6ae432007-07-19 22:50:47 +000039
Denis Vlasenko9a7d38f2007-05-31 22:42:12 +000040 if (ENABLE_FEATURE_CLEAN_UP)
41 endutent();
Denis Vlasenkoc2905632006-09-23 16:01:09 +000042 return 1;
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000043}