runlevel.c 919 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * 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 GPLv2 or later, see file LICENSE in this source tree.
  11. *
  12. * initially busyboxified by Bernhard Reutner-Fischer
  13. */
  14. #include "libbb.h"
  15. #include <utmp.h>
  16. int runlevel_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  17. int runlevel_main(int argc UNUSED_PARAM, char **argv)
  18. {
  19. struct utmp *ut;
  20. char prev;
  21. if (argv[1]) utmpname(argv[1]);
  22. setutent();
  23. while ((ut = getutent()) != NULL) {
  24. if (ut->ut_type == RUN_LVL) {
  25. prev = ut->ut_pid / 256;
  26. if (prev == 0) prev = 'N';
  27. printf("%c %c\n", prev, ut->ut_pid % 256);
  28. if (ENABLE_FEATURE_CLEAN_UP)
  29. endutent();
  30. return 0;
  31. }
  32. }
  33. puts("unknown");
  34. if (ENABLE_FEATURE_CLEAN_UP)
  35. endutent();
  36. return 1;
  37. }