diff options
Diffstat (limited to '')
-rw-r--r-- | src/plugins.d/plugins_d.c (renamed from src/collectors/plugins.d/plugins_d.c) | 51 |
1 files changed, 38 insertions, 13 deletions
diff --git a/src/collectors/plugins.d/plugins_d.c b/src/plugins.d/plugins_d.c index 85f1563c3..09be1ffc6 100644 --- a/src/collectors/plugins.d/plugins_d.c +++ b/src/plugins.d/plugins_d.c @@ -158,7 +158,7 @@ static void *pluginsd_worker_thread(void *arg) { rrdhost_hostname(cd->host), cd->cmd); break; } - cd->unsafe.pid = spawn_server_instance_pid(cd->unsafe.pi->si); + cd->unsafe.pid = spawn_popen_pid(cd->unsafe.pi); nd_log(NDLS_DAEMON, NDLP_DEBUG, "PLUGINSD: 'host:%s' connected to '%s' running on pid %d", @@ -181,10 +181,13 @@ static void *pluginsd_worker_thread(void *arg) { }; ND_LOG_STACK_PUSH(lgs); - count = pluginsd_process(cd->host, cd, cd->unsafe.pi->child_stdin_fp, cd->unsafe.pi->child_stdout_fp, 0); + count = pluginsd_process(cd->host, cd, + spawn_popen_read_fd(cd->unsafe.pi), + spawn_popen_write_fd(cd->unsafe.pi), + 0); - nd_log(NDLS_DAEMON, NDLP_DEBUG, - "PLUGINSD: 'host:%s', '%s' (pid %d) disconnected after %zu successful data collections (ENDs).", + nd_log(NDLS_COLLECTORS, NDLP_WARNING, + "PLUGINSD: 'host:%s', '%s' (pid %d) disconnected after %zu successful data collections.", rrdhost_hostname(cd->host), cd->fullfilename, cd->unsafe.pid, count); int worker_ret_code = spawn_popen_kill(cd->unsafe.pi); @@ -228,6 +231,33 @@ static void pluginsd_main_cleanup(void *pptr) { worker_unregister(); } +static bool is_plugin(char *dst, size_t dst_size, const char *filename) { + size_t len = strlen(filename); + + const char *suffix; + size_t suffix_len; + + suffix = ".plugin"; + suffix_len = strlen(suffix); + if (len > suffix_len && + strcmp(suffix, &filename[len - suffix_len]) == 0) { + snprintfz(dst, dst_size, "%.*s", (int)(len - suffix_len), filename); + return true; + } + +#if defined(OS_WINDOWS) + suffix = ".plugin.exe"; + suffix_len = strlen(suffix); + if (len > suffix_len && + strcmp(suffix, &filename[len - suffix_len]) == 0) { + snprintfz(dst, dst_size, "%.*s", (int)(len - suffix_len), filename); + return true; + } +#endif + + return false; +} + void *pluginsd_main(void *ptr) { CLEANUP_FUNCTION_REGISTER(pluginsd_main_cleanup) cleanup_ptr = ptr; @@ -276,18 +306,13 @@ void *pluginsd_main(void *ptr) { if (unlikely(strcmp(file->d_name, ".") == 0 || strcmp(file->d_name, "..") == 0)) continue; - int len = (int)strlen(file->d_name); - if (unlikely(len <= (int)PLUGINSD_FILE_SUFFIX_LEN)) - continue; - if (unlikely(strcmp(PLUGINSD_FILE_SUFFIX, &file->d_name[len - (int)PLUGINSD_FILE_SUFFIX_LEN]) != 0)) { - netdata_log_debug(D_PLUGINSD, "file '%s' does not end in '%s'", file->d_name, PLUGINSD_FILE_SUFFIX); + char pluginname[CONFIG_MAX_NAME + 1]; + if(!is_plugin(pluginname, sizeof(pluginname), file->d_name)) { + netdata_log_debug(D_PLUGINSD, "file '%s' does not look like a plugin", file->d_name); continue; } - char pluginname[CONFIG_MAX_NAME + 1]; - snprintfz(pluginname, CONFIG_MAX_NAME, "%.*s", (int)(len - PLUGINSD_FILE_SUFFIX_LEN), file->d_name); int enabled = config_get_boolean(CONFIG_SECTION_PLUGINS, pluginname, automatic_run); - if (unlikely(!enabled)) { netdata_log_debug(D_PLUGINSD, "plugin '%s' is not enabled", file->d_name); continue; @@ -318,7 +343,7 @@ void *pluginsd_main(void *ptr) { cd->unsafe.enabled = enabled; cd->unsafe.running = false; - cd->update_every = (int)config_get_number(cd->id, "update every", localhost->rrd_update_every); + cd->update_every = (int)config_get_duration_seconds(cd->id, "update every", localhost->rrd_update_every); cd->started_t = now_realtime_sec(); char *def = ""; |