Lines Matching +full:timeout +full:- +full:lp +full:- +full:ms
4 * Copyright (c) 2005-2020 Damien Miller. All rights reserved.
104 for (i--; i > 0; i--) { in rtrim()
110 /* set/unset filedescriptor to non-blocking */
117 if (val == -1) { in set_nonblock()
119 return (-1); in set_nonblock()
127 if (fcntl(fd, F_SETFL, val) == -1) { in set_nonblock()
130 return (-1); in set_nonblock()
141 if (val == -1) { in unset_nonblock()
143 return (-1); in unset_nonblock()
151 if (fcntl(fd, F_SETFL, val) == -1) { in unset_nonblock()
154 return (-1); in unset_nonblock()
175 if (getsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &opt, &optlen) == -1) { in set_nodelay()
185 if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof opt) == -1) in set_nodelay()
195 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1) { in set_reuseaddr()
197 return -1; in set_reuseaddr()
213 if (getsockopt(fd, SOL_SOCKET, SO_RTABLE, &rtable, &len) == -1) { in get_rdomain()
241 return -1; in set_rdomain()
244 &rtable, sizeof(rtable)) == -1) { in set_rdomain()
247 return -1; in set_rdomain()
252 return -1; in set_rdomain()
263 if (getsockname(fd, (struct sockaddr *)&to, &tolen) == -1) in get_sock_af()
264 return -1; in get_sock_af()
267 IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)&to)->sin6_addr)) in get_sock_af()
280 case -1: in set_sock_tos()
287 &tos, sizeof(tos)) == -1) { in set_sock_tos()
297 &tos, sizeof(tos)) == -1) { in set_sock_tos()
313 * Returns 0 if fd ready or -1 on timeout or error (see errno).
319 struct timespec timeout; in waitfd() local
323 if (timeoutp && *timeoutp == -1) in waitfd()
327 ptimeout_init(&timeout); in waitfd()
329 ptimeout_deadline_ms(&timeout, *timeoutp); in waitfd()
338 return -1; in waitfd()
341 r = ppoll(&pfd, 1, ptimeout_get_tsp(&timeout), in waitfd()
347 *timeoutp = ptimeout_get_ms(&timeout); in waitfd()
351 else if (r == -1 && errno != EAGAIN && errno != EINTR) in waitfd()
352 return -1; in waitfd()
356 /* timeout */ in waitfd()
358 return -1; in waitfd()
364 * Returns 0 if fd ready or -1 on timeout or error (see errno).
372 * Attempt a non-blocking connect(2) to the specified address, waiting up to
373 * *timeoutp milliseconds for the connection to complete. If the timeout is
376 * Returns 0 on success or -1 on failure.
385 /* No timeout: just do a blocking connect() */ in timeout_connect()
398 return -1; in timeout_connect()
402 if (waitfd(sockfd, timeoutp, POLLIN | POLLOUT, NULL) == -1) in timeout_connect()
403 return -1; in timeout_connect()
406 if (getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &optval, &optlen) == -1) { in timeout_connect()
408 return -1; in timeout_connect()
412 return -1; in timeout_connect()
488 copy->pw_name = xstrdup(pw->pw_name); in pwcopy()
489 copy->pw_passwd = xstrdup(pw->pw_passwd == NULL ? "*" : pw->pw_passwd); in pwcopy()
491 copy->pw_gecos = xstrdup(pw->pw_gecos); in pwcopy()
493 copy->pw_uid = pw->pw_uid; in pwcopy()
494 copy->pw_gid = pw->pw_gid; in pwcopy()
496 copy->pw_expire = pw->pw_expire; in pwcopy()
499 copy->pw_change = pw->pw_change; in pwcopy()
502 copy->pw_class = xstrdup(pw->pw_class); in pwcopy()
504 copy->pw_dir = xstrdup(pw->pw_dir); in pwcopy()
505 copy->pw_shell = xstrdup(pw->pw_shell); in pwcopy()
512 * Return -1 if invalid.
525 return ntohs(se->s_port); in a2port()
526 return -1; in a2port()
585 * Return -1 if time string is invalid.
599 return -1; in convtime()
606 return -1; in convtime()
611 endp--; in convtime()
633 return -1; in convtime()
636 return -1; in convtime()
638 if (total > INT_MAX - secs) in convtime()
639 return -1; in convtime()
642 return -1; in convtime()
697 if (asprintf(&hoststr, "[%s]:%d", host, (int)port) == -1) in put_host_port()
763 if (*host == '[' && host[strlen(host) - 1] == ']') { in cleanhostname()
764 host[strlen(host) - 1] = '\0'; in cleanhostname()
800 * Returns 0 on success, -1 on failure.
807 int ret = -1; in parse_user_host_path()
867 * If port was not specified then *portp will be -1.
868 * Returns 0 on success, -1 on failure.
875 int port = -1, ret = -1; in parse_user_host_port()
882 *portp = -1; in parse_user_host_port()
885 return -1; in parse_user_host_port()
924 * Converts a two-byte hex string to decimal.
925 * Returns the decimal value or -1 for invalid input.
935 result[i] = (unsigned char)(s[i] - '0'); in hexchar()
937 result[i] = (unsigned char)(s[i] - 'a') + 10; in hexchar()
939 result[i] = (unsigned char)(s[i] - 'A') + 10; in hexchar()
941 return -1; in hexchar()
947 * Decode an url-encoded string.
968 (ch = hexchar(src + 1)) == -1) { in urldecode()
987 * See https://tools.ietf.org/html/draft-ietf-secsh-scp-sftp-ssh-uri-04
988 * Either user or path may be url-encoded (but not host or port).
993 * If port was not specified then *portp will be -1.
995 * Returns 0 on success, 1 if non-uri/wrong scheme, -1 on error/invalid uri.
1003 int port = -1, ret = -1; in parse_uri()
1016 *portp = -1; in parse_uri()
1022 /* Extract optional ssh-info (username + connection params) */ in parse_uri()
1100 if (r == -1) in addargs()
1103 nalloc = args->nalloc; in addargs()
1104 if (args->list == NULL) { in addargs()
1106 args->num = 0; in addargs()
1107 } else if (args->num > (256 * 1024)) in addargs()
1109 else if (args->num >= args->nalloc) in addargs()
1111 else if (args->num+2 >= nalloc) in addargs()
1114 args->list = xrecallocarray(args->list, args->nalloc, in addargs()
1116 args->nalloc = nalloc; in addargs()
1117 args->list[args->num++] = cp; in addargs()
1118 args->list[args->num] = NULL; in addargs()
1131 if (r == -1) in replacearg()
1133 if (args->list == NULL || args->num >= args->nalloc) in replacearg()
1136 if (which >= args->num) in replacearg()
1138 which, args->num); in replacearg()
1139 free(args->list[which]); in replacearg()
1140 args->list[which] = cp; in replacearg()
1150 if (args->list != NULL && args->num < args->nalloc) { in freeargs()
1151 for (i = 0; i < args->num; i++) in freeargs()
1152 free(args->list[i]); in freeargs()
1153 free(args->list); in freeargs()
1155 args->nalloc = args->num = 0; in freeargs()
1156 args->list = NULL; in freeargs()
1170 int ret = -1, r, slash; in tilde_expand()
1190 copy[path - copy] = '\0'; in tilde_expand()
1210 slash = (len = strlen(pw->pw_dir)) == 0 || pw->pw_dir[len - 1] != '/'; in tilde_expand()
1212 if ((r = xasprintf(&s, "%s%s%s", pw->pw_dir, in tilde_expand()
1297 len = varend - string; in vdollar_percent_expand()
1299 error_f("zero-length environment variable"); in vdollar_percent_expand()
1308 debug3_f("expand ${%s} -> '%s'", var, val); in vdollar_percent_expand()
1340 fatal_fr(r, "sshbuf_put %%-repl"); in vdollar_percent_expand()
1425 int fd = -1, sock; in tun_open()
1439 for (tun = 100; tun >= 0; tun--) { in tun_open()
1447 return -1; in tun_open()
1450 if (fd == -1) { in tun_open()
1452 return -1; in tun_open()
1459 if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) in tun_open()
1462 if (ioctl(sock, SIOCGIFFLAGS, &ifr) == -1) { in tun_open()
1470 if (ioctl(sock, SIOCSIFFLAGS, &ifr) == -1) { in tun_open()
1488 return -1; in tun_open()
1491 return (-1); in tun_open()
1500 if ((nullfd = dupfd = open(_PATH_DEVNULL, O_RDWR)) == -1) { in sanitise_stdfd()
1507 if (fcntl(dupfd, F_GETFL) == -1 && errno == EBADF) { in sanitise_stdfd()
1508 if (dup2(nullfd, dupfd) == -1) { in sanitise_stdfd()
1669 ms_subtract_diff(struct timeval *start, int *ms) in ms_subtract_diff() argument
1675 *ms -= (diff.tv_sec * 1000) + (diff.tv_usec / 1000); in ms_subtract_diff()
1679 ms_to_timespec(struct timespec *ts, int ms) in ms_to_timespec() argument
1681 if (ms < 0) in ms_to_timespec()
1682 ms = 0; in ms_to_timespec()
1683 ts->tv_sec = ms / 1000; in ms_to_timespec()
1684 ts->tv_nsec = (ms % 1000) * 1000 * 1000; in ms_to_timespec()
1714 ts->tv_sec = tv.tv_sec; in monotime_ts()
1715 ts->tv_nsec = (long)tv.tv_usec * 1000; in monotime_ts()
1724 tv->tv_sec = ts.tv_sec; in monotime_tv()
1725 tv->tv_usec = ts.tv_nsec / 1000; in monotime_tv()
1749 bw->buflen = buflen; in bandwidth_limit_init()
1750 bw->rate = kbps; in bandwidth_limit_init()
1751 bw->thresh = buflen; in bandwidth_limit_init()
1752 bw->lamt = 0; in bandwidth_limit_init()
1753 timerclear(&bw->bwstart); in bandwidth_limit_init()
1754 timerclear(&bw->bwend); in bandwidth_limit_init()
1757 /* Callback from read/write loop to insert bandwidth-limiting delays */
1764 bw->lamt += read_len; in bandwidth_limit()
1765 if (!timerisset(&bw->bwstart)) { in bandwidth_limit()
1766 monotime_tv(&bw->bwstart); in bandwidth_limit()
1769 if (bw->lamt < bw->thresh) in bandwidth_limit()
1772 monotime_tv(&bw->bwend); in bandwidth_limit()
1773 timersub(&bw->bwend, &bw->bwstart, &bw->bwend); in bandwidth_limit()
1774 if (!timerisset(&bw->bwend)) in bandwidth_limit()
1777 bw->lamt *= 8; in bandwidth_limit()
1778 waitlen = (double)1000000L * bw->lamt / bw->rate; in bandwidth_limit()
1780 bw->bwstart.tv_sec = waitlen / 1000000L; in bandwidth_limit()
1781 bw->bwstart.tv_usec = waitlen % 1000000L; in bandwidth_limit()
1783 if (timercmp(&bw->bwstart, &bw->bwend, >)) { in bandwidth_limit()
1784 timersub(&bw->bwstart, &bw->bwend, &bw->bwend); in bandwidth_limit()
1787 if (bw->bwend.tv_sec) { in bandwidth_limit()
1788 bw->thresh /= 2; in bandwidth_limit()
1789 if (bw->thresh < bw->buflen / 4) in bandwidth_limit()
1790 bw->thresh = bw->buflen / 4; in bandwidth_limit()
1791 } else if (bw->bwend.tv_usec < 10000) { in bandwidth_limit()
1792 bw->thresh *= 2; in bandwidth_limit()
1793 if (bw->thresh > bw->buflen * 8) in bandwidth_limit()
1794 bw->thresh = bw->buflen * 8; in bandwidth_limit()
1797 TIMEVAL_TO_TIMESPEC(&bw->bwend, &ts); in bandwidth_limit()
1798 while (nanosleep(&ts, &rm) == -1) { in bandwidth_limit()
1805 bw->lamt = 0; in bandwidth_limit()
1806 monotime_tv(&bw->bwstart); in bandwidth_limit()
1817 r = snprintf(s, len, "%s/ssh-XXXXXXXXXXXX", tmpdir); in mktemp_proto()
1821 r = snprintf(s, len, "/tmp/ssh-XXXXXXXXXXXX"); in mktemp_proto()
1856 { NULL, -1 }
1867 return -1; in parse_ipqos()
1875 return -1; in parse_ipqos()
1912 return -1; in unix_listener()
1916 if (sock == -1) { in unix_listener()
1920 return -1; in unix_listener()
1926 if (bind(sock, (struct sockaddr *)&sunaddr, sizeof(sunaddr)) == -1) { in unix_listener()
1931 return -1; in unix_listener()
1933 if (listen(sock, backlog) == -1) { in unix_listener()
1939 return -1; in unix_listener()
1951 if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) == -1) in sock_set_v6only()
1957 * Compares two strings that maybe be NULL. Returns non-zero if strings
1971 * Compare two forwards, returning non-zero if they are identical or
1977 if (strcmp_maybe_null(a->listen_host, b->listen_host) == 0) in forward_equals()
1979 if (a->listen_port != b->listen_port) in forward_equals()
1981 if (strcmp_maybe_null(a->listen_path, b->listen_path) == 0) in forward_equals()
1983 if (strcmp_maybe_null(a->connect_host, b->connect_host) == 0) in forward_equals()
1985 if (a->connect_port != b->connect_port) in forward_equals()
1987 if (strcmp_maybe_null(a->connect_path, b->connect_path) == 0) in forward_equals()
2145 (*argcp)--; in argv_next()
2169 /* Returns 0 if pid exited cleanly, non-zero otherwise */
2175 while (waitpid(pid, &status, 0) == -1) { in exited_cleanly()
2178 return -1; in exited_cleanly()
2183 return -1; in exited_cleanly()
2187 return -1; in exited_cleanly()
2203 * Returns 0 on success and -1 on failure
2217 return -1; in safe_path()
2222 if (!S_ISREG(stp->st_mode)) { in safe_path()
2224 return -1; in safe_path()
2226 if ((!platform_sys_dir_uid(stp->st_uid) && stp->st_uid != uid) || in safe_path()
2227 (stp->st_mode & 022) != 0) { in safe_path()
2230 return -1; in safe_path()
2237 return -1; in safe_path()
2241 if (stat(buf, &st) == -1 || in safe_path()
2246 return -1; in safe_path()
2267 * Returns 0 on success and -1 on failure
2276 if (fstat(fd, &st) == -1) { in safe_path_fd()
2279 return -1; in safe_path_fd()
2281 return safe_path(file, &st, pw->pw_dir, pw->pw_uid, err, errlen); in safe_path_fd()
2329 if (i >= envsize - 1) { in child_set_env()
2375 if (c != '.' && c != '-' && !isalnum(c) && in valid_domain()
2383 if (name[l - 1] == '.') in valid_domain()
2384 name[l - 1] = '\0'; in valid_domain()
2440 if (l > 1 && strcasecmp(s + l - 1, "Z") == 0) { in parse_absolute_time()
2442 l--; in parse_absolute_time()
2443 } else if (l > 3 && strcasecmp(s + l - 3, "UTC") == 0) { in parse_absolute_time()
2445 l -= 3; in parse_absolute_time()
2449 * is white-space or other non-alphanumeric characters between in parse_absolute_time()
2454 fmt = "%Y-%m-%d"; in parse_absolute_time()
2455 snprintf(buf, sizeof(buf), "%.4s-%.2s-%.2s", s, s + 4, s + 6); in parse_absolute_time()
2458 fmt = "%Y-%m-%dT%H:%M"; in parse_absolute_time()
2459 snprintf(buf, sizeof(buf), "%.4s-%.2s-%.2sT%.2s:%.2s", in parse_absolute_time()
2463 fmt = "%Y-%m-%dT%H:%M:%S"; in parse_absolute_time()
2464 snprintf(buf, sizeof(buf), "%.4s-%.2s-%.2sT%.2s:%.2s:%.2s", in parse_absolute_time()
2493 strftime(buf, len, "%Y-%m-%dT%H:%M:%S", &tm); in format_absolute_time()
2498 * Returns 0 on success or non-zero on failure.
2512 return -1; in parse_pattern_interval()
2517 return -1; in parse_pattern_interval()
2522 return -1; in parse_pattern_interval()
2550 /* authorized_key-style options parsing helpers */
2554 * 'no-opt'. Returns -1 if option not matched, 1 if option matches or 0
2566 if (allow_negate && strncasecmp(opts, "no-", 3) == 0) { in opt_flag()
2574 return -1; in opt_flag()
2623 char ***array, int **iarray, u_int *lp, const char *s, int i) in opt_array_append2() argument
2626 if (*lp >= INT_MAX) in opt_array_append2()
2630 *iarray = xrecallocarray(*iarray, *lp, *lp + 1, in opt_array_append2()
2632 (*iarray)[*lp] = i; in opt_array_append2()
2635 *array = xrecallocarray(*array, *lp, *lp + 1, sizeof(**array)); in opt_array_append2()
2636 (*array)[*lp] = xstrdup(s); in opt_array_append2()
2637 (*lp)++; in opt_array_append2()
2642 char ***array, u_int *lp, const char *s) in opt_array_append() argument
2644 opt_array_append2(file, line, directive, array, NULL, lp, s, 0); in opt_array_append()
2673 if (sigaction(signum, &sa, &osa) == -1) { in ssh_signal()
2685 if ((devnull = open(_PATH_DEVNULL, O_RDWR)) == -1) { in stdfd_devnull()
2688 return -1; in stdfd_devnull()
2690 if ((do_stdin && dup2(devnull, STDIN_FILENO) == -1) || in stdfd_devnull()
2691 (do_stdout && dup2(devnull, STDOUT_FILENO) == -1) || in stdfd_devnull()
2692 (do_stderr && dup2(devnull, STDERR_FILENO) == -1)) { in stdfd_devnull()
2694 ret = -1; in stdfd_devnull()
2736 tag, command, pw->pw_name, flags); in subprocess()
2751 * and appears safe-ish to execute in subprocess()
2759 if (stat(av[0], &st) == -1) { in subprocess()
2770 if (pipe(p) == -1) { in subprocess()
2781 case -1: /* error */ in subprocess()
2792 child_set_env(&env, &nenv, "USER", pw->pw_name); in subprocess()
2793 child_set_env(&env, &nenv, "LOGNAME", pw->pw_name); in subprocess()
2794 child_set_env(&env, &nenv, "HOME", pw->pw_dir); in subprocess()
2802 if ((devnull = open(_PATH_DEVNULL, O_RDWR)) == -1) { in subprocess()
2807 if (dup2(devnull, STDIN_FILENO) == -1) { in subprocess()
2813 fd = -1; in subprocess()
2818 if (fd != -1 && dup2(fd, STDOUT_FILENO) == -1) { in subprocess()
2825 initgroups(pw->pw_name, pw->pw_gid) == -1) { in subprocess()
2827 pw->pw_name, (u_int)pw->pw_gid, strerror(errno)); in subprocess()
2830 if (setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) == -1) { in subprocess()
2831 error("%s: setresgid %u: %s", tag, (u_int)pw->pw_gid, in subprocess()
2835 if (setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) == -1) { in subprocess()
2836 error("%s: setresuid %u: %s", tag, (u_int)pw->pw_uid, in subprocess()
2842 dup2(STDIN_FILENO, STDERR_FILENO) == -1) { in subprocess()
2865 while (waitpid(pid, NULL, 0) == -1 && errno == EINTR) in subprocess()
2913 /* Initialise a poll/ppoll timeout with an indefinite deadline */
2921 pt->tv_sec = -1; in ptimeout_init()
2922 pt->tv_nsec = 0; in ptimeout_init()
2929 if (pt->tv_sec == -1 || pt->tv_sec >= sec) { in ptimeout_deadline_sec()
2930 pt->tv_sec = sec; in ptimeout_deadline_sec()
2931 pt->tv_nsec = 0; in ptimeout_deadline_sec()
2939 if (pt->tv_sec == -1 || timespeccmp(pt, p, >=)) in ptimeout_deadline_tsp()
2943 /* Specify a poll/ppoll deadline of at most 'ms' milliseconds */
2945 ptimeout_deadline_ms(struct timespec *pt, long ms) in ptimeout_deadline_ms() argument
2949 p.tv_sec = ms / 1000; in ptimeout_deadline_ms()
2950 p.tv_nsec = (ms % 1000) * 1000000; in ptimeout_deadline_ms()
2963 /* 'when' is now or in the past. Timeout ASAP */ in ptimeout_deadline_monotime_tsp()
2964 pt->tv_sec = 0; in ptimeout_deadline_monotime_tsp()
2965 pt->tv_nsec = 0; in ptimeout_deadline_monotime_tsp()
2983 /* Get a poll(2) timeout value in milliseconds */
2987 if (pt->tv_sec == -1) in ptimeout_get_ms()
2988 return -1; in ptimeout_get_ms()
2989 if (pt->tv_sec >= (INT_MAX - (pt->tv_nsec / 1000000)) / 1000) in ptimeout_get_ms()
2991 return (pt->tv_sec * 1000) + (pt->tv_nsec / 1000000); in ptimeout_get_ms()
2994 /* Get a ppoll(2) timeout value as a timespec pointer */
2998 return pt->tv_sec == -1 ? NULL : pt; in ptimeout_get_tsp()
3001 /* Returns non-zero if a timeout has been set (i.e. is not indefinite) */
3005 return pt->tv_sec != -1; in ptimeout_isset()
3017 int ret = -1, r; in lib_contains_symbol()
3022 if ((r = nlist(path, nl)) == -1) { in lib_contains_symbol()
3036 int fd, ret = -1; in lib_contains_symbol()
3044 return -1; in lib_contains_symbol()