Code

Tree wide: Use user_data_t compound literal where appropriate.
authorFlorian Forster <octo@collectd.org>
Sun, 11 Sep 2016 19:21:56 +0000 (21:21 +0200)
committerFlorian Forster <octo@collectd.org>
Sun, 11 Sep 2016 19:54:48 +0000 (21:54 +0200)
23 files changed:
src/amqp.c
src/apache.c
src/curl_json.c
src/curl_xml.c
src/dbi.c
src/java.c
src/lua.c
src/memcached.c
src/modbus.c
src/mqtt.c
src/mysql.c
src/netapp.c
src/openldap.c
src/python.c
src/routeros.c
src/snmp.c
src/tail.c
src/tail_csv.c
src/varnish.c
src/write_graphite.c
src/write_kafka.c
src/write_mongodb.c
src/write_redis.c

index 89f051e81960668c957abfe72239c542ed4681d2..06fd1f1d4aecd3d11ed9502fbea45baecc527e00 100644 (file)
@@ -1070,11 +1070,13 @@ static int camqp_config_connection (oconfig_item_t *ci, /* {{{ */
     if (publish)
     {
         char cbname[128];
-        user_data_t ud = { conf, camqp_config_free };
-
         ssnprintf (cbname, sizeof (cbname), "amqp/%s", conf->name);
 
-        status = plugin_register_write (cbname, camqp_write, &ud);
+        status = plugin_register_write (cbname, camqp_write,
+                &(user_data_t) {
+                    .data = conf,
+                    .free_func = camqp_config_free,
+                });
         if (status != 0)
         {
             camqp_config_free (conf);
index e10a15d46a01e4b9ba6a429d7ecb16861d022a10..56546ad8f138093d132b1df58cfd8209918bc257 100644 (file)
@@ -239,11 +239,6 @@ static int config_add (oconfig_item_t *ci)
 
        if (status == 0)
        {
-               user_data_t ud = {
-                       .data = st,
-                       .free_func = apache_free
-               };
-
                char callback_name[3*DATA_MAX_NAME_LEN];
 
                ssnprintf (callback_name, sizeof (callback_name),
@@ -255,7 +250,11 @@ static int config_add (oconfig_item_t *ci)
                                /* name      = */ callback_name,
                                /* callback  = */ apache_read_host,
                                /* interval  = */ 0,
-                               /* user_data = */ &ud);
+                               /* user_data = */ &(user_data_t) {
+                                       .data = st,
+                                       .free_func = apache_free,
+                               });
+
        }
 
        if (status != 0)
index ab0237e14df982a1f621e286014cacb70b14d340..582443186876a1d0b6a518532c47fc441972a699 100644 (file)
@@ -769,14 +769,12 @@ static int cj_config_add_url (oconfig_item_t *ci) /* {{{ */
     cb_name = ssnprintf_alloc ("curl_json-%s-%s",
                db->instance, db->url ? db->url : db->sock);
 
-    user_data_t ud = {
-      .data = db,
-      .free_func = cj_free
-    };
-
     plugin_register_complex_read (/* group = */ NULL, cb_name, cj_read,
                                   /* interval = */ db->interval,
-                                  &ud);
+                                  &(user_data_t) {
+                                    .data = db,
+                                    .free_func = cj_free,
+                                  });
     sfree (cb_name);
   }
   else
index c8a1313cbec48769c882ab5cb034faae3da1cc07..924665c72af1b2e792b9a8f317372713f79b1b83 100644 (file)
@@ -1026,13 +1026,12 @@ static int cx_config_add_url (oconfig_item_t *ci) /* {{{ */
 
     cb_name = ssnprintf_alloc ("curl_xml-%s-%s", db->instance, db->url);
 
-    user_data_t ud = {
-      .data = db,
-      .free_func = cx_free
-    };
-
     plugin_register_complex_read (/* group = */ "curl_xml", cb_name, cx_read,
-                                  /* interval = */ 0, &ud);
+        /* interval = */ 0,
+        &(user_data_t) {
+          .data = db,
+          .free_func = cx_free,
+        });
     sfree (cb_name);
   }
   else
index 19d4b0a6c089c3d9b0ad48445ff27a16718acb07..84aa74740f7d566e5742ea6f23ab13c07880ffdc 100644 (file)
--- a/src/dbi.c
+++ b/src/dbi.c
@@ -390,24 +390,19 @@ static int cdbi_config_add_database (oconfig_item_t *ci) /* {{{ */
     }
     else
     {
-      char *name = NULL;
-
       databases = temp;
       databases[databases_num] = db;
       databases_num++;
 
-      name = ssnprintf_alloc("dbi:%s", db->name);
-
-      user_data_t ud = {
-        .data = db
-      };
-
+      char *name = ssnprintf_alloc("dbi:%s", db->name);
       plugin_register_complex_read (/* group = */ NULL,
           /* name = */ name ? name : db->name,
           /* callback = */ cdbi_read_database,
           /* interval = */ (db->interval > 0) ? db->interval : 0,
-          /* user_data = */ &ud);
-      free (name);
+          /* user_data = */ &(user_data_t) {
+            .data = db,
+         });
+      sfree (name);
     }
   }
 
index 67740ac8dae78c6da33a4d47891c9824fa04096a..cd173c5890ae122dbe6db94dda4dead5699a1152 100644 (file)
@@ -1425,13 +1425,11 @@ static jint JNICALL cjni_api_register_read (JNIEnv *jvm_env, /* {{{ */
 
   DEBUG ("java plugin: Registering new read callback: %s", cbi->name);
 
-  user_data_t ud = {
-    .data = cbi,
-    .free_func = cjni_callback_info_destroy
-  };
-
   plugin_register_complex_read (/* group = */ NULL, cbi->name, cjni_read,
-      /* interval = */ 0, &ud);
+      /* interval = */ 0, &(user_data_t) {
+        .data = cbi,
+        .free_func = cjni_callback_info_destroy,
+      });
 
   (*jvm_env)->DeleteLocalRef (jvm_env, o_read);
 
@@ -1449,12 +1447,10 @@ static jint JNICALL cjni_api_register_write (JNIEnv *jvm_env, /* {{{ */
 
   DEBUG ("java plugin: Registering new write callback: %s", cbi->name);
 
-  user_data_t ud = {
-    .data = cbi,
-    .free_func = cjni_callback_info_destroy
-  };
-
-  plugin_register_write (cbi->name, cjni_write, &ud);
+  plugin_register_write (cbi->name, cjni_write, &(user_data_t) {
+        .data = cbi,
+        .free_func = cjni_callback_info_destroy,
+      });
 
   (*jvm_env)->DeleteLocalRef (jvm_env, o_write);
 
@@ -1472,12 +1468,10 @@ static jint JNICALL cjni_api_register_flush (JNIEnv *jvm_env, /* {{{ */
 
   DEBUG ("java plugin: Registering new flush callback: %s", cbi->name);
 
-  user_data_t ud = {
-    .data = cbi,
-    .free_func = cjni_callback_info_destroy
-  };
-
-  plugin_register_flush (cbi->name, cjni_flush, &ud);
+  plugin_register_flush (cbi->name, cjni_flush, &(user_data_t) {
+        .data = cbi,
+        .free_func = cjni_callback_info_destroy,
+      });
 
   (*jvm_env)->DeleteLocalRef (jvm_env, o_flush);
 
@@ -1502,12 +1496,10 @@ static jint JNICALL cjni_api_register_log (JNIEnv *jvm_env, /* {{{ */
 
   DEBUG ("java plugin: Registering new log callback: %s", cbi->name);
 
-  user_data_t ud = {
-    .data = cbi,
-    .free_func = cjni_callback_info_destroy
-  };
-
-  plugin_register_log (cbi->name, cjni_log, &ud);
+  plugin_register_log (cbi->name, cjni_log, &(user_data_t) {
+        .data = cbi,
+        .free_func = cjni_callback_info_destroy,
+      });
 
   (*jvm_env)->DeleteLocalRef (jvm_env, o_log);
 
@@ -1526,12 +1518,10 @@ static jint JNICALL cjni_api_register_notification (JNIEnv *jvm_env, /* {{{ */
 
   DEBUG ("java plugin: Registering new notification callback: %s", cbi->name);
 
-  user_data_t ud = {
-    .data = cbi,
-    .free_func = cjni_callback_info_destroy
-  };
-
-  plugin_register_notification (cbi->name, cjni_notification, &ud);
+  plugin_register_notification (cbi->name, cjni_notification, &(user_data_t) {
+        .data = cbi,
+        .free_func = cjni_callback_info_destroy,
+      });
 
   (*jvm_env)->DeleteLocalRef (jvm_env, o_notification);
 
index ba5fbceac593a53ed33977fbf87e650284c883b0..cf6dadcc28729c82caaa9eaf3f3ae52ad9952e81 100644 (file)
--- a/src/lua.c
+++ b/src/lua.c
@@ -303,15 +303,13 @@ static int lua_cb_register_read(lua_State *L) /* {{{ */
   cb->lua_function_name = strdup(function_name);
   pthread_mutex_init(&cb->lock, NULL);
 
-  user_data_t ud = {
-    .data = cb
-  };
-
   int status = plugin_register_complex_read(/* group = */ "lua",
                                             /* name      = */ function_name,
                                             /* callback  = */ clua_read,
                                             /* interval  = */ 0,
-                                            /* user_data = */ &ud);
+                                            /* user_data = */ &(user_data_t) {
+                                              .data = cb,
+                                            });
 
   if (status != 0)
     return luaL_error(L, "%s", "plugin_register_complex_read failed");
@@ -349,13 +347,11 @@ static int lua_cb_register_write(lua_State *L) /* {{{ */
   cb->lua_function_name = strdup(function_name);
   pthread_mutex_init(&cb->lock, NULL);
 
-  user_data_t ud = {
-    .data = cb
-  };
-
   int status = plugin_register_write(/* name = */ function_name,
                                     /* callback  = */ clua_write,
-                                    /* user_data = */ &ud);
+                                    /* user_data = */ &(user_data_t) {
+                                      .data = cb,
+                                    });
 
   if (status != 0)
     return luaL_error(L, "%s", "plugin_register_write failed");
index 9e6e725293d152561bd3287427f3e90dffb217f5..2cd3a50a28c31becc2e7f11eb00f07cad5a18c40 100644 (file)
@@ -554,16 +554,15 @@ static int memcached_add_read_callback (memcached_t *st)
   assert (st->name != NULL);
   ssnprintf (callback_name, sizeof (callback_name), "memcached/%s", st->name);
 
-  user_data_t ud = {
-    .data = st,
-    .free_func = memcached_free
-  };
-
   status = plugin_register_complex_read (/* group = */ "memcached",
       /* name      = */ callback_name,
       /* callback  = */ memcached_read,
       /* interval  = */ 0,
-      /* user_data = */ &ud);
+      /* user_data = */ &(user_data_t) {
+        .data = st,
+        .free_func = memcached_free,
+      });
+
   return (status);
 } /* int memcached_add_read_callback */
 
index 82213d2c6b62ed21c11e035ad7f79a77c935b6e3..a7d1b582c76fb27a3007aaad27a83abc60bd0616 100644 (file)
@@ -1003,18 +1003,17 @@ static int mb_config_add_host (oconfig_item_t *ci) /* {{{ */
 
   if (status == 0)
   {
-    user_data_t ud;
     char name[1024];
 
-    ud.data = host;
-    ud.free_func = host_free;
-
     ssnprintf (name, sizeof (name), "modbus-%s", host->host);
 
     plugin_register_complex_read (/* group = */ NULL, name,
         /* callback = */ mb_read,
         /* interval = */ host->interval,
-        &ud);
+        &(user_data_t) {
+          .data = host,
+          .free_func = host_free,
+        });
   }
   else
   {
index ad889953a1127a561234af42463fc040cba2bf7c..c08fd29ed2842cde90572f6dac5cbed817e3ba83 100644 (file)
@@ -631,11 +631,9 @@ static int mqtt_config_publisher (oconfig_item_t *ci)
     }
 
     ssnprintf (cb_name, sizeof (cb_name), "mqtt/%s", conf->name);
-    user_data_t user_data = {
-        .data = conf
-    };
-
-    plugin_register_write (cb_name, mqtt_write, &user_data);
+    plugin_register_write (cb_name, mqtt_write, &(user_data_t) {
+                .data = conf,
+            });
     return (0);
 } /* mqtt_config_publisher */
 
index 32b72e286a0b0d08a4f8202ad17ac8296601504a..3bd8cb98159cf853d2e815a442c0de4575844d93 100644 (file)
@@ -233,14 +233,11 @@ static int mysql_config_database (oconfig_item_t *ci) /* {{{ */
                else
                        sstrncpy (cb_name, "mysql", sizeof (cb_name));
 
-               user_data_t ud = {
-                       .data = db,
-                       .free_func = mysql_database_free
-               };
-
                plugin_register_complex_read (/* group = */ NULL, cb_name,
-                                             mysql_read,
-                                             /* interval = */ 0, &ud);
+                               mysql_read, /* interval = */ 0, &(user_data_t) {
+                                       .data = db,
+                                       .free_func = mysql_database_free,
+                               });
        }
        else
        {
index d73969646f7ca9be74c966fcd3da03d2754cc0a0..1c9b21ce1644b80745b257284e8bbd34111f6300 100644 (file)
@@ -2879,15 +2879,13 @@ static int cna_register_host (host_config_t *host) /* {{{ */
        else
                ssnprintf (cb_name, sizeof (cb_name), "netapp-%s", host->name);
 
-       user_data_t ud = {
-               .data = host,
-               .free_func = (void (*) (void *)) free_host_config
-       };
-
        plugin_register_complex_read (/* group = */ NULL, cb_name,
                        /* callback  = */ cna_read,
                        /* interval  = */ host->interval,
-                       /* user data = */ &ud);
+                       /* user data = */ &(user_data_t) {
+                               .data = host,
+                               .free_func = (void *) free_host_config,
+                       });
 
        return (0);
 } /* }}} int cna_register_host */
index d424cb457557fe563ebc4cf997604d42a19ada53..374181dfb2980592449536c8b381847df10e5085 100644 (file)
@@ -663,15 +663,13 @@ static int cldap_config_add (oconfig_item_t *ci) /* {{{ */
                                        (st->host != NULL) ? st->host : hostname_g,
                                        (st->name != NULL) ? st->name : "default");
 
-                       user_data_t ud = {
-                               .data = st
-                       };
-
                        status = plugin_register_complex_read (/* group = */ NULL,
                                        /* name      = */ callback_name,
                                        /* callback  = */ cldap_read_host,
                                        /* interval  = */ 0,
-                                       /* user_data = */ &ud);
+                                       /* user_data = */ &(user_data_t) {
+                                               .data = st,
+                                       });
                }
        }
 
index ec2317b3721d00149e68fdc1567f59340da2cf99..5274262bbd6b5826ca40b8ec6940a20a7ea297cb 100644 (file)
@@ -665,12 +665,11 @@ static PyObject *cpy_register_generic_userdata(void *reg, void *handler, PyObjec
        c->data = data;
        c->next = NULL;
 
-       user_data_t user_data = {
-               .data = c,
-               .free_func = cpy_destroy_user_data
-       };
+       register_function(buf, handler, &(user_data_t) {
+                               .data = c,
+                               .free_func = cpy_destroy_user_data,
+                       });
 
-       register_function(buf, handler, &user_data);
        ++cpy_num_callbacks;
        return cpy_string_to_unicode_or_bytes(buf);
 }
@@ -704,13 +703,12 @@ static PyObject *cpy_register_read(PyObject *self, PyObject *args, PyObject *kwd
        c->data = data;
        c->next = NULL;
 
-       user_data_t user_data = {
-               .data = c,
-               .free_func = cpy_destroy_user_data
-       };
-
        plugin_register_complex_read(/* group = */ "python", buf,
-                       cpy_read_callback, DOUBLE_TO_CDTIME_T (interval), &user_data);
+                       cpy_read_callback, DOUBLE_TO_CDTIME_T (interval),
+                       &(user_data_t) {
+                               .data = c,
+                               .free_func = cpy_destroy_user_data,
+                       });
        ++cpy_num_callbacks;
        return cpy_string_to_unicode_or_bytes(buf);
 }
index a270f484981dbde8a9e1ac2681a8205c445049ba..5fc14db5dd0b9fc0a928bbad340660318ee84809 100644 (file)
@@ -325,7 +325,6 @@ static int cr_config_router (oconfig_item_t *ci) /* {{{ */
 {
   cr_data_t *router_data;
   char read_name[128];
-  user_data_t user_data;
   int status;
 
   router_data = calloc (1, sizeof (*router_data));
@@ -409,11 +408,12 @@ static int cr_config_router (oconfig_item_t *ci) /* {{{ */
   }
 
   ssnprintf (read_name, sizeof (read_name), "routeros/%s", router_data->node);
-  user_data.data = router_data;
-  user_data.free_func = (void *) cr_free_data;
   if (status == 0)
     status = plugin_register_complex_read (/* group = */ NULL, read_name,
-       cr_read, /* interval = */ 0, &user_data);
+        cr_read, /* interval = */ 0, &(user_data_t) {
+          .data = router_data,
+          .free_func = (void *) cr_free_data,
+        });
 
   if (status != 0)
     cr_free_data (router_data);
index abeda436795427f9597e281c30ce1e8ae656b519..d80ee9222615b6ff3a824376252d3ef65f352284 100644 (file)
@@ -764,13 +764,11 @@ static int csnmp_config_add_host (oconfig_item_t *ci)
 
   ssnprintf (cb_name, sizeof (cb_name), "snmp-%s", hd->name);
 
-  user_data_t ud = {
-    .data = hd,
-    .free_func = csnmp_host_definition_destroy
-  };
-
   status = plugin_register_complex_read (/* group = */ NULL, cb_name,
-      csnmp_read_host, hd->interval, /* user_data = */ &ud);
+      csnmp_read_host, hd->interval, &(user_data_t) {
+        .data = hd,
+        .free_func = csnmp_host_definition_destroy,
+      });
   if (status != 0)
   {
     ERROR ("snmp plugin: Registering complex read function failed.");
index e8cde1edcd21a3cf27a1e9a8dea4ba9f7588e728..74fdf84aa35233110bed7a2315d677cb4830fbf3 100644 (file)
@@ -339,11 +339,10 @@ static int ctail_init (void)
   {
     ssnprintf(str, sizeof(str), "tail-%zu", i);
 
-    user_data_t ud = {
-     .data = tail_match_list[i]
-    };
-
-    plugin_register_complex_read (NULL, str, ctail_read, tail_match_list_intervals[i], &ud);
+    plugin_register_complex_read (NULL, str, ctail_read, tail_match_list_intervals[i],
+        &(user_data_t) {
+          .data = tail_match_list[i],
+        });
   }
 
   return (0);
index 1bdf8b29de65dc4317b9714613ea337028d06408..faeb56f8eeb71c7e9a9de03cd98775248b1a7b29 100644 (file)
@@ -482,13 +482,11 @@ static int tcsv_config_add_file(oconfig_item_t *ci)
 
     ssnprintf (cb_name, sizeof (cb_name), "tail_csv/%s", id->path);
 
-    user_data_t ud = {
-        .data = id,
-        .free_func = tcsv_instance_definition_destroy
-    };
-
-    status = plugin_register_complex_read(NULL, cb_name, tcsv_read, id->interval, &ud);
-
+    status = plugin_register_complex_read(NULL, cb_name, tcsv_read, id->interval,
+            &(user_data_t) {
+                .data = id,
+                .free_func = tcsv_instance_definition_destroy,
+            });
     if (status != 0){
         ERROR("tail_csv plugin: Registering complex read function failed.");
         tcsv_instance_definition_destroy(id);
index 6cc092c0041eac9fcb028e179610f1c4cf40606e..91320fed8a8ecab93a64ab5fe0620111deea598b 100644 (file)
@@ -951,16 +951,14 @@ static int varnish_init (void) /* {{{ */
 
        varnish_config_apply_default (conf);
 
-       user_data_t ud = {
-               .data = conf,
-               .free_func = varnish_config_free
-       };
-
        plugin_register_complex_read (/* group = */ "varnish",
                        /* name      = */ "varnish/localhost",
                        /* callback  = */ varnish_read,
                        /* interval  = */ 0,
-                       /* user data = */ &ud);
+                       /* user data = */ &(user_data_t) {
+                               .data = conf,
+                               .free_func = varnish_config_free,
+                       });
 
        return (0);
 } /* }}} int varnish_init */
@@ -968,7 +966,6 @@ static int varnish_init (void) /* {{{ */
 static int varnish_config_instance (const oconfig_item_t *ci) /* {{{ */
 {
        user_config_t *conf;
-       user_data_t ud;
        char callback_name[DATA_MAX_NAME_LEN];
 
        conf = calloc (1, sizeof (*conf));
@@ -1132,14 +1129,14 @@ static int varnish_config_instance (const oconfig_item_t *ci) /* {{{ */
        ssnprintf (callback_name, sizeof (callback_name), "varnish/%s",
                        (conf->instance == NULL) ? "localhost" : conf->instance);
 
-       ud.data = conf;
-       ud.free_func = varnish_config_free;
-
        plugin_register_complex_read (/* group = */ "varnish",
                        /* name      = */ callback_name,
                        /* callback  = */ varnish_read,
                        /* interval  = */ 0,
-                       /* user data = */ &ud);
+                       /* user data = */ &(user_data_t) {
+                               ud.data = conf,
+                               ud.free_func = varnish_config_free,
+                       });
 
        have_instance = 1;
 
index fe2376ad7382f0d2ae14f39ef6500c26e49ec8df..845ba898b2dff38362116d841bd06452c473301c 100644 (file)
@@ -575,15 +575,13 @@ static int wg_config_node (oconfig_item_t *ci)
         ssnprintf (callback_name, sizeof (callback_name), "write_graphite/%s",
                 cb->name);
 
-    user_data_t ud = {
-        .data = cb,
-        .free_func = wg_callback_free
-    };
-
-    plugin_register_write (callback_name, wg_write, &ud);
+    plugin_register_write (callback_name, wg_write,
+            &(user_data_t) {
+                .data = cb,
+                .free_func = wg_callback_free,
+            });
 
-    ud.free_func = NULL;
-    plugin_register_flush (callback_name, wg_flush, &ud);
+    plugin_register_flush (callback_name, wg_flush, &(user_data_t) { .data = cb });
 
     return (0);
 }
index 9fda2dfc13a416989afeb1de71b2ad6dcb84a99d..75da6aaafefdc6d2bacb3de0c1fae5bdc0eb0ef0 100644 (file)
@@ -383,12 +383,11 @@ static void kafka_config_topic(rd_kafka_conf_t *conf, oconfig_item_t *ci) /* {{{
     ssnprintf(callback_name, sizeof(callback_name),
               "write_kafka/%s", tctx->topic_name);
 
-    user_data_t ud = {
-        .data = tctx,
-        .free_func = kafka_topic_context_free
-    };
-
-    status = plugin_register_write (callback_name, kafka_write, &ud);
+    status = plugin_register_write (callback_name, kafka_write,
+            &(user_data_t) {
+                .data = tctx,
+                .free_func = kafka_topic_context_free,
+            });
     if (status != 0) {
         WARNING ("write_kafka plugin: plugin_register_write (\"%s\") "
                 "failed with status %i.",
index 6d5f37943ea330c369fc6f871777aa8f7887e6e3..796574e749538701364d6e3e2b55420f578c91f6 100644 (file)
@@ -339,12 +339,11 @@ static int wm_config_node (oconfig_item_t *ci) /* {{{ */
 
     ssnprintf (cb_name, sizeof (cb_name), "write_mongodb/%s", node->name);
 
-    user_data_t ud = {
-      .data = node,
-      .free_func = wm_config_free
-    };
-
-    status = plugin_register_write (cb_name, wm_write, &ud);
+    status = plugin_register_write (cb_name, wm_write,
+                   &(user_data_t) {
+                           .data = node,
+                           .free_func = wm_config_free,
+                   });
     INFO ("write_mongodb plugin: registered write plugin %s %d",cb_name,status);
   }
 
index 472241623dd51b02890c9f9324dae3a9a6ec9b56..def3d9cdbcd0702265cc7137b3d50114a4b058bd 100644 (file)
@@ -234,12 +234,11 @@ static int wr_config_node (oconfig_item_t *ci) /* {{{ */
 
     ssnprintf (cb_name, sizeof (cb_name), "write_redis/%s", node->name);
 
-    user_data_t ud = {
-      .data = node,
-      .free_func = wr_config_free
-    };
-
-    status = plugin_register_write (cb_name, wr_write, &ud);
+    status = plugin_register_write (cb_name, wr_write,
+        &(user_data_t) {
+          .data = node,
+          .free_func = wr_config_free,
+        });
   }
 
   if (status != 0)