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" |
Denys Vlasenko | 1e11360 | 2009-11-26 15:26:14 +0100 | [diff] [blame] | 15 | #include <utmp.h> |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 16 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 17 | int runlevel_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denys Vlasenko | 1e11360 | 2009-11-26 15:26:14 +0100 | [diff] [blame] | 18 | int runlevel_main(int argc UNUSED_PARAM, char **argv) |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 19 | { |
Denis Vlasenko | c290563 | 2006-09-23 16:01:09 +0000 | [diff] [blame] | 20 | struct utmp *ut; |
| 21 | char prev; |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 22 | |
Denys Vlasenko | 1e11360 | 2009-11-26 15:26:14 +0100 | [diff] [blame] | 23 | if (argv[1]) utmpname(argv[1]); |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 24 | |
Denis Vlasenko | c290563 | 2006-09-23 16:01:09 +0000 | [diff] [blame] | 25 | 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 Vlasenko | 9a7d38f | 2007-05-31 22:42:12 +0000 | [diff] [blame] | 31 | if (ENABLE_FEATURE_CLEAN_UP) |
| 32 | endutent(); |
Denis Vlasenko | c290563 | 2006-09-23 16:01:09 +0000 | [diff] [blame] | 33 | return 0; |
| 34 | } |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 35 | } |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 36 | |
Denis Vlasenko | c290563 | 2006-09-23 16:01:09 +0000 | [diff] [blame] | 37 | puts("unknown"); |
Denis Vlasenko | 2f6ae43 | 2007-07-19 22:50:47 +0000 | [diff] [blame] | 38 | |
Denis Vlasenko | 9a7d38f | 2007-05-31 22:42:12 +0000 | [diff] [blame] | 39 | if (ENABLE_FEATURE_CLEAN_UP) |
| 40 | endutent(); |
Denis Vlasenko | c290563 | 2006-09-23 16:01:09 +0000 | [diff] [blame] | 41 | return 1; |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 42 | } |