blob: 91d49fa5504e1111666602a32fe677a60fdab092 [file] [log] [blame]
Bernhard Reutner-Fischerc89982d2006-06-03 19:49:21 +00001/* vi: set sw=4 ts=4: */
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +00002/*
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-Fischerc89982d2006-06-03 19:49:21 +000015#include "busybox.h"
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000016#include <stdio.h>
17#include <utmp.h>
18#include <time.h>
19#include <stdlib.h>
20
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000021int runlevel_main(int argc, char *argv[])
22{
Denis Vlasenkoc2905632006-09-23 16:01:09 +000023 struct utmp *ut;
24 char prev;
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000025
Denis Vlasenkoc2905632006-09-23 16:01:09 +000026 if (argc > 1) utmpname(argv[1]);
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000027
Denis Vlasenkoc2905632006-09-23 16:01:09 +000028 setutent();
29 while ((ut = getutent()) != NULL) {
30 if (ut->ut_type == RUN_LVL) {
31 prev = ut->ut_pid / 256;
32 if (prev == 0) prev = 'N';
33 printf("%c %c\n", prev, ut->ut_pid % 256);
34 endutent();
35 return 0;
36 }
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000037 }
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000038
Denis Vlasenkoc2905632006-09-23 16:01:09 +000039 puts("unknown");
40 endutent();
41 return 1;
Bernhard Reutner-Fischer62d7acc2005-10-28 20:37:03 +000042}