rpcd: Switch to nanosleep
authorRosen Penev <rosenp@gmail.com>
Thu, 18 Jul 2019 17:54:44 +0000 (10:54 -0700)
committerJo-Philipp Wich <jo@mein.io>
Tue, 3 Sep 2019 09:26:51 +0000 (11:26 +0200)
usleep has been deprecated by POSIX.1-2001 and removed in POSIX.1-2008.
Fixes compilation when libc does not include usleep (optional with
uClibc-ng).

nanosleep also has the advantage of being more accurate.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
[move timespec definition to the top of the function]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
sys.c

diff --git a/sys.c b/sys.c
index 43eadc411402d2628fedea44fa59651e82ce688d..2d835229fe85c1e898dcbc3b6f26638643462faf 100644 (file)
--- a/sys.c
+++ b/sys.c
@@ -145,7 +145,8 @@ rpc_cgi_password_set(struct ubus_context *ctx, struct ubus_object *obj,
                if (n < 0)
                        return rpc_errno_status();
 
-               usleep(100 * 1000);
+               const struct timespec req = {0, 100 * 1000 * 1000};
+               nanosleep(&req, NULL);
 
                n = write(fds[1], blobmsg_data(tb[RPC_P_PASSWORD]),
                              blobmsg_data_len(tb[RPC_P_PASSWORD]) - 1);