diff --git a/src/main/lkt.c b/src/main/lkt.c index 267adffd9438113b22d7363b920f31d26fa019a9..0b5b06a14cb1d13de33e9dd0e5c56d750e7786a0 100644 --- a/src/main/lkt.c +++ b/src/main/lkt.c @@ -223,10 +223,10 @@ PRIVATE_FUNCTION int read_socket(SOCKET sock, char *buff, size_t max_len) { size_t i; - int len = 0; + ssize_t len = 0; memset(buff, 0, max_len * sizeof(char)); for (i = 0; i < max_len - 1; ++i) { - len = recv(sock, buff+i, (int)max_len, 0); + len = recv(sock, buff+i, max_len, 0); if (buff[i] == '\n' || len != 1) break; } @@ -309,7 +309,7 @@ write_socket(SOCKET sock, const char *format, ...) va_list ap; va_start(ap, format); - int size = safe_vsnprintf(buff, LKT_MESSAGE_MAX - 1, format, ap); + const int size = safe_vsnprintf(buff, LKT_MESSAGE_MAX - 1, format, ap); FAIL_IF(size < 0, "Failed to write to temporary buffer"); FAIL_IF(fwrite(buff, sizeof(char), (size_t)size, sock) < (unsigned int)size, "Connexion error"); diff --git a/src/net/listen.c b/src/net/listen.c index dede5d96cd4cbf4a9c1f418e4ab10664d2bf91d5..1d6dee87af98d6a29ed3411811fa9abe3d587861 100644 --- a/src/net/listen.c +++ b/src/net/listen.c @@ -491,7 +491,7 @@ handle_outgoing_data(struct lkt_state *srv, size_t c) typedef SOCKET (*init_socket_func)(const char *, const char *); static void -init_permission_socket_unix(const char *file, int perms) +init_permission_socket_unix(const char *file, unsigned int perms) { errno = 0; if (chmod(file, perms) < 0) { @@ -531,7 +531,7 @@ failure: static int init_listening_socket_unix(const char UNUSED *file, const char UNUSED *type /* == "unix" */) { - #if defined(LKT_OS_TOASTER) && (LKT_OS_TOASTER == 1) + #if !(defined(LKT_OS_WIN) && (LKT_OS_WIN == 1)) if (!STR_NMATCH(type, "unix", 4)) LOG_FATAL("Incorrect call to the function, 'port' is not set to 'unix'"); @@ -611,7 +611,7 @@ init_listening_socket_net(const char *host, const char *port) goto failure; } - if (bind(fd, p->ai_addr, (int)(p->ai_addrlen)) != 0) { + if (bind(fd, p->ai_addr, p->ai_addrlen) != 0) { closesocket(fd); LOG_ERROR("INIT", "Failed to bind tcp socket: %s", strerror(errno)); continue; @@ -642,7 +642,7 @@ init_listening_socket_net(const char *host, const char *port) } static int -accept_all(SOCKET listen_fd, struct pollfd* fds, ULONG fds_max, ULONG *fds_len) +accept_all(SOCKET listen_fd, struct pollfd* fds, size_t fds_max, size_t *fds_len) { SOCKET fd; struct sockaddr_in peer_addr; @@ -655,7 +655,7 @@ accept_all(SOCKET listen_fd, struct pollfd* fds, ULONG fds_max, ULONG *fds_len) const int error = get_last_error(); if (is_error_would_block(error)) return n; - id (is_error_connection_aborted(error)) + if (is_error_connection_aborted(error)) continue; perror("accept"); return -1; @@ -675,7 +675,6 @@ accept_all(SOCKET listen_fd, struct pollfd* fds, ULONG fds_max, ULONG *fds_len) break; } #else - int flag = fcntl(fd, F_GETFL, 0); const int flag = fcntl(fd, F_GETFL, 0); if (flag < 0) { perror("fcntl"); @@ -1093,7 +1092,7 @@ lkt_listen(struct lkt_state *srv) if (fds_max_config <= 0) LOG_FATAL("The max_clients number must be a positive integer"); - srv->fds_max = (ULONG)fds_max_config; + srv->fds_max = (size_t)fds_max_config; srv->fds = LKT_ALLOC_STRUCT_ARRAY(pollfd, srv->fds_max); srv->clients = LKT_ALLOC_STRUCT_ARRAY(lkt_client, srv->fds_max); @@ -1113,8 +1112,7 @@ lkt_listen(struct lkt_state *srv) LOG_INFO("INIT", "Signal handlers registered"); int is_unix_socket = STR_NMATCH(srv->port, "unix", 4); - char perms_s[6] = { 0 }; - int perms = 0600; + unsigned int perms = 0600; /* FIXME: Use the server register, and add a socket type (which is * unix/tcp) and place the 'socket name' in a [server.socket] and not @@ -1122,16 +1120,11 @@ lkt_listen(struct lkt_state *srv) * function call 'create_unix', 'create_tcp' as [server.use] or something * line that. */ if (is_unix_socket) { - if (!database_config_get_text(srv->db, "server", "permission", perms_s, 6)) - LOG_WARN("INIT", "Failed to get server socket permission, using default 0%o", perms); - else { - perms = (int)strtol(perms_s, NULL, 8); /* In octal */ - LOG_DEBUG("INIT", "Got socket permission 0%o from config file", perms); - } + DBCONF_GET_OCTAL(srv->db, "server", "permission", &perms); } - init_socket_func init_sock = init_listening_socket_net; - (void)init_listening_socket_unix; + const init_socket_func init_sock = + is_unix_socket ? init_listening_socket_unix : init_listening_socket_net; if ((srv->fds[0].fd = init_sock(srv->host, srv->port)) == INVALID_SOCKET) LOG_FATAL("Failed to init socket: %s:%s", srv->host, srv->port);