summaryrefslogtreecommitdiffstats
path: root/lib/libc/net/rcmd.c
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2015-08-30 05:45:43 +0000
committerguenther <guenther@openbsd.org>2015-08-30 05:45:43 +0000
commit83dc3a585ecdcc1b950da954f31dc650254de40f (patch)
tree6519f2e565c8342a3742900ecf3955ca90232247 /lib/libc/net/rcmd.c
parentFor *chmod, allow S_ISTXT in tame mode. I am evaluating what to (diff)
downloadwireguard-openbsd-83dc3a585ecdcc1b950da954f31dc650254de40f.tar.xz
wireguard-openbsd-83dc3a585ecdcc1b950da954f31dc650254de40f.zip
Use nanosleep instead of sleep to avoid the extra layer and simplify later
symbol hiding ok w/tweak deraadt@
Diffstat (limited to 'lib/libc/net/rcmd.c')
-rw-r--r--lib/libc/net/rcmd.c13
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;