links

lynx-like text mode web browser
git clone anongit@rnpnr.xyz:links.git
Log | Files | Refs | Feed | README | LICENSE

Commit: 42585197ed0bea4a8c9c590b8bbbcfcff5d7f9a9
Parent: 949516ff5c4b2620b272ec805f2cfbace53134b6
Author: Randy Palamar
Date:   Thu, 26 Aug 2021 16:31:18 -0600

cleanup c_socket a bit and remove incorrect error checks

the error checks were wrong before but now they are even more wrong

Diffstat:
Mconnect.c | 9++-------
Mdns.c | 14+++++++-------
Mos_dep.c | 16+++++++++++-----
3 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/connect.c b/connect.c @@ -16,11 +16,8 @@ static void handle_socks_reply(void *); int socket_and_bind(int pf, unsigned char *address) { - int s; - int rs; - s = c_socket(pf, SOCK_STREAM, IPPROTO_TCP); - if (s == -1) - return -1; + int rs, s = c_socket(pf, SOCK_STREAM, IPPROTO_TCP); + if (address && *address) { switch (pf) { case PF_INET: { @@ -186,7 +183,6 @@ int get_pasv_socket(struct connection *c, int cc, int *sock, unsigned char *port goto e; } s = c_socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); - if (s == -1) goto e; *sock = s; set_nonblock(s); memcpy(&sb, &sa, sizeof(struct sockaddr_in)); @@ -224,7 +220,6 @@ int get_pasv_socket_ipv6(struct connection *c, int cc, int *sock, unsigned char goto e; } s = c_socket(PF_INET6, SOCK_STREAM, IPPROTO_TCP); - if (s == -1) goto e; *sock = s; set_nonblock(s); memcpy(&sb, &sa, sizeof(struct sockaddr_in6)); diff --git a/dns.c b/dns.c @@ -3,6 +3,8 @@ * This file is a part of the Links program, released under GPL */ +#include <sys/socket.h> + #include "links.h" int support_ipv6; @@ -474,8 +476,6 @@ int ipv6_full_access(void) if (!support_ipv6) return 0; h = c_socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); - if (h == -1) - return 0; memset(&sin6, 0, sizeof sin6); sin6.sin6_family = AF_INET6; sin6.sin6_port = htons(1024); @@ -489,13 +489,13 @@ int ipv6_full_access(void) void init_dns(void) { + int h; register_cache_upcall(shrink_dns_cache, 0, cast_uchar "dns"); - int h, rs; - h = c_socket(AF_INET6, SOCK_STREAM, 0); - if (h == -1) + h = socket(AF_INET6, SOCK_STREAM, 0); + if (h == -1) { support_ipv6 = 0; - else { - EINTRLOOP(rs, close(h)); + } else { + close(h); support_ipv6 = 1; } } diff --git a/os_dep.c b/os_dep.c @@ -3,8 +3,11 @@ * This file is a part of the Links program, released under GPL. */ +#include <fcntl.h> #include <limits.h> #include <sys/ioctl.h> +#include <sys/socket.h> +#include <unistd.h> #include "links.h" @@ -239,11 +242,14 @@ int c_dup(int oh) int c_socket(int d, int t, int p) { - int h; - do { - EINTRLOOP(h, socket(d, t, p)); - if (h != -1) new_fd_cloexec(h); - } while (h == -1 && cleanup_fds()); + int h = socket(d, t, p); + + if (h == -1) + die("socket()\n"); + + if (fcntl(h, F_SETFD, FD_CLOEXEC) == -1) + die("c_socket(): fcntl()\n"); + return h; }