diff options
author | mrb0nk500 <b0nk@b0nk.xyz> | 2021-06-12 08:57:45 -0400 |
---|---|---|
committer | mrb0nk500 <b0nk@b0nk.xyz> | 2021-06-12 08:57:45 -0400 |
commit | c5afd11c47aa7bc0a64a6e54345e50ae690218ef (patch) | |
tree | 8b8f44ea6c021f22cd3be4b50eb4b8fe2ece880a /pullreqd.c | |
parent | 08881ad97e49a619d52dede77c18d69c02d3d150 (diff) |
Expanded all instances of `did_fail`, and
`did_fail_reason`.
I also replaced all instances of `log` in the expanded
`did_fail_reason` instances with `log_reason`.
Diffstat (limited to 'pullreqd.c')
-rw-r--r-- | pullreqd.c | 30 |
1 files changed, 24 insertions, 6 deletions
@@ -102,7 +102,10 @@ int init_socket(config *cfg) { if (sock_type == AF_UNIX) { size_t path_length = strlen(cfg->sock); /* Is the path too long? */ - did_fail(path_length >= UNIX_PATH_MAX, "The socket path is too long, and exceeded %i characters.", UNIX_PATH_MAX); + if (path_length >= UNIX_PATH_MAX) { + log(LOG_ERR, "The socket path is too long, and exceeded %i characters.", UNIX_PATH_MAX); + return -1; + } sockaddr_size = sizeof(sock_addr.sa_un); sock_addr.sa_un.sun_family = sock_type; @@ -119,7 +122,10 @@ int init_socket(config *cfg) { const int gai_ret = getaddrinfo(cfg->sock, cfg->port, &hints, &ainfo_root); /* Did getaddrinfo fail? */ - did_fail_reason(gai_ret, "getaddrinfo() failed for hostname %s.", cfg->sock, gai_strerror(gai_ret)); + if (gai_ret) { + log_reason(LOG_ERR, "getaddrinfo() failed for hostname %s.", cfg->sock, gai_strerror(gai_ret)); + return -1; + } /* TODO: Create sockets for all resolved addresses, instead of just the first. */ sockaddr_size = ainfo_root->ai_addrlen; @@ -132,19 +138,31 @@ int init_socket(config *cfg) { const int fd = socket(sock_addr.sa.sa_family, SOCK_SEQPACKET, 0); /* Did we fail to create the listen socket? */ - did_fail_reason(fd < 0, "Failed to create listen socket.", strerror(errno)); + if (fd < 0) { + log_reason(LOG_ERR, "Failed to create listen socket.", strerror(errno)); + return -1; + } /* Did we fail to bind the listen socket? */ - did_fail_reason(bind(fd, &sock_addr.sa, sockaddr_size) < 0, "Failed to bind listen socket.", strerror(errno)); + if (bind(fd, &sock_addr.sa, sockaddr_size) < 0) { + log_reason(LOG_ERR, "Failed to bind listen socket.", strerror(errno)); + return -1; + } int one = 1; /* Did we fail to enable SO_REUSEADDR? */ - did_fail_reason(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) < 0, "Failed to enable SO_REUSEADDR.", strerror(errno)); + if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) < 0) { + log_reason(LOG_ERR, "Failed to enable SO_REUSEADDR.", strerror(errno)); + return -1; + } /* Did we fail to listen to the socket? */ - did_fail_reason(listen(fd, 20) < 0, "Failed to listen to socket.", strerror(errno)); + if (listen(fd, 20) < 0) { + log_reason(LOG_ERR, "Failed to listen to socket.", strerror(errno)); + return -1; + } log(LOG_INFO, "Successfully created socket descriptor %i for address %s.", fd, cfg->sock); return fd; |