blob: 7024361e780c97d4a0b9dc6df4319cccea765293 [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"
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000015
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000016int runlevel_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denys Vlasenko1e113602009-11-26 15:26:14 +010017int runlevel_main(int argc UNUSED_PARAM, char **argv)
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000018{
Denis Vlasenkoc2905632006-09-23 16:01:09 +000019 struct utmp *ut;
20 char prev;
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000021
Denys Vlasenko1e113602009-11-26 15:26:14 +010022 if (argv[1]) utmpname(argv[1]);
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000023
Denis Vlasenkoc2905632006-09-23 16:01:09 +000024 setutent();
25 while ((ut = getutent()) != NULL) {
26 if (ut->ut_type == RUN_LVL) {
27 prev = ut->ut_pid / 256;
28 if (prev == 0) prev = 'N';
29 printf("%c %c\n", prev, ut->ut_pid % 256);
Denis Vlasenko9a7d38f2007-05-31 22:42:12 +000030 if (ENABLE_FEATURE_CLEAN_UP)
31 endutent();
Denis Vlasenkoc2905632006-09-23 16:01:09 +000032 return 0;
33 }
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000034 }
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000035
Denis Vlasenkoc2905632006-09-23 16:01:09 +000036 puts("unknown");
Denis Vlasenko2f6ae432007-07-19 22:50:47 +000037
Denis Vlasenko9a7d38f2007-05-31 22:42:12 +000038 if (ENABLE_FEATURE_CLEAN_UP)
39 endutent();
Denis Vlasenkoc2905632006-09-23 16:01:09 +000040 return 1;
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000041}