3
0

runlevel.c 845 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* vi: set sw=4 ts=4: */
  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. #include "busybox.h"
  15. #include <stdio.h>
  16. #include <utmp.h>
  17. #include <time.h>
  18. #include <stdlib.h>
  19. int runlevel_main(int argc, char *argv[])
  20. {
  21. struct utmp *ut;
  22. char prev;
  23. if (argc > 1) utmpname(argv[1]);
  24. setutent();
  25. while ((ut = getutent()) != NULL) {
  26. if (ut->ut_type == RUN_LVL) {
  27. prev = ut->ut_pid / 256;
  28. if (prev == 0) prev = 'N';
  29. printf("%c %c\n", prev, ut->ut_pid % 256);
  30. endutent();
  31. return 0;
  32. }
  33. }
  34. puts("unknown");
  35. endutent();
  36. return 1;
  37. }