Bernhard Reutner-Fischer | c89982d | 2006-06-03 19:49:21 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 2 | /* |
Denys Vlasenko | e4dcba1 | 2010-10-28 18:57:19 +0200 | [diff] [blame] | 3 | * Prints out the previous and the current runlevel. |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 4 | * |
Denys Vlasenko | e4dcba1 | 2010-10-28 18:57:19 +0200 | [diff] [blame] | 5 | * Version: @(#)runlevel 1.20 16-Apr-1997 MvS |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 6 | * |
Denys Vlasenko | e4dcba1 | 2010-10-28 18:57:19 +0200 | [diff] [blame] | 7 | * This file is part of the sysvinit suite, |
| 8 | * Copyright 1991-1997 Miquel van Smoorenburg. |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 9 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 10 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 11 | * |
Bernhard Reutner-Fischer | 6c4dade | 2008-09-25 12:13:34 +0000 | [diff] [blame] | 12 | * initially busyboxified by Bernhard Reutner-Fischer |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 13 | */ |
Denis Vlasenko | 9a7d38f | 2007-05-31 22:42:12 +0000 | [diff] [blame] | 14 | #include "libbb.h" |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 15 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 16 | int runlevel_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denys Vlasenko | 1e11360 | 2009-11-26 15:26:14 +0100 | [diff] [blame] | 17 | int runlevel_main(int argc UNUSED_PARAM, char **argv) |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 18 | { |
Denis Vlasenko | c290563 | 2006-09-23 16:01:09 +0000 | [diff] [blame] | 19 | struct utmp *ut; |
| 20 | char prev; |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 21 | |
Denys Vlasenko | 1e11360 | 2009-11-26 15:26:14 +0100 | [diff] [blame] | 22 | if (argv[1]) utmpname(argv[1]); |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 23 | |
Denis Vlasenko | c290563 | 2006-09-23 16:01:09 +0000 | [diff] [blame] | 24 | 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 Vlasenko | 9a7d38f | 2007-05-31 22:42:12 +0000 | [diff] [blame] | 30 | if (ENABLE_FEATURE_CLEAN_UP) |
| 31 | endutent(); |
Denis Vlasenko | c290563 | 2006-09-23 16:01:09 +0000 | [diff] [blame] | 32 | return 0; |
| 33 | } |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 34 | } |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 35 | |
Denis Vlasenko | c290563 | 2006-09-23 16:01:09 +0000 | [diff] [blame] | 36 | puts("unknown"); |
Denis Vlasenko | 2f6ae43 | 2007-07-19 22:50:47 +0000 | [diff] [blame] | 37 | |
Denis Vlasenko | 9a7d38f | 2007-05-31 22:42:12 +0000 | [diff] [blame] | 38 | if (ENABLE_FEATURE_CLEAN_UP) |
| 39 | endutent(); |
Denis Vlasenko | c290563 | 2006-09-23 16:01:09 +0000 | [diff] [blame] | 40 | return 1; |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 41 | } |