[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/2] Refactor module loading for single place of exec* call.
From: |
Boris Dušek |
Subject: |
[PATCH 1/2] Refactor module loading for single place of exec* call. |
Date: |
Sat, 19 Mar 2011 14:21:10 +0100 |
---
src/server/module.c | 37 +++++++++++++++++++++----------------
1 files changed, 21 insertions(+), 16 deletions(-)
diff --git a/src/server/module.c b/src/server/module.c
index 9fe6a6f..74b508d 100644
--- a/src/server/module.c
+++ b/src/server/module.c
@@ -124,8 +124,6 @@ OutputModule *load_output_module(char *mod_name, char
*mod_prog,
{
OutputModule *module;
int fr;
- char *arg1 = NULL;
- int cfg = 0;
int ret;
char *module_conf_dir;
char *rep_line = NULL;
@@ -133,6 +131,8 @@ OutputModule *load_output_module(char *mod_name, char
*mod_prog,
size_t n = 0;
char s;
GString *reply;
+ char *argv[5] = {0, 0, 0, 0, 0};
+ size_t mod_argv_offset = 0;
if (mod_name == NULL)
return NULL;
@@ -166,11 +166,21 @@ OutputModule *load_output_module(char *mod_name, char
*mod_prog,
return NULL;
}
+ argv[0] = module->filename;
if (mod_cfgfile) {
- arg1 = g_strdup_printf("%s", module->configfilename);
- cfg = 1;
+ argv[1] = g_strdup(module->configfilename);
}
+ /* if (valgrind) {
+ * argv[4]=argv[2];
+ * argv[3]=argv[1];
+ * argv[2]=argv[0];
+ * argv[0]="valgrind";
+ * argv[1]="--trace-children=yes";
+ * mod_argv_offset = 2;
+ * }
+ */
+
/* Open the file for child stderr (logging) redirection */
if (module->debugfilename != NULL) {
module->stderr_redirect = open(module->debugfilename,
@@ -202,6 +212,7 @@ OutputModule *load_output_module(char *mod_name, char
*mod_prog,
}
if (fr == 0) {
+
ret = dup2(module->pipe_in[0], 0);
close(module->pipe_in[0]);
close(module->pipe_in[1]);
@@ -215,22 +226,16 @@ OutputModule *load_output_module(char *mod_name, char
*mod_prog,
ret = dup2(module->stderr_redirect, 2);
}
- if (cfg == 0) {
- if (execlp(module->filename, module->filename, (char
*)0) == -1) {
- exit(1);
- }
- } else {
- //if (execlp("valgrind", "valgrind"
,"--trace-children=yes", module->filename, arg1, arg2, (char *) 0) == -1){
- if (execlp(module->filename, module->filename, arg1,
(char *)0) == -1) {
- exit(1);
- }
+ execvp(argv[0], argv);
+ {
+ const char *modfile = argv[0 + mod_argv_offset];
+ const char *modconf = argv[1 + mod_argv_offset] ?
argv[1 + mod_argv_offset] : "<none>";
+ MSG(1, "Exec of module \"%s\" with config \"%s\" failed
with error %d: %s", modfile, modconf, errno, strerror(errno));
}
+ exit(1);
assert(0);
}
- if (cfg)
- g_free(arg1);
-
module->pid = fr;
close(module->pipe_in[0]);
close(module->pipe_out[1]);
--
1.7.4
- [PATCH 1/2] Refactor module loading for single place of exec* call.,
Boris Dušek <=
- [PATCH 1/2] Refactor module loading for single place of exec* call., Boris Dušek, 2011/03/19
- [PATCH 2/2] Slight workaround for buggy spd_get_path., Boris Dušek, 2011/03/19
- [PATCH 1/2] Refactor module loading for single place of exec* call., Trevor Saunders, 2011/03/19
- [PATCH 1/2] Refactor module loading for single place of exec* call., Boris Dušek, 2011/03/19
- [PATCH 1/2] Refactor module loading for single place of exec* call., Trevor Saunders, 2011/03/19
- [PATCH 1/2] Refactor module loading for single place of exec* call., Boris Dušek, 2011/03/22
- [PATCH 1/2] Refactor module loading for single place of exec* call., Christopher Brannon, 2011/03/29
- [PATCH 1/2] Refactor module loading for single place of exec* call., Boris Dušek, 2011/03/29
[PATCH 1/2] Refactor module loading for single place of exec* call., Boris Dušek, 2011/03/19