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