diff options
author | Colin Watson <cjwatson@debian.org> | 2020-02-21 11:57:14 +0000 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2020-02-21 11:57:14 +0000 |
commit | f0de78bd4f29fa688c5df116f3f9cd43543a76d0 (patch) | |
tree | 856b0dee3f2764c13a32dad5ffe2424fab7fef41 /misc.c | |
parent | 4213eec74e74de6310c27a40c3e9759a08a73996 (diff) | |
parent | 8aa3455b16fddea4c0144a7c4a1edb10ec67dcc8 (diff) |
Import openssh_8.2p1.orig.tar.gz
Diffstat (limited to 'misc.c')
-rw-r--r-- | misc.c | 69 |
1 files changed, 63 insertions, 6 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: misc.c,v 1.142 2019/09/03 08:32:11 djm Exp $ */ | 1 | /* $OpenBSD: misc.c,v 1.146 2020/01/28 01:49:36 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. |
4 | * Copyright (c) 2005,2006 Damien Miller. All rights reserved. | 4 | * Copyright (c) 2005,2006 Damien Miller. All rights reserved. |
@@ -38,7 +38,9 @@ | |||
38 | #ifdef HAVE_LIBGEN_H | 38 | #ifdef HAVE_LIBGEN_H |
39 | # include <libgen.h> | 39 | # include <libgen.h> |
40 | #endif | 40 | #endif |
41 | #ifdef HAVE_POLL_H | ||
41 | #include <poll.h> | 42 | #include <poll.h> |
43 | #endif | ||
42 | #include <signal.h> | 44 | #include <signal.h> |
43 | #include <stdarg.h> | 45 | #include <stdarg.h> |
44 | #include <stdio.h> | 46 | #include <stdio.h> |
@@ -236,12 +238,12 @@ set_rdomain(int fd, const char *name) | |||
236 | } | 238 | } |
237 | 239 | ||
238 | /* | 240 | /* |
239 | * Wait up to *timeoutp milliseconds for fd to be readable. Updates | 241 | * Wait up to *timeoutp milliseconds for events on fd. Updates |
240 | * *timeoutp with time remaining. | 242 | * *timeoutp with time remaining. |
241 | * Returns 0 if fd ready or -1 on timeout or error (see errno). | 243 | * Returns 0 if fd ready or -1 on timeout or error (see errno). |
242 | */ | 244 | */ |
243 | int | 245 | static int |
244 | waitrfd(int fd, int *timeoutp) | 246 | waitfd(int fd, int *timeoutp, short events) |
245 | { | 247 | { |
246 | struct pollfd pfd; | 248 | struct pollfd pfd; |
247 | struct timeval t_start; | 249 | struct timeval t_start; |
@@ -249,7 +251,7 @@ waitrfd(int fd, int *timeoutp) | |||
249 | 251 | ||
250 | monotime_tv(&t_start); | 252 | monotime_tv(&t_start); |
251 | pfd.fd = fd; | 253 | pfd.fd = fd; |
252 | pfd.events = POLLIN; | 254 | pfd.events = events; |
253 | for (; *timeoutp >= 0;) { | 255 | for (; *timeoutp >= 0;) { |
254 | r = poll(&pfd, 1, *timeoutp); | 256 | r = poll(&pfd, 1, *timeoutp); |
255 | oerrno = errno; | 257 | oerrno = errno; |
@@ -268,6 +270,16 @@ waitrfd(int fd, int *timeoutp) | |||
268 | } | 270 | } |
269 | 271 | ||
270 | /* | 272 | /* |
273 | * Wait up to *timeoutp milliseconds for fd to be readable. Updates | ||
274 | * *timeoutp with time remaining. | ||
275 | * Returns 0 if fd ready or -1 on timeout or error (see errno). | ||
276 | */ | ||
277 | int | ||
278 | waitrfd(int fd, int *timeoutp) { | ||
279 | return waitfd(fd, timeoutp, POLLIN); | ||
280 | } | ||
281 | |||
282 | /* | ||
271 | * Attempt a non-blocking connect(2) to the specified address, waiting up to | 283 | * Attempt a non-blocking connect(2) to the specified address, waiting up to |
272 | * *timeoutp milliseconds for the connection to complete. If the timeout is | 284 | * *timeoutp milliseconds for the connection to complete. If the timeout is |
273 | * <=0, then wait indefinitely. | 285 | * <=0, then wait indefinitely. |
@@ -293,7 +305,7 @@ timeout_connect(int sockfd, const struct sockaddr *serv_addr, | |||
293 | } else if (errno != EINPROGRESS) | 305 | } else if (errno != EINPROGRESS) |
294 | return -1; | 306 | return -1; |
295 | 307 | ||
296 | if (waitrfd(sockfd, timeoutp) == -1) | 308 | if (waitfd(sockfd, timeoutp, POLLIN | POLLOUT) == -1) |
297 | return -1; | 309 | return -1; |
298 | 310 | ||
299 | /* Completed or failed */ | 311 | /* Completed or failed */ |
@@ -1232,6 +1244,33 @@ tohex(const void *vp, size_t l) | |||
1232 | return (r); | 1244 | return (r); |
1233 | } | 1245 | } |
1234 | 1246 | ||
1247 | /* | ||
1248 | * Extend string *sp by the specified format. If *sp is not NULL (or empty), | ||
1249 | * then the separator 'sep' will be prepended before the formatted arguments. | ||
1250 | * Extended strings are heap allocated. | ||
1251 | */ | ||
1252 | void | ||
1253 | xextendf(char **sp, const char *sep, const char *fmt, ...) | ||
1254 | { | ||
1255 | va_list ap; | ||
1256 | char *tmp1, *tmp2; | ||
1257 | |||
1258 | va_start(ap, fmt); | ||
1259 | xvasprintf(&tmp1, fmt, ap); | ||
1260 | va_end(ap); | ||
1261 | |||
1262 | if (*sp == NULL || **sp == '\0') { | ||
1263 | free(*sp); | ||
1264 | *sp = tmp1; | ||
1265 | return; | ||
1266 | } | ||
1267 | xasprintf(&tmp2, "%s%s%s", *sp, sep == NULL ? "" : sep, tmp1); | ||
1268 | free(tmp1); | ||
1269 | free(*sp); | ||
1270 | *sp = tmp2; | ||
1271 | } | ||
1272 | |||
1273 | |||
1235 | u_int64_t | 1274 | u_int64_t |
1236 | get_u64(const void *vp) | 1275 | get_u64(const void *vp) |
1237 | { | 1276 | { |
@@ -1520,6 +1559,7 @@ static const struct { | |||
1520 | { "cs6", IPTOS_DSCP_CS6 }, | 1559 | { "cs6", IPTOS_DSCP_CS6 }, |
1521 | { "cs7", IPTOS_DSCP_CS7 }, | 1560 | { "cs7", IPTOS_DSCP_CS7 }, |
1522 | { "ef", IPTOS_DSCP_EF }, | 1561 | { "ef", IPTOS_DSCP_EF }, |
1562 | { "le", IPTOS_DSCP_LE }, | ||
1523 | { "lowdelay", IPTOS_LOWDELAY }, | 1563 | { "lowdelay", IPTOS_LOWDELAY }, |
1524 | { "throughput", IPTOS_THROUGHPUT }, | 1564 | { "throughput", IPTOS_THROUGHPUT }, |
1525 | { "reliability", IPTOS_RELIABILITY }, | 1565 | { "reliability", IPTOS_RELIABILITY }, |
@@ -2209,3 +2249,20 @@ opt_match(const char **opts, const char *term) | |||
2209 | return 0; | 2249 | return 0; |
2210 | } | 2250 | } |
2211 | 2251 | ||
2252 | sshsig_t | ||
2253 | ssh_signal(int signum, sshsig_t handler) | ||
2254 | { | ||
2255 | struct sigaction sa, osa; | ||
2256 | |||
2257 | /* mask all other signals while in handler */ | ||
2258 | bzero(&sa, sizeof(sa)); | ||
2259 | sa.sa_handler = handler; | ||
2260 | sigfillset(&sa.sa_mask); | ||
2261 | if (signum != SIGALRM) | ||
2262 | sa.sa_flags = SA_RESTART; | ||
2263 | if (sigaction(signum, &sa, &osa) == -1) { | ||
2264 | debug3("sigaction(%s): %s", strsignal(signum), strerror(errno)); | ||
2265 | return SIG_ERR; | ||
2266 | } | ||
2267 | return osa.sa_handler; | ||
2268 | } | ||