blob: 363e45049274ff975e50496d6fa68ef6304874a1 [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/*
Denys Vlasenkoe4dcba12010-10-28 18:57:19 +02003 * Prints out the previous and the current runlevel.
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +00004 *
Denys Vlasenkoe4dcba12010-10-28 18:57:19 +02005 * Version: @(#)runlevel 1.20 16-Apr-1997 MvS
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +00006 *
Denys Vlasenkoe4dcba12010-10-28 18:57:19 +02007 * This file is part of the sysvinit suite,
8 * Copyright 1991-1997 Miquel van Smoorenburg.
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +00009 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +020010 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000011 *
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}