treewide: use designated initializers for ai_hints
authorRuben Kerkhof <ruben@rubenkerkhof.com>
Tue, 2 Aug 2016 14:27:17 +0000 (16:27 +0200)
committerRuben Kerkhof <ruben@rubenkerkhof.com>
Wed, 3 Aug 2016 08:05:11 +0000 (10:05 +0200)
21 files changed:
src/apcups.c
src/chrony.c
src/daemon/collectd.c
src/daemon/common.c
src/gmond.c
src/hddtemp.c
src/libcollectdclient/client.c
src/libcollectdclient/network.c
src/mbmon.c
src/memcached.c
src/modbus.c
src/network.c
src/ntpd.c
src/olsrd.c
src/pinba.c
src/statsd.c
src/teamspeak2.c
src/write_graphite.c
src/write_sensu.c
src/write_tsdb.c
src/zookeeper.c

index 8424933..aa0be83 100644 (file)
@@ -115,13 +115,14 @@ static int net_open (char const *node, char const *service)
 {
        int              sd;
        int              status;
-       struct addrinfo  ai_hints = { 0 };
        struct addrinfo *ai_return;
        struct addrinfo *ai_list;
 
        /* TODO: Change this to `AF_UNSPEC' if apcupsd can handle IPv6 */
-       ai_hints.ai_family   = AF_INET;
-       ai_hints.ai_socktype = SOCK_STREAM;
+       struct addrinfo ai_hints = {
+               .ai_family = AF_INET,
+               .ai_socktype = SOCK_STREAM
+       };
 
        status = getaddrinfo (node, service, &ai_hints, &ai_return);
        if (status != 0)
index 4a09753..9c40dd3 100644 (file)
@@ -306,14 +306,15 @@ static int
 connect_client(const char *p_hostname,
                const char *p_service, int p_family, int p_socktype)
 {
-  struct addrinfo hints = { 0 };
-  struct addrinfo *res = NULL, *ressave = NULL;
+  struct addrinfo *res, *ressave;
   int n, sockfd;
 
-  hints.ai_family = p_family;
-  hints.ai_socktype = p_socktype;
+  struct addrinfo ai_hints = {
+    .ai_family = p_family,
+    .ai_socktype = p_socktype
+  };
 
-  n = getaddrinfo(p_hostname, p_service, &hints, &res);
+  n = getaddrinfo(p_hostname, p_service, &ai_hints, &res);
 
   if (n < 0)
   {
index 8405208..3a6fe1e 100644 (file)
@@ -97,7 +97,6 @@ static int init_hostname (void)
 {
        const char *str;
 
-       struct addrinfo  ai_hints = { 0 };
        struct addrinfo *ai_list;
        struct addrinfo *ai_ptr;
        int status;
@@ -120,7 +119,9 @@ static int init_hostname (void)
        if (IS_FALSE (str))
                return (0);
 
-       ai_hints.ai_flags = AI_CANONNAME;
+       struct addrinfo ai_hints = {
+               .ai_flags = AI_CANONNAME
+       };
 
        status = getaddrinfo (hostname_g, NULL, &ai_hints, &ai_list);
        if (status != 0)
index 9da4775..b3bc753 100644 (file)
@@ -1518,7 +1518,6 @@ int service_name_to_port_number (const char *service_name)
 {
        struct addrinfo *ai_list;
        struct addrinfo *ai_ptr;
-       struct addrinfo ai_hints = { 0 };
        int status;
        int service_number;
 
@@ -1526,7 +1525,10 @@ int service_name_to_port_number (const char *service_name)
                return (-1);
 
        ai_list = NULL;
-       ai_hints.ai_family = AF_UNSPEC;
+
+       struct addrinfo ai_hints = {
+               .ai_family = AF_UNSPEC
+       };
 
        status = getaddrinfo (/* node = */ NULL, service_name,
                        &ai_hints, &ai_list);
index 9dda84c..cfe7eaf 100644 (file)
@@ -211,7 +211,6 @@ static int create_sockets (socket_entry_t **ret_sockets, /* {{{ */
     size_t *ret_sockets_num,
     const char *node, const char *service, int listen)
 {
-  struct addrinfo  ai_hints = { 0 };
   struct addrinfo *ai_list;
   struct addrinfo *ai_ptr;
   int              ai_return;
@@ -224,10 +223,12 @@ static int create_sockets (socket_entry_t **ret_sockets, /* {{{ */
   if (*ret_sockets != NULL)
     return (EINVAL);
 
-  ai_hints.ai_flags    = AI_ADDRCONFIG | AI_PASSIVE;
-  ai_hints.ai_family   = AF_UNSPEC;
-  ai_hints.ai_socktype = SOCK_DGRAM;
-  ai_hints.ai_protocol = IPPROTO_UDP;
+  struct addrinfo ai_hints = {
+    .ai_family = AF_UNSPEC,
+    .ai_flags = AI_ADDRCONFIG | AI_PASSIVE,
+    .ai_protocol = IPPROTO_UDP,
+    .ai_socktype = SOCK_DGRAM
+  };
 
   ai_return = getaddrinfo (node, service, &ai_hints, &ai_list);
   if (ai_return != 0)
index bda41a1..1b7ed32 100644 (file)
@@ -88,15 +88,9 @@ static int hddtemp_query_daemon (char *buffer, int buffer_size)
        const char *host;
        const char *port;
 
-       struct addrinfo  ai_hints = { 0 };
        struct addrinfo *ai_list, *ai_ptr;
        int              ai_return;
 
-       ai_hints.ai_flags    = AI_ADDRCONFIG;
-       ai_hints.ai_family   = PF_UNSPEC;
-       ai_hints.ai_socktype = SOCK_STREAM;
-       ai_hints.ai_protocol = IPPROTO_TCP;
-
        host = hddtemp_host;
        if (host == NULL)
                host = HDDTEMP_DEF_HOST;
@@ -105,6 +99,13 @@ static int hddtemp_query_daemon (char *buffer, int buffer_size)
        if (strlen (port) == 0)
                port = HDDTEMP_DEF_PORT;
 
+       struct addrinfo ai_hints = {
+               .ai_flags = AI_ADDRCONFIG,
+               .ai_family = PF_UNSPEC,
+               .ai_protocol = IPPROTO_TCP,
+               .ai_socktype = SOCK_STREAM
+       };
+
        if ((ai_return = getaddrinfo (host, port, &ai_hints, &ai_list)) != 0)
        {
                char errbuf[1024];
index 58c4e67..fea9360 100644 (file)
@@ -420,7 +420,6 @@ static int lcc_open_unixsocket (lcc_connection_t *c, const char *path) /* {{{ */
 static int lcc_open_netsocket (lcc_connection_t *c, /* {{{ */
     const char *addr_orig)
 {
-  struct addrinfo ai_hints = { 0 };
   struct addrinfo *ai_res;
   struct addrinfo *ai_ptr;
   char addr_copy[NI_MAXHOST];
@@ -437,10 +436,6 @@ static int lcc_open_netsocket (lcc_connection_t *c, /* {{{ */
   addr_copy[sizeof(addr_copy) - 1] = '\0';
   addr = addr_copy;
 
-  ai_hints.ai_flags  = AI_ADDRCONFIG;
-  ai_hints.ai_family = AF_UNSPEC;
-  ai_hints.ai_socktype = SOCK_STREAM;
-
   port = NULL;
   if (*addr == '[') /* IPv6+port format */
   {
@@ -477,6 +472,13 @@ static int lcc_open_netsocket (lcc_connection_t *c, /* {{{ */
   }
 
   ai_res = NULL;
+
+  struct addrinfo ai_hints = {
+    .ai_family = AF_UNSPEC,
+    .ai_flags = AI_ADDRCONFIG,
+    .ai_socktype = SOCK_STREAM
+  };
+
   status = getaddrinfo (addr,
                         port == NULL ? LCC_DEFAULT_PORT : port,
                         &ai_hints, &ai_res);
index fdca6e4..afbee6e 100644 (file)
@@ -119,7 +119,6 @@ static void int_server_destroy (lcc_server_t *srv) /* {{{ */
 
 static int server_open_socket (lcc_server_t *srv) /* {{{ */
 {
-  struct addrinfo ai_hints = { 0 };
   struct addrinfo *ai_list = NULL;
   struct addrinfo *ai_ptr;
   int status;
@@ -130,9 +129,11 @@ static int server_open_socket (lcc_server_t *srv) /* {{{ */
   if (srv->fd >= 0)
     server_close_socket (srv);
 
-  ai_hints.ai_flags = AI_ADDRCONFIG;
-  ai_hints.ai_family   = AF_UNSPEC;
-  ai_hints.ai_socktype = SOCK_DGRAM;
+  struct addrinfo ai_hints = {
+    .ai_family = AF_UNSPEC,
+    .ai_flags = AI_ADDRCONFIG,
+    .ai_socktype = SOCK_DGRAM
+  };
 
   status = getaddrinfo (srv->node, srv->service, &ai_hints, &ai_list);
   if (status != 0)
index bec6bdf..1f0a0d6 100644 (file)
@@ -84,15 +84,9 @@ static int mbmon_query_daemon (char *buffer, int buffer_size)
        const char *host;
        const char *port;
 
-       struct addrinfo  ai_hints = { 0 };
        struct addrinfo *ai_list, *ai_ptr;
        int              ai_return;
 
-       ai_hints.ai_flags    = AI_ADDRCONFIG;
-       ai_hints.ai_family   = PF_UNSPEC;
-       ai_hints.ai_socktype = SOCK_STREAM;
-       ai_hints.ai_protocol = IPPROTO_TCP;
-
        host = mbmon_host;
        if (host == NULL)
                host = MBMON_DEF_HOST;
@@ -101,6 +95,13 @@ static int mbmon_query_daemon (char *buffer, int buffer_size)
        if (port == NULL)
                port = MBMON_DEF_PORT;
 
+       struct addrinfo ai_hints = {
+               .ai_family = PF_UNSPEC,
+               .ai_flags = AI_ADDRCONFIG,
+               .ai_protocol = IPPROTO_TCP,
+               .ai_socktype = SOCK_STREAM
+       };
+
        if ((ai_return = getaddrinfo (host, port, &ai_hints, &ai_list)) != 0)
        {
                char errbuf[1024];
index 17a7760..c0c9e70 100644 (file)
@@ -101,20 +101,21 @@ static int memcached_connect_inet (memcached_t *st)
   const char *host;
   const char *port;
 
-  struct addrinfo  ai_hints = { 0 };
   struct addrinfo *ai_list, *ai_ptr;
   int status;
   int fd = -1;
 
-  ai_hints.ai_flags    = AI_ADDRCONFIG;
-  ai_hints.ai_family   = AF_UNSPEC;
-  ai_hints.ai_socktype = SOCK_STREAM;
-  ai_hints.ai_protocol = 0;
-
   host = (st->host != NULL) ? st->host : MEMCACHED_DEF_HOST;
   port = (st->port != NULL) ? st->port : MEMCACHED_DEF_PORT;
 
   ai_list = NULL;
+
+  struct addrinfo ai_hints = {
+    .ai_family = AF_UNSPEC,
+    .ai_flags = AI_ADDRCONFIG,
+    .ai_socktype = SOCK_STREAM
+  };
+
   status = getaddrinfo (host, port, &ai_hints, &ai_list);
   if (status != 0)
   {
index c58cb39..a215060 100644 (file)
@@ -818,20 +818,19 @@ static int mb_config_set_host_address (mb_host_t *host, /* {{{ */
 {
   struct addrinfo *ai_list;
   struct addrinfo *ai_ptr;
-  struct addrinfo  ai_hints = { 0 };
   int status;
 
   if ((host == NULL) || (address == NULL))
     return (EINVAL);
 
-  ai_hints.ai_flags = AI_ADDRCONFIG;
-  /* XXX: libmodbus can only handle IPv4 addresses. */
-  ai_hints.ai_family = AF_INET;
-  ai_hints.ai_addr = NULL;
-  ai_hints.ai_canonname = NULL;
-  ai_hints.ai_next = NULL;
-
   ai_list = NULL;
+
+  struct addrinfo  ai_hints = {
+    /* XXX: libmodbus can only handle IPv4 addresses. */
+    .ai_family = AF_INET,
+    .ai_flags = AI_ADDRCONFIG
+  };
+
   status = getaddrinfo (address, /* service = */ NULL,
       &ai_hints, &ai_list);
   if (status != 0)
index baeb915..11c39a7 100644 (file)
@@ -2139,7 +2139,6 @@ static int sockent_client_connect (sockent_t *se) /* {{{ */
        static c_complain_t complaint = C_COMPLAIN_INIT_STATIC;
 
        struct sockent_client *client;
-       struct addrinfo  ai_hints = { 0 };
        struct addrinfo *ai_list = NULL, *ai_ptr;
        int status;
        _Bool reconnect = 0;
@@ -2160,10 +2159,12 @@ static int sockent_client_connect (sockent_t *se) /* {{{ */
        if (client->fd >= 0 && !reconnect) /* already connected and not stale*/
                return (0);
 
-       ai_hints.ai_flags    = AI_ADDRCONFIG;
-       ai_hints.ai_family   = AF_UNSPEC;
-       ai_hints.ai_socktype = SOCK_DGRAM;
-       ai_hints.ai_protocol = IPPROTO_UDP;
+       struct addrinfo ai_hints = {
+               .ai_family   = AF_UNSPEC,
+               .ai_flags    = AI_ADDRCONFIG,
+               .ai_protocol = IPPROTO_UDP,
+               .ai_socktype = SOCK_DGRAM
+       };
 
        status = getaddrinfo (se->node,
                        (se->service != NULL) ? se->service : NET_DEFAULT_PORT,
@@ -2234,7 +2235,6 @@ static int sockent_client_connect (sockent_t *se) /* {{{ */
 /* Open the file descriptors for a initialized sockent structure. */
 static int sockent_server_listen (sockent_t *se) /* {{{ */
 {
-       struct addrinfo  ai_hints = { 0 };
        struct addrinfo *ai_list, *ai_ptr;
        int              status;
 
@@ -2256,10 +2256,12 @@ static int sockent_server_listen (sockent_t *se) /* {{{ */
         DEBUG ("network plugin: sockent_server_listen: node = %s; service = %s;",
             node, service);
 
-       ai_hints.ai_flags    = AI_ADDRCONFIG | AI_PASSIVE;
-       ai_hints.ai_family   = AF_UNSPEC;
-       ai_hints.ai_socktype = SOCK_DGRAM;
-       ai_hints.ai_protocol = IPPROTO_UDP;
+       struct addrinfo ai_hints = {
+               .ai_family   = AF_UNSPEC,
+               .ai_flags    = AI_ADDRCONFIG | AI_PASSIVE,
+               .ai_protocol = IPPROTO_UDP,
+               .ai_socktype = SOCK_DGRAM
+       };
 
        status = getaddrinfo (node, service, &ai_hints, &ai_list);
        if (status != 0)
index f36c500..e075a20 100644 (file)
@@ -346,7 +346,6 @@ static int ntpd_connect (void)
        const char *host;
        const char *port;
 
-       struct addrinfo  ai_hints = { 0 };
        struct addrinfo *ai_list;
        struct addrinfo *ai_ptr;
        int              status;
@@ -364,10 +363,12 @@ static int ntpd_connect (void)
        if (strlen (port) == 0)
                port = NTPD_DEFAULT_PORT;
 
-       ai_hints.ai_flags    = AI_ADDRCONFIG;
-       ai_hints.ai_family   = PF_UNSPEC;
-       ai_hints.ai_socktype = SOCK_DGRAM;
-       ai_hints.ai_protocol = IPPROTO_UDP;
+       struct addrinfo ai_hints = {
+               .ai_family   = PF_UNSPEC,
+               .ai_flags    = AI_ADDRCONFIG,
+               .ai_protocol = IPPROTO_UDP,
+               .ai_socktype = SOCK_DGRAM
+       };
 
        if ((status = getaddrinfo (host, port, &ai_hints, &ai_list)) != 0)
        {
index 2a4bf03..976793f 100644 (file)
@@ -149,18 +149,20 @@ static size_t strtabsplit (char *string, char **fields, size_t size) /* {{{ */
 
 static FILE *olsrd_connect (void) /* {{{ */
 {
-  struct addrinfo  ai_hints = { 0 };
   struct addrinfo *ai_list, *ai_ptr;
   int              ai_return;
 
   FILE *fh;
 
-  ai_hints.ai_flags    = AI_ADDRCONFIG;
-  ai_hints.ai_family   = PF_UNSPEC;
-  ai_hints.ai_socktype = SOCK_STREAM;
-  ai_hints.ai_protocol = IPPROTO_TCP;
-
   ai_list = NULL;
+
+  struct addrinfo ai_hints = {
+    .ai_family   = PF_UNSPEC,
+    .ai_flags    = AI_ADDRCONFIG,
+    .ai_protocol = IPPROTO_TCP,
+    .ai_socktype = SOCK_STREAM
+  };
+
   ai_return = getaddrinfo (olsrd_get_node (), olsrd_get_service (),
       &ai_hints, &ai_list);
   if (ai_return != 0)
index 833fa1b..6a4ebfc 100644 (file)
@@ -352,16 +352,8 @@ static pinba_socket_t *pinba_socket_open (const char *node, /* {{{ */
   pinba_socket_t *s;
   struct addrinfo *ai_list;
   struct addrinfo *ai_ptr;
-  struct addrinfo  ai_hints = { 0 };
   int status;
 
-  ai_hints.ai_flags = AI_PASSIVE;
-  ai_hints.ai_family = AF_UNSPEC;
-  ai_hints.ai_socktype = SOCK_DGRAM;
-  ai_hints.ai_addr = NULL;
-  ai_hints.ai_canonname = NULL;
-  ai_hints.ai_next = NULL;
-
   if (node == NULL)
     node = PINBA_DEFAULT_NODE;
 
@@ -369,6 +361,13 @@ static pinba_socket_t *pinba_socket_open (const char *node, /* {{{ */
     service = PINBA_DEFAULT_SERVICE;
 
   ai_list = NULL;
+
+  struct addrinfo  ai_hints = {
+    .ai_family = AF_UNSPEC,
+    .ai_flags = AI_PASSIVE,
+    .ai_socktype = SOCK_DGRAM
+  };
+
   status = getaddrinfo (node, service,
       &ai_hints, &ai_list);
   if (status != 0)
index 5df072d..285486d 100644 (file)
@@ -500,7 +500,6 @@ static int statsd_network_init (struct pollfd **ret_fds, /* {{{ */
   struct pollfd *fds = NULL;
   size_t fds_num = 0;
 
-  struct addrinfo ai_hints = { 0 };
   struct addrinfo *ai_list = NULL;
   struct addrinfo *ai_ptr;
   int status;
@@ -509,9 +508,11 @@ static int statsd_network_init (struct pollfd **ret_fds, /* {{{ */
   char const *service = (conf_service != NULL)
     ? conf_service : STATSD_DEFAULT_SERVICE;
 
-  ai_hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
-  ai_hints.ai_family = AF_UNSPEC;
-  ai_hints.ai_socktype = SOCK_DGRAM;
+  struct addrinfo ai_hints = {
+    .ai_family = AF_UNSPEC,
+    .ai_flags = AI_PASSIVE | AI_ADDRCONFIG,
+    .ai_socktype = SOCK_DGRAM
+  };
 
   status = getaddrinfo (node, service, &ai_hints, &ai_list);
   if (status != 0)
index 89578f0..5d53460 100644 (file)
@@ -198,7 +198,6 @@ static int tss2_get_socket (FILE **ret_read_fh, FILE **ret_write_fh)
         * Returns connected file objects or establishes the connection
         * if it's not already present
         */
-       struct addrinfo ai_hints = { 0 };
        struct addrinfo *ai_head;
        struct addrinfo *ai_ptr;
        int sd = -1;
@@ -216,9 +215,11 @@ static int tss2_get_socket (FILE **ret_read_fh, FILE **ret_write_fh)
        }
 
        /* Get all addrs for this hostname */
-       ai_hints.ai_flags = AI_ADDRCONFIG;
-       ai_hints.ai_family = AF_UNSPEC;
-       ai_hints.ai_socktype = SOCK_STREAM;
+       struct addrinfo ai_hints = {
+               .ai_family = AF_UNSPEC,
+               .ai_flags = AI_ADDRCONFIG,
+               .ai_socktype = SOCK_STREAM
+       };
 
        status = getaddrinfo ((config_host != NULL) ? config_host : DEFAULT_HOST,
                        (config_port != NULL) ? config_port : DEFAULT_PORT,
index a22a236..efdd4d8 100644 (file)
@@ -193,7 +193,6 @@ static int wg_flush_nolock (cdtime_t timeout, struct wg_callback *cb)
 
 static int wg_callback_init (struct wg_callback *cb)
 {
-    struct addrinfo ai_hints = { 0 };
     struct addrinfo *ai_list;
     struct addrinfo *ai_ptr;
     cdtime_t now;
@@ -211,8 +210,10 @@ static int wg_callback_init (struct wg_callback *cb)
         return (EAGAIN);
     cb->last_connect_time = now;
 
-    ai_hints.ai_flags  = AI_ADDRCONFIG;
-    ai_hints.ai_family = AF_UNSPEC;
+    struct addrinfo ai_hints = {
+        .ai_family = AF_UNSPEC,
+        .ai_flags  = AI_ADDRCONFIG
+    };
 
     if (0 == strcasecmp ("tcp", cb->protocol))
         ai_hints.ai_socktype = SOCK_STREAM;
index 99fca17..63c6d99 100644 (file)
@@ -104,23 +104,25 @@ static void free_str_list(struct str_list *strs) /* {{{ */
 static int sensu_connect(struct sensu_host *host) /* {{{ */
 {
        int                      e;
-       struct addrinfo         *ai, hints;
+       struct addrinfo         *ai;
        char const              *node;
        char const              *service;
 
        // Resolve the target if we haven't done already
        if (!(host->flags & F_READY)) {
-               memset(&hints, 0, sizeof(hints));
                memset(&service, 0, sizeof(service));
                host->res = NULL;
-               hints.ai_family = AF_INET;
-               hints.ai_socktype = SOCK_STREAM;
-               hints.ai_flags = AI_ADDRCONFIG;
 
                node = (host->node != NULL) ? host->node : SENSU_HOST;
                service = (host->service != NULL) ? host->service : SENSU_PORT;
 
-               if ((e = getaddrinfo(node, service, &hints, &(host->res))) != 0) {
+               struct addrinfo ai_hints = {
+                       .ai_family = AF_INET,
+                       .ai_flags = AI_ADDRCONFIG,
+                       .ai_socktype = SOCK_STREAM
+               };
+
+               if ((e = getaddrinfo(node, service, &ai_hints, &(host->res))) != 0) {
                        ERROR("write_sensu plugin: Unable to resolve host \"%s\": %s",
                                        node, gai_strerror(e));
                        return -1;
index 7a8f851..fe418cf 100644 (file)
@@ -155,7 +155,6 @@ static int wt_flush_nolock(cdtime_t timeout, struct wt_callback *cb)
 
 static int wt_callback_init(struct wt_callback *cb)
 {
-    struct addrinfo ai_hints = { 0 };
     struct addrinfo *ai_list;
     struct addrinfo *ai_ptr;
     int status;
@@ -166,12 +165,14 @@ static int wt_callback_init(struct wt_callback *cb)
     if (cb->sock_fd > 0)
         return 0;
 
-    ai_hints.ai_flags    = AI_ADDRCONFIG;
-    ai_hints.ai_family   = AF_UNSPEC;
-    ai_hints.ai_socktype = SOCK_STREAM;
-
     ai_list = NULL;
 
+    struct addrinfo ai_hints = {
+        .ai_family = AF_UNSPEC,
+        .ai_flags = AI_ADDRCONFIG,
+        .ai_socktype = SOCK_STREAM
+    };
+
     status = getaddrinfo(node, service, &ai_hints, &ai_list);
     if (status != 0)
     {
index a236c8a..a3b7362 100644 (file)
@@ -105,17 +105,19 @@ static int zookeeper_connect (void)
 {
        int sk = -1;
        int status;
-       struct addrinfo ai_hints = { 0 };
        struct addrinfo *ai;
        struct addrinfo *ai_list;
        const char *host;
        const char *port;
 
-       ai_hints.ai_family   = AF_UNSPEC;
-       ai_hints.ai_socktype = SOCK_STREAM;
-
        host = (zk_host != NULL) ? zk_host : ZOOKEEPER_DEF_HOST;
        port = (zk_port != NULL) ? zk_port : ZOOKEEPER_DEF_PORT;
+
+       struct addrinfo ai_hints = {
+               .ai_family   = AF_UNSPEC,
+               .ai_socktype = SOCK_STREAM
+       };
+
        status = getaddrinfo (host, port, &ai_hints, &ai_list);
        if (status != 0)
        {