From: Sebastian Harl Date: Thu, 27 Aug 2009 21:24:44 +0000 (+0200) Subject: patches: Added java-fix-jvm-start.dpatch. X-Git-Tag: collectd-4.7.2-1~12 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=82eb5980cffaafa03917712b8c8229d3392a25e5;p=pkg-collectd.git patches: Added java-fix-jvm-start.dpatch. This is an upstream patch to fix the JVM startup. --- diff --git a/debian/changelog b/debian/changelog index c00c56e..c7add8d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -42,6 +42,7 @@ collectd (4.7.2-1) unstable; urgency=low - Added plugin-fix-unregister.dpatch - upstream patch to make 'plugin_unregister_read()' functional again, thus fixing a failed assertion in some cases. + - Added java-fix-jvm-start.dpatch - upstream patch to fix the JVM startup. * debian/README.Debian: - Removed the note about how to get collectd2html.pl working with version 4 of collectd - the script now supports the --recursive option @@ -59,7 +60,7 @@ collectd (4.7.2-1) unstable; urgency=low - Set the 'apache' plugin's URL according to the default used by Debian's Apache; thanks to Joey Hess for reporting this (Closes: #541888). - -- Sebastian Harl Thu, 27 Aug 2009 23:11:09 +0200 + -- Sebastian Harl Thu, 27 Aug 2009 23:23:16 +0200 collectd (4.6.3-1) unstable; urgency=low diff --git a/debian/patches/00list b/debian/patches/00list index 680577a..7297c98 100644 --- a/debian/patches/00list +++ b/debian/patches/00list @@ -3,4 +3,5 @@ collection_conf_path.dpatch network-fix-cacheflush.dpatch libvirt-reconnect.dpatch plugin-fix-unregister.dpatch +java-fix-jvm-start.dpatch diff --git a/debian/patches/java-fix-jvm-start.dpatch b/debian/patches/java-fix-jvm-start.dpatch new file mode 100755 index 0000000..b21629d --- /dev/null +++ b/debian/patches/java-fix-jvm-start.dpatch @@ -0,0 +1,127 @@ +#! /bin/sh /usr/share/dpatch/dpatch-run +## java-fix-jvm-start.dpatch by Florian Forster +## +## DP: java plugin: Wait with the configuration until the daemon has forked. +## DP +## DP: Passing the configuration to Java-based plugins requires the JVM to be +## DP: active and running. However, the JVM starts some threads that are lost +## DP: when the daemon forks to the background. +## DP: +## DP: This patch changes the behavior of the Java plugin to copy the +## DP: configuration blocks found to a local variable and run the configuration +## DP: of the Java-based plugins from the `init' callback, because it is +## DP: invoked after the daemon has forked to the background. + +@DPATCH@ + +diff a/src/java.c b/src/java.c +--- a/src/java.c ++++ b/src/java.c +@@ -93,6 +93,8 @@ static cjni_callback_info_t *java_callbacks = NULL; + static size_t java_callbacks_num = 0; + static pthread_mutex_t java_callbacks_lock = PTHREAD_MUTEX_INITIALIZER; + ++static oconfig_item_t *config_block = NULL; ++ + /* + * Prototypes + * +@@ -2304,7 +2306,7 @@ static int cjni_config_plugin_block (oconfig_item_t *ci) /* {{{ */ + return (0); + } /* }}} int cjni_config_plugin_block */ + +-static int cjni_config (oconfig_item_t *ci) /* {{{ */ ++static int cjni_config_perform (oconfig_item_t *ci) /* {{{ */ + { + int success; + int errors; +@@ -2359,7 +2361,56 @@ static int cjni_config (oconfig_item_t *ci) /* {{{ */ + } + + return (0); +-} /* }}} int cjni_config */ ++} /* }}} int cjni_config_perform */ ++ ++/* Copy the children of `ci' to the global `config_block' variable. */ ++static int cjni_config_callback (oconfig_item_t *ci) /* {{{ */ ++{ ++ oconfig_item_t *ci_copy; ++ oconfig_item_t *tmp; ++ ++ assert (ci != NULL); ++ if (ci->children_num == 0) ++ return (0); /* nothing to do */ ++ ++ ci_copy = oconfig_clone (ci); ++ if (ci_copy == NULL) ++ { ++ ERROR ("java plugin: oconfig_clone failed."); ++ return (-1); ++ } ++ ++ if (config_block == NULL) ++ { ++ config_block = ci_copy; ++ return (0); ++ } ++ ++ tmp = realloc (config_block->children, ++ (config_block->children_num + ci_copy->children_num) * sizeof (*tmp)); ++ if (tmp == NULL) ++ { ++ ERROR ("java plugin: realloc failed."); ++ oconfig_free (ci_copy); ++ return (-1); ++ } ++ config_block->children = tmp; ++ ++ /* Copy the pointers */ ++ memcpy (config_block->children + config_block->children_num, ++ ci_copy->children, ++ ci_copy->children_num * sizeof (*ci_copy->children)); ++ config_block->children_num += ci_copy->children_num; ++ ++ /* Delete the pointers from the copy, so `oconfig_free' can't free them. */ ++ memset (ci_copy->children, 0, ++ ci_copy->children_num * sizeof (*ci_copy->children)); ++ ci_copy->children_num = 0; ++ ++ oconfig_free (ci_copy); ++ ++ return (0); ++} /* }}} int cjni_config_callback */ + + /* Free the data contained in the `user_data_t' pointer passed to `cjni_read' + * and `cjni_write'. In particular, delete the global reference to the Java +@@ -2995,6 +3046,22 @@ static int cjni_init (void) /* {{{ */ + { + JNIEnv *jvm_env; + ++ if ((config_block == NULL) && (jvm == NULL)) ++ { ++ ERROR ("java plugin: cjni_init: No configuration block for " ++ "the java plugin was found."); ++ return (-1); ++ } ++ ++ if (config_block != NULL) ++ { ++ int status; ++ ++ status = cjni_config_perform (config_block); ++ oconfig_free (config_block); ++ config_block = NULL; ++ } ++ + if (jvm == NULL) + { + ERROR ("java plugin: cjni_init: jvm == NULL"); +@@ -3013,7 +3080,7 @@ static int cjni_init (void) /* {{{ */ + + void module_register (void) + { +- plugin_register_complex_config ("java", cjni_config); ++ plugin_register_complex_config ("java", cjni_config_callback); + plugin_register_init ("java", cjni_init); + plugin_register_shutdown ("java", cjni_shutdown); + } /* void module_register (void) */