From: Sean Campbell Date: Wed, 11 Oct 2017 21:50:56 +0000 (-0400) Subject: Make g_strings in perl.c not global so that hostname_g as a char* doesn't break it.x X-Git-Tag: collectd-5.8.0~35^2~4 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=f4e0ca6bb59e633618ff3918fde47018672ea758;p=collectd.git Make g_strings in perl.c not global so that hostname_g as a char* doesn't break it.x --- diff --git a/src/daemon/globals.c b/src/daemon/globals.c index 2222a5ce..9b0aec73 100644 --- a/src/daemon/globals.c +++ b/src/daemon/globals.c @@ -28,15 +28,6 @@ #include #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; +} + diff --git a/src/perl.c b/src/perl.c index d2a00bfd..9268086f 100644 --- a/src/perl.c +++ b/src/perl.c @@ -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);