**/
#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;
+ user_data_t ud = { 0 };
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;
static jint JNICALL cjni_api_register_write (JNIEnv *jvm_env, /* {{{ */
jobject this, jobject o_name, jobject o_write)
{
- user_data_t ud;
+ user_data_t ud = { 0 };
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;
static jint JNICALL cjni_api_register_flush (JNIEnv *jvm_env, /* {{{ */
jobject this, jobject o_name, jobject o_flush)
{
- user_data_t ud;
+ user_data_t ud = { 0 };
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;
static jint JNICALL cjni_api_register_log (JNIEnv *jvm_env, /* {{{ */
jobject this, jobject o_name, jobject o_log)
{
- user_data_t ud;
+ user_data_t ud = { 0 };
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;
static jint JNICALL cjni_api_register_notification (JNIEnv *jvm_env, /* {{{ */
jobject this, jobject o_name, jobject o_notification)
{
- user_data_t ud;
+ user_data_t ud = { 0 };
cjni_callback_info_t *cbi;
cbi = cjni_callback_info_create (jvm_env, o_name, o_notification,
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;
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;
}
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;
return (NULL);
}
- cbi = (cjni_callback_info_t *) malloc (sizeof (*cbi));
+ cbi = calloc (1, sizeof (*cbi));
if (cbi == NULL)
{
- ERROR ("java plugin: cjni_callback_info_create: malloc failed.");
+ ERROR ("java plugin: cjni_callback_info_create: calloc failed.");
(*jvm_env)->ReleaseStringUTFChars (jvm_env, o_name, c_name);
return (NULL);
}
- memset (cbi, 0, sizeof (*cbi));
cbi->type = type;
cbi->name = strdup (c_name);
pthread_mutex_lock (&java_callbacks_lock);
- tmp = (cjni_callback_info_t *) realloc (java_callbacks,
+ tmp = realloc (java_callbacks,
(java_callbacks_num + 1) * sizeof (*java_callbacks));
if (tmp == NULL)
{
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]);
if (cjni_env == NULL)
{
/* This pointer is free'd in `cjni_jvm_env_destroy'. */
- cjni_env = (cjni_jvm_env_t *) malloc (sizeof (*cjni_env));
+ cjni_env = calloc (1, sizeof (*cjni_env));
if (cjni_env == NULL)
{
- ERROR ("java plugin: cjni_thread_attach: malloc failed.");
+ ERROR ("java plugin: cjni_thread_attach: calloc failed.");
return (NULL);
}
- memset (cjni_env, 0, sizeof (*cjni_env));
cjni_env->reference_counter = 0;
cjni_env->jvm_env = NULL;
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);
return (-1);
}
- tmp = (char **) realloc (jvm_argv, sizeof (char *) * (jvm_argc + 1));
+ tmp = realloc (jvm_argv, sizeof (char *) * (jvm_argc + 1));
if (tmp == NULL)
{
ERROR ("java plugin: realloc failed.");
if (jvm_env == NULL)
return (-1);
- class = (java_plugin_class_t *) realloc (java_classes_list,
+ class = realloc (java_classes_list,
(java_classes_list_len + 1) * sizeof (*java_classes_list));
if (class == NULL)
{
{ /* 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;
/* Allocate a new callback info structure. This is going to be our user_data
* pointer. */
- cbi_ret = (cjni_callback_info_t *) malloc (sizeof (*cbi_ret));
+ cbi_ret = calloc (1, sizeof (*cbi_ret));
if (cbi_ret == NULL)
{
- ERROR ("java plugin: cjni_match_target_create: malloc failed.");
+ ERROR ("java plugin: cjni_match_target_create: calloc failed.");
BAIL_OUT (-1);
}
- memset (cbi_ret, 0, sizeof (*cbi_ret));
+
cbi_ret->object = NULL;
cbi_ret->type = type;
* `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);