blob: 684ab781b179ec73e783e2af6c5f580d7b6f94f0 [file] [log] [blame]
Erik Andersencbb0a4b2000-04-04 18:52:02 +00001/* vi: set sw=4 ts=4: */
2/*
Manuel Novoa III cad53642003-03-19 09:13:01 +00003 * usleep implementation for busybox
Erik Andersencbb0a4b2000-04-04 18:52:02 +00004 *
Manuel Novoa III cad53642003-03-19 09:13:01 +00005 * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org>
Erik Andersencbb0a4b2000-04-04 18:52:02 +00006 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02007 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Erik Andersencbb0a4b2000-04-04 18:52:02 +00008 */
Denys Vlasenkoaf3f4202016-11-23 14:46:56 +01009//config:config USLEEP
Denys Vlasenko4eed2c62017-07-18 22:01:24 +020010//config: bool "usleep (1.1 kb)"
Denys Vlasenkoaf3f4202016-11-23 14:46:56 +010011//config: default y
12//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020013//config: usleep is used to pause for a specified number of microseconds.
Denys Vlasenkoaf3f4202016-11-23 14:46:56 +010014
15//applet:IF_USLEEP(APPLET_NOFORK(usleep, usleep, BB_DIR_BIN, BB_SUID_DROP, usleep))
16
17//kbuild:lib-$(CONFIG_USLEEP) += usleep.o
Erik Andersencbb0a4b2000-04-04 18:52:02 +000018
Manuel Novoa III cad53642003-03-19 09:13:01 +000019/* BB_AUDIT SUSv3 N/A -- Apparently a busybox extension. */
Eric Andersen92d23242001-03-19 23:49:41 +000020
Pere Orga34425382011-03-31 14:43:25 +020021//usage:#define usleep_trivial_usage
22//usage: "N"
23//usage:#define usleep_full_usage "\n\n"
24//usage: "Pause for N microseconds"
25//usage:
26//usage:#define usleep_example_usage
27//usage: "$ usleep 1000000\n"
28//usage: "[pauses for 1 second]\n"
29
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000030#include "libbb.h"
Erik Andersencbb0a4b2000-04-04 18:52:02 +000031
Denis Vlasenko99912ca2007-04-10 15:43:37 +000032/* This is a NOFORK applet. Be very careful! */
33
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000034int usleep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000035int usleep_main(int argc UNUSED_PARAM, char **argv)
Erik Andersencbb0a4b2000-04-04 18:52:02 +000036{
Denis Vlasenko1d426652008-03-17 09:09:09 +000037 if (!argv[1]) {
Manuel Novoa III cad53642003-03-19 09:13:01 +000038 bb_show_usage();
Erik Andersencbb0a4b2000-04-04 18:52:02 +000039 }
40
Denys Vlasenko7c40ddd2017-08-02 16:37:39 +020041 /* Safe wrt NOFORK? (noforks are not allowed to run for
42 * a long time). Try "usleep 99999999" + ^C + "echo $?"
43 * in hush with FEATURE_SH_NOFORK=y.
44 * At least on uclibc, usleep() thanslates to nanosleep()
45 * which returns early on any signal (even caught one),
46 * and uclibc does not loop back on EINTR.
47 */
Denys Vlasenkoacff3732011-07-08 08:37:57 +020048 usleep(xatou(argv[1]));
Manuel Novoa III cad53642003-03-19 09:13:01 +000049
Matt Kraai3e856ce2000-12-01 02:55:13 +000050 return EXIT_SUCCESS;
Erik Andersencbb0a4b2000-04-04 18:52:02 +000051}