usleep.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * usleep implementation for busybox
  4. *
  5. * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org>
  6. *
  7. * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  8. */
  9. //config:config USLEEP
  10. //config: bool "usleep (1.3 kb)"
  11. //config: default y
  12. //config: help
  13. //config: usleep is used to pause for a specified number of microseconds.
  14. //applet:IF_USLEEP(APPLET_NOFORK(usleep, usleep, BB_DIR_BIN, BB_SUID_DROP, usleep))
  15. //kbuild:lib-$(CONFIG_USLEEP) += usleep.o
  16. /* BB_AUDIT SUSv3 N/A -- Apparently a busybox extension. */
  17. //usage:#define usleep_trivial_usage
  18. //usage: "N"
  19. //usage:#define usleep_full_usage "\n\n"
  20. //usage: "Pause for N microseconds"
  21. //usage:
  22. //usage:#define usleep_example_usage
  23. //usage: "$ usleep 1000000\n"
  24. //usage: "[pauses for 1 second]\n"
  25. #include "libbb.h"
  26. /* This is a NOFORK applet. Be very careful! */
  27. int usleep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  28. int usleep_main(int argc UNUSED_PARAM, char **argv)
  29. {
  30. if (!argv[1]) {
  31. bb_show_usage();
  32. }
  33. /* Safe wrt NOFORK? (noforks are not allowed to run for
  34. * a long time). Try "usleep 99999999" + ^C + "echo $?"
  35. * in hush with FEATURE_SH_NOFORK=y.
  36. * At least on uclibc, usleep() thanslates to nanosleep()
  37. * which returns early on any signal (even caught one),
  38. * and uclibc does not loop back on EINTR.
  39. */
  40. usleep(xatou(argv[1]));
  41. return EXIT_SUCCESS;
  42. }