diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2015-08-30 05:45:44 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2015-08-30 05:45:44 +0000 |
commit | d368b2e8b6245ab51887cbc0619eb5612abe6464 (patch) | |
tree | 17b65b06c9d73f8a4063571cd8ef895a022dad5d | |
parent | 62f76469832b2528f5c5f87be2dd4397dae114ef (diff) |
Use nanosleep instead of sleep to avoid the extra layer and simplify later
symbol hiding
ok w/tweak deraadt@
-rw-r--r-- | lib/libc/net/rcmd.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/libc/net/rcmd.c b/lib/libc/net/rcmd.c index 5ef44040019..600565a2359 100644 --- a/lib/libc/net/rcmd.c +++ b/lib/libc/net/rcmd.c @@ -45,6 +45,7 @@ #include <ctype.h> #include <string.h> #include <syslog.h> +#include <time.h> #include <stdlib.h> #include <poll.h> @@ -66,7 +67,8 @@ rcmd_af(char **ahost, int porta, const char *locuser, const char *remuser, struct sockaddr_storage from; sigset_t oldmask, mask; pid_t pid; - int s, lport, timo; + int s, lport; + struct timespec timo; char c, *p; int refused; in_port_t rport = porta; @@ -110,10 +112,11 @@ rcmd_af(char **ahost, int porta, const char *locuser, const char *remuser, r = res; refused = 0; + timespecclear(&timo); sigemptyset(&mask); sigaddset(&mask, SIGURG); sigprocmask(SIG_BLOCK, &mask, &oldmask); - for (timo = 1, lport = IPPORT_RESERVED - 1;;) { + for (timo.tv_sec = 1, lport = IPPORT_RESERVED - 1;;) { s = rresvport_af(&lport, r->ai_family); if (s < 0) { if (errno == EAGAIN) @@ -161,9 +164,9 @@ rcmd_af(char **ahost, int porta, const char *locuser, const char *remuser, (void)fprintf(stderr, "Trying %s...\n", hbuf); continue; } - if (refused && timo <= 16) { - (void)sleep(timo); - timo *= 2; + if (refused && timo.tv_sec <= 16) { + (void)nanosleep(&timo, NULL); + timo.tv_sec *= 2; r = res; refused = 0; continue; |