From: Pavel Rochnyack Date: Mon, 22 Oct 2018 02:03:39 +0000 (+0700) Subject: cleanup: Use compound literals for SO_REUSEADDR setsockopt X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=6ffc9507f630a20577bf9bc70c08d113e47e5ee4 cleanup: Use compound literals for SO_REUSEADDR setsockopt --- diff --git a/src/gmond.c b/src/gmond.c index 2bca05ad..291dfadb 100644 --- a/src/gmond.c +++ b/src/gmond.c @@ -252,10 +252,8 @@ static int create_sockets(socket_entry_t **ret_sockets, /* {{{ */ sockets_num++; break; } else { - int yes = 1; - status = setsockopt(sockets[sockets_num].fd, SOL_SOCKET, SO_REUSEADDR, - (void *)&yes, sizeof(yes)); + &(int){1}, sizeof(int)); if (status != 0) { WARNING("gmond plugin: setsockopt(2) failed: %s", STRERRNO); } diff --git a/src/network.c b/src/network.c index d602dfc8..64c6d24b 100644 --- a/src/network.c +++ b/src/network.c @@ -1728,10 +1728,9 @@ static int network_bind_socket(int fd, const struct addrinfo *ai, #else int loop = 0; #endif - int yes = 1; /* allow multiple sockets to use the same PORT number */ - if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) == -1) { + if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int)) == -1) { ERROR("network plugin: setsockopt (reuseaddr): %s", STRERRNO); return -1; } diff --git a/src/pinba.c b/src/pinba.c index 66b9cd1f..9f571d04 100644 --- a/src/pinba.c +++ b/src/pinba.c @@ -280,9 +280,6 @@ static int pb_del_socket(pinba_socket_t *s, /* {{{ */ static int pb_add_socket(pinba_socket_t *s, /* {{{ */ const struct addrinfo *ai) { - int fd; - int tmp; - int status; if (s->fd_num == PINBA_MAX_SOCKETS) { WARNING("pinba plugin: Sorry, you have hit the built-in limit of " @@ -292,14 +289,13 @@ static int pb_add_socket(pinba_socket_t *s, /* {{{ */ return -1; } - fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); + int fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); if (fd < 0) { ERROR("pinba plugin: socket(2) failed: %s", STRERRNO); return 0; } - tmp = 1; - status = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &tmp, sizeof(tmp)); + int status = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int)); if (status != 0) { WARNING("pinba plugin: setsockopt(SO_REUSEADDR) failed: %s", STRERRNO); } diff --git a/src/write_prometheus.c b/src/write_prometheus.c index 6f9b0490..7137558c 100644 --- a/src/write_prometheus.c +++ b/src/write_prometheus.c @@ -763,8 +763,7 @@ static int prom_open_socket(int addrfamily) { if (fd == -1) continue; - int tmp = 1; - if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &tmp, sizeof(tmp)) != 0) { + if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int)) != 0) { WARNING("write_prometheus: setsockopt(SO_REUSEADDR) failed: %s", STRERRNO); close(fd);