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 | c89982d | 2006-06-03 19:49:21 +0000 | [diff] [blame] | 15 | #include "busybox.h" |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 16 | #include <stdio.h> |
| 17 | #include <utmp.h> |
| 18 | #include <time.h> |
| 19 | #include <stdlib.h> |
| 20 | |
Denis Vlasenko | 06af216 | 2007-02-03 17:28:39 +0000 | [diff] [blame^] | 21 | int runlevel_main(int argc, char *argv[]); |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 22 | int runlevel_main(int argc, char *argv[]) |
| 23 | { |
Denis Vlasenko | c290563 | 2006-09-23 16:01:09 +0000 | [diff] [blame] | 24 | struct utmp *ut; |
| 25 | char prev; |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 26 | |
Denis Vlasenko | c290563 | 2006-09-23 16:01:09 +0000 | [diff] [blame] | 27 | if (argc > 1) utmpname(argv[1]); |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 28 | |
Denis Vlasenko | c290563 | 2006-09-23 16:01:09 +0000 | [diff] [blame] | 29 | setutent(); |
| 30 | while ((ut = getutent()) != NULL) { |
| 31 | if (ut->ut_type == RUN_LVL) { |
| 32 | prev = ut->ut_pid / 256; |
| 33 | if (prev == 0) prev = 'N'; |
| 34 | printf("%c %c\n", prev, ut->ut_pid % 256); |
| 35 | endutent(); |
| 36 | return 0; |
| 37 | } |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 38 | } |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 39 | |
Denis Vlasenko | c290563 | 2006-09-23 16:01:09 +0000 | [diff] [blame] | 40 | puts("unknown"); |
| 41 | endutent(); |
| 42 | return 1; |
Bernhard Reutner-Fischer | 62d7acc | 2005-10-28 20:37:03 +0000 | [diff] [blame] | 43 | } |