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 | */ |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 14 | |
| 15 | //usage:#define runlevel_trivial_usage |
| 16 | //usage: "[FILE]" |
| 17 | //usage:#define runlevel_full_usage "\n\n" |
| 18 | //usage: "Find the current and previous system runlevel\n" |
| 19 | //usage: "\n" |
| 20 | //usage: "If no utmp FILE exists or if no runlevel record can be found,\n" |
| 21 | //usage: "print \"unknown\"" |
| 22 | //usage: |
| 23 | //usage:#define runlevel_example_usage |
| 24 | //usage: "$ runlevel /var/run/utmp\n" |
| 25 | //usage: "N 2" |
| 26 | |
Denis Vlasenko | 9a7d38f | 2007-05-31 22:42:12 +0000 | [diff] [blame] | 27 | #include "libbb.h" |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 28 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 29 | int runlevel_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denys Vlasenko | 1e11360 | 2009-11-26 15:26:14 +0100 | [diff] [blame] | 30 | int runlevel_main(int argc UNUSED_PARAM, char **argv) |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 31 | { |
Denis Vlasenko | c290563 | 2006-09-23 16:01:09 +0000 | [diff] [blame] | 32 | struct utmp *ut; |
| 33 | char prev; |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 34 | |
Denys Vlasenko | 1e11360 | 2009-11-26 15:26:14 +0100 | [diff] [blame] | 35 | if (argv[1]) utmpname(argv[1]); |
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 | setutent(); |
| 38 | while ((ut = getutent()) != NULL) { |
| 39 | if (ut->ut_type == RUN_LVL) { |
| 40 | prev = ut->ut_pid / 256; |
| 41 | if (prev == 0) prev = 'N'; |
| 42 | printf("%c %c\n", prev, ut->ut_pid % 256); |
Denis Vlasenko | 9a7d38f | 2007-05-31 22:42:12 +0000 | [diff] [blame] | 43 | if (ENABLE_FEATURE_CLEAN_UP) |
| 44 | endutent(); |
Denis Vlasenko | c290563 | 2006-09-23 16:01:09 +0000 | [diff] [blame] | 45 | return 0; |
| 46 | } |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 47 | } |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 48 | |
Denis Vlasenko | c290563 | 2006-09-23 16:01:09 +0000 | [diff] [blame] | 49 | puts("unknown"); |
Denis Vlasenko | 2f6ae43 | 2007-07-19 22:50:47 +0000 | [diff] [blame] | 50 | |
Denis Vlasenko | 9a7d38f | 2007-05-31 22:42:12 +0000 | [diff] [blame] | 51 | if (ENABLE_FEATURE_CLEAN_UP) |
| 52 | endutent(); |
Denis Vlasenko | c290563 | 2006-09-23 16:01:09 +0000 | [diff] [blame] | 53 | return 1; |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 54 | } |