runlevel.c 832 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 1991-1997 Miquel van Smoorenburg.
  8. *
  9. * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
  10. *
  11. * initially busyboxified by Bernhard Fischer
  12. */
  13. #include <stdio.h>
  14. #include <utmp.h>
  15. #include <time.h>
  16. #include <stdlib.h>
  17. #include "busybox.h"
  18. int runlevel_main(int argc, char *argv[])
  19. {
  20. struct utmp *ut;
  21. char prev;
  22. if (argc > 1) utmpname(argv[1]);
  23. setutent();
  24. while ((ut = getutent()) != NULL) {
  25. if (ut->ut_type == RUN_LVL) {
  26. prev = ut->ut_pid / 256;
  27. if (prev == 0) prev = 'N';
  28. printf("%c %c\n", prev, ut->ut_pid % 256);
  29. endutent();
  30. return (0);
  31. }
  32. }
  33. printf("unknown\n");
  34. endutent();
  35. return (1);
  36. }