diff --git a/src/java.c b/src/java.c
index 4187e7c382d03c3658238e0b7aa65a34cd231bd1..67740ac8dae78c6da33a4d47891c9824fa04096a 100644 (file)
--- a/src/java.c
+++ b/src/java.c
**/
#include "collectd.h"
+
#include "plugin.h"
#include "common.h"
#include "filter_chain.h"
-#include <pthread.h>
#include <jni.h>
#if !defined(JNI_VERSION_1_2)
jmethodID m_addchild;
jobject o_key;
jobject o_ocitem;
- int i;
c_ocitem = (*jvm_env)->FindClass (jvm_env, "org/collectd/api/OConfigItem");
if (c_ocitem == NULL)
(*jvm_env)->DeleteLocalRef (jvm_env, o_key);
/* Call OConfigItem.addValue for each value */
- for (i = 0; i < ci->values_num; i++) /* {{{ */
+ for (int i = 0; i < ci->values_num; i++) /* {{{ */
{
jobject o_value;
} /* }}} for (i = 0; i < ci->values_num; i++) */
/* Call OConfigItem.addChild for each child */
- for (i = 0; i < ci->children_num; i++) /* {{{ */
+ for (int i = 0; i < ci->children_num; i++) /* {{{ */
{
jobject o_child;
jmethodID m_add;
jobject o_type;
jobject o_dataset;
- size_t i;
/* Look up the org/collectd/api/DataSet class */
c_dataset = (*jvm_env)->FindClass (jvm_env, "org/collectd/api/DataSet");
/* Decrease reference counter on the java.lang.String object. */
(*jvm_env)->DeleteLocalRef (jvm_env, o_type);
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
{
jobject o_datasource;
jmethodID m_valuelist_constructor;
jobject o_valuelist;
int status;
- size_t i;
/* First, create a new ValueList instance..
* Look up the class.. */
return (NULL);
}
- for (i = 0; i < vl->values_len; i++)
+ for (size_t i = 0; i < vl->values_len; i++)
{
status = ctoj_value_list_add_value (jvm_env, vl->values[i], ds->ds[i].type,
c_valuelist, o_valuelist);
value_t *values;
int values_num;
- int i;
values_num = ds->ds_num;
BAIL_OUT (-1);
}
- for (i = 0; i < values_num; i++)
+ for (int i = 0; i < values_num; i++)
{
jobject o_number;
int status;
static jint JNICALL cjni_api_dispatch_notification (JNIEnv *jvm_env, /* {{{ */
jobject this, jobject o_notification)
{
- notification_t n;
+ notification_t n = { 0 };
int status;
- memset (&n, 0, sizeof (n));
- n.meta = NULL;
-
status = jtoc_notification (jvm_env, &n, o_notification);
if (status != 0)
{
static jint JNICALL cjni_api_register_read (JNIEnv *jvm_env, /* {{{ */
jobject this, jobject o_name, jobject o_read)
{
- user_data_t ud;
cjni_callback_info_t *cbi;
cbi = cjni_callback_info_create (jvm_env, o_name, o_read, CB_TYPE_READ);
DEBUG ("java plugin: Registering new read callback: %s", cbi->name);
- memset (&ud, 0, sizeof (ud));
- ud.data = (void *) cbi;
- ud.free_func = cjni_callback_info_destroy;
+ 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);
static jint JNICALL cjni_api_register_write (JNIEnv *jvm_env, /* {{{ */
jobject this, jobject o_name, jobject o_write)
{
- user_data_t ud;
cjni_callback_info_t *cbi;
cbi = cjni_callback_info_create (jvm_env, o_name, o_write, CB_TYPE_WRITE);
DEBUG ("java plugin: Registering new write callback: %s", cbi->name);
- memset (&ud, 0, sizeof (ud));
- ud.data = (void *) cbi;
- ud.free_func = cjni_callback_info_destroy;
+ user_data_t ud = {
+ .data = cbi,
+ .free_func = cjni_callback_info_destroy
+ };
plugin_register_write (cbi->name, cjni_write, &ud);
static jint JNICALL cjni_api_register_flush (JNIEnv *jvm_env, /* {{{ */
jobject this, jobject o_name, jobject o_flush)
{
- user_data_t ud;
cjni_callback_info_t *cbi;
cbi = cjni_callback_info_create (jvm_env, o_name, o_flush, CB_TYPE_FLUSH);
DEBUG ("java plugin: Registering new flush callback: %s", cbi->name);
- memset (&ud, 0, sizeof (ud));
- ud.data = (void *) cbi;
- ud.free_func = cjni_callback_info_destroy;
+ user_data_t ud = {
+ .data = cbi,
+ .free_func = cjni_callback_info_destroy
+ };
plugin_register_flush (cbi->name, cjni_flush, &ud);
static jint JNICALL cjni_api_register_log (JNIEnv *jvm_env, /* {{{ */
jobject this, jobject o_name, jobject o_log)
{
- user_data_t ud;
cjni_callback_info_t *cbi;
cbi = cjni_callback_info_create (jvm_env, o_name, o_log, CB_TYPE_LOG);
DEBUG ("java plugin: Registering new log callback: %s", cbi->name);
- memset (&ud, 0, sizeof (ud));
- ud.data = (void *) cbi;
- ud.free_func = cjni_callback_info_destroy;
+ user_data_t ud = {
+ .data = cbi,
+ .free_func = cjni_callback_info_destroy
+ };
plugin_register_log (cbi->name, cjni_log, &ud);
static jint JNICALL cjni_api_register_notification (JNIEnv *jvm_env, /* {{{ */
jobject this, jobject o_name, jobject o_notification)
{
- user_data_t ud;
cjni_callback_info_t *cbi;
cbi = cjni_callback_info_create (jvm_env, o_name, o_notification,
@@ -1534,9 +1526,10 @@ static jint JNICALL cjni_api_register_notification (JNIEnv *jvm_env, /* {{{ */
DEBUG ("java plugin: Registering new notification callback: %s", cbi->name);
- memset (&ud, 0, sizeof (ud));
- ud.data = (void *) cbi;
- ud.free_func = cjni_callback_info_destroy;
+ user_data_t ud = {
+ .data = cbi,
+ .free_func = cjni_callback_info_destroy
+ };
plugin_register_notification (cbi->name, cjni_notification, &ud);
@@ -1568,9 +1561,8 @@ static jint JNICALL cjni_api_register_match_target (JNIEnv *jvm_env, /* {{{ */
if (type == CB_TYPE_MATCH)
{
- match_proc_t m_proc;
+ match_proc_t m_proc = { 0 };
- memset (&m_proc, 0, sizeof (m_proc));
m_proc.create = cjni_match_target_create;
m_proc.destroy = cjni_match_target_destroy;
m_proc.match = (void *) cjni_match_target_invoke;
@@ -1579,9 +1571,8 @@ static jint JNICALL cjni_api_register_match_target (JNIEnv *jvm_env, /* {{{ */
}
else if (type == CB_TYPE_TARGET)
{
- target_proc_t t_proc;
+ target_proc_t t_proc = { 0 };
- memset (&t_proc, 0, sizeof (t_proc));
t_proc.create = cjni_match_target_create;
t_proc.destroy = cjni_match_target_destroy;
t_proc.invoke = cjni_match_target_invoke;
static int cjni_create_jvm (void) /* {{{ */
{
JNIEnv *jvm_env;
- JavaVMInitArgs vm_args;
+ JavaVMInitArgs vm_args = { 0 };
JavaVMOption vm_options[jvm_argc];
int status;
- size_t i;
if (jvm != NULL)
return (0);
jvm_env = NULL;
- memset (&vm_args, 0, sizeof (vm_args));
vm_args.version = JNI_VERSION_1_2;
vm_args.options = vm_options;
vm_args.nOptions = (jint) jvm_argc;
- for (i = 0; i < jvm_argc; i++)
+ for (size_t i = 0; i < jvm_argc; i++)
{
DEBUG ("java plugin: cjni_create_jvm: jvm_argv[%zu] = %s",
i, jvm_argv[i]);
else
{
int status;
- JavaVMAttachArgs args;
+ JavaVMAttachArgs args = { 0 };
assert (cjni_env->jvm_env == NULL);
- memset (&args, 0, sizeof (args));
args.version = JNI_VERSION_1_2;
status = (*jvm)->AttachCurrentThread (jvm, (void *) &jvm_env, (void *) &args);
{ /* Replace all dots ('.') with slashes ('/'). Dots are usually used
thorough the Java community, but (Sun's) `FindClass' and friends need
slashes. */
- size_t i;
- for (i = 0; class->name[i] != 0; i++)
+ for (size_t i = 0; class->name[i] != 0; i++)
if (class->name[i] == '.')
class->name[i] = '/';
}
cjni_callback_info_t *cbi;
jobject o_ocitem;
const char *name;
- size_t i;
jclass class;
jmethodID method;
name = ci->values[0].value.string;
cbi = NULL;
- for (i = 0; i < java_callbacks_num; i++)
+ for (size_t i = 0; i < java_callbacks_num; i++)
{
if (java_callbacks[i].type != CB_TYPE_CONFIG)
continue;
int success;
int errors;
int status;
- int i;
success = 0;
errors = 0;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
jobject o_ci;
jobject o_tmp;
int type;
- size_t i;
cbi_ret = NULL;
o_ci = NULL;
/* Lets see if we have a matching factory here.. */
cbi_factory = NULL;
- for (i = 0; i < java_callbacks_num; i++)
+ for (size_t i = 0; i < java_callbacks_num; i++)
{
if (java_callbacks[i].type != type)
continue;
* `value_list_t'. */
if (cbi->type == CB_TYPE_TARGET)
{
- value_list_t new_vl;
+ value_list_t new_vl = { 0 };
- memset (&new_vl, 0, sizeof (new_vl));
status = jtoc_value_list (jvm_env, &new_vl, o_vl);
if (status != 0)
{
static int cjni_init_plugins (JNIEnv *jvm_env) /* {{{ */
{
int status;
- size_t i;
- for (i = 0; i < java_callbacks_num; i++)
+ for (size_t i = 0; i < java_callbacks_num; i++)
{
if (java_callbacks[i].type != CB_TYPE_INIT)
continue;
static int cjni_shutdown_plugins (JNIEnv *jvm_env) /* {{{ */
{
int status;
- size_t i;
- for (i = 0; i < java_callbacks_num; i++)
+ for (size_t i = 0; i < java_callbacks_num; i++)
{
if (java_callbacks[i].type != CB_TYPE_SHUTDOWN)
continue;
static int cjni_shutdown (void) /* {{{ */
{
JNIEnv *jvm_env;
- JavaVMAttachArgs args;
+ JavaVMAttachArgs args = { 0 };
int status;
- size_t i;
if (jvm == NULL)
return (0);
jvm_env = NULL;
- memset (&args, 0, sizeof (args));
args.version = JNI_VERSION_1_2;
status = (*jvm)->AttachCurrentThread (jvm, (void *) &jvm_env, &args);
cjni_shutdown_plugins (jvm_env);
/* Release all the global references to callback functions */
- for (i = 0; i < java_callbacks_num; i++)
+ for (size_t i = 0; i < java_callbacks_num; i++)
{
if (java_callbacks[i].object != NULL)
{
sfree (java_callbacks);
/* Release all the global references to directly loaded classes. */
- for (i = 0; i < java_classes_list_len; i++)
+ for (size_t i = 0; i < java_classes_list_len; i++)
{
if (java_classes_list[i].object != NULL)
{
pthread_key_delete (jvm_env_key);
/* Free the JVM argument list */
- for (i = 0; i < jvm_argc; i++)
+ for (size_t i = 0; i < jvm_argc; i++)
sfree (jvm_argv[i]);
jvm_argc = 0;
sfree (jvm_argv);