Include -Wunreachable-code when building.
[sysvinit.git] / src / runlevel.c
CommitLineData
a74aeac6
PR
1/*
2 * runlevel Prints out the previous and the current runlevel.
3 *
4 * Version: @(#)runlevel 1.20 16-Apr-1997 MvS
5 *
6 * This file is part of the sysvinit suite,
7 * Copyright (C) 1991-1997 Miquel van Smoorenburg.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include <stdio.h>
25#include <utmp.h>
26#include <time.h>
27#include <stdlib.h>
28
29int main(argc, argv)
30int argc;
31char **argv;
32{
33 struct utmp *ut;
34 char prev;
35
36 if (argc > 1) utmpname(argv[1]);
37
38 setutent();
39 while ((ut = getutent()) != NULL) {
40 if (ut->ut_type == RUN_LVL) {
41 prev = ut->ut_pid / 256;
42 if (prev == 0) prev = 'N';
43 printf("%c %c\n", prev, ut->ut_pid % 256);
44 endutent();
45 exit(0);
46 }
47 }
48
49 printf("unknown\n");
50 endutent();
51 return(1);
52}
53