Code

Make g_strings in perl.c not global so that hostname_g as a char* doesn't break it.x
authorSean Campbell <campbellsean@campbellsean-cloudtop.c.googlers.com>
Wed, 11 Oct 2017 21:50:56 +0000 (17:50 -0400)
committerSean Campbell <campbellsean@campbellsean-cloudtop.c.googlers.com>
Wed, 11 Oct 2017 21:50:56 +0000 (17:50 -0400)
src/daemon/globals.c
src/perl.c

index 2222a5ce8b9e8f53e69319324219c3a35fa3212d..9b0aec739997c1af2419a021b87df8e57e311615 100644 (file)
 #include <kstat.h>
 #endif
 
-void hostname_set(char const *hostname) {
-  char *h = strdup(hostname);
-  if (h == NULL)
-    return;
-
-  free(hostname_g);
-  hostname_g = h;
-}
-
 /*
  * Global variables
  */
@@ -47,3 +38,12 @@ int  timeout_g;
 kstat_ctl_t *kc;
 #endif
 
+void hostname_set(char const *hostname) {
+    char *h = strdup(hostname);
+      if (h == NULL)
+            return;
+
+        free(hostname_g);
+          hostname_g = h;
+}
+
index d2a00bfde5ec316e2482bbf7deb1148a7a13dac2..9268086fd8e82c11848e7ad009b8bc8b8ce8a27c 100644 (file)
@@ -261,12 +261,6 @@ struct {
                  {"Collectd::NOTIF_WARNING", NOTIF_WARNING},
                  {"Collectd::NOTIF_OKAY", NOTIF_OKAY},
                  {"", 0}};
-
-struct {
-  char name[64];
-  char *var;
-} g_strings[] = {{"Collectd::hostname_g", hostname_g}, {"", NULL}};
-
 /*
  * Helper functions for data type conversion.
  */
@@ -2390,6 +2384,11 @@ static void xs_init(pTHX) {
    * accessing any such variable (this is basically the same as using
    * tie() in Perl) */
   /* global strings */
+  struct {
+      char name[64];
+      char *var;
+  } g_strings[] = {{"Collectd::hostname_g", hostname_g}, {"", NULL}};
+
   for (int i = 0; '\0' != g_strings[i].name[0]; ++i) {
     tmp = get_sv(g_strings[i].name, 1);
     sv_magicext(tmp, NULL, PERL_MAGIC_ext, &g_pv_vtbl, g_strings[i].var, 0);