Browse Source

* misc fixes

master
Alex 'AdUser' Z 9 years ago
parent
commit
0d32d5d95c
  1. 7
      src/backend.c
  2. 21
      src/backends/exec.c
  3. 2
      src/config.c

7
src/backend.c

@ -8,6 +8,7 @@ f2b_backend_create(f2b_config_section_t *config, const char *id) {
f2b_config_param_t *param = NULL; f2b_config_param_t *param = NULL;
f2b_backend_t *backend = NULL; f2b_backend_t *backend = NULL;
int flags = RTLD_NOW | RTLD_LOCAL; int flags = RTLD_NOW | RTLD_LOCAL;
const char *dlerr = NULL;
assert(config != NULL); assert(config != NULL);
assert(config->type == t_backend); assert(config->type == t_backend);
@ -50,7 +51,7 @@ f2b_backend_create(f2b_config_section_t *config, const char *id) {
} }
/* try init */ /* try init */
for (; param != NULL; param = param->next) { for (param = config->param; param != NULL; param = param->next) {
if (strcmp(param->name, BACKEND_LIBRARY_PARAM) == 0) if (strcmp(param->name, BACKEND_LIBRARY_PARAM) == 0)
continue; continue;
if (backend->config(backend->cfg, param->name, param->value)) if (backend->config(backend->cfg, param->name, param->value))
@ -66,7 +67,9 @@ f2b_backend_create(f2b_config_section_t *config, const char *id) {
f2b_log_msg(log_error, "backend '%s' not fully configured", config->name); f2b_log_msg(log_error, "backend '%s' not fully configured", config->name);
cleanup: cleanup:
f2b_log_msg(log_error, "load error: %s", dlerror()); dlerr = dlerror();
if (dlerr)
f2b_log_msg(log_error, "backend load error: %s", dlerr);
if (backend->h) { if (backend->h) {
if (backend->cfg && backend->destroy) if (backend->cfg && backend->destroy)
backend->destroy(backend->cfg); backend->destroy(backend->cfg);

21
src/backends/exec.c

@ -14,7 +14,7 @@ typedef struct cmd_t {
char *args; /**< stores path of cmd & args, delimited by '\0' */ char *args; /**< stores path of cmd & args, delimited by '\0' */
char **argv; /**< stores array of pointers to args + NULL */ char **argv; /**< stores array of pointers to args + NULL */
size_t argc; /**< args count */ size_t argc; /**< args count */
size_t pos; /**< index in argv[] where to insert IP address */ size_t pos; /**< index+1 in argv[] where to insert IP address (zero means "no placeholder") */
} cmd_t; } cmd_t;
struct _config { struct _config {
@ -31,7 +31,9 @@ static cmd_t *
cmd_from_str(const char *str) { cmd_from_str(const char *str) {
cmd_t *cmd = NULL; cmd_t *cmd = NULL;
const char *delim = " \t"; const char *delim = " \t";
char *token, *saveptr, *argv; char *token, *saveptr, **argv;
assert(str != NULL);
if ((cmd = calloc(1, sizeof(cmd_t))) == NULL) if ((cmd = calloc(1, sizeof(cmd_t))) == NULL)
return NULL; return NULL;
@ -39,17 +41,24 @@ cmd_from_str(const char *str) {
if ((cmd->args = strdup(str)) == NULL) if ((cmd->args = strdup(str)) == NULL)
goto cleanup; goto cleanup;
cmd->argc = 1;
if ((cmd->argv = calloc(2, sizeof(cmd->argv))) == NULL)
goto cleanup;
cmd->argv[cmd->argc] = NULL;
strtok_r(cmd->args, delim, &saveptr); strtok_r(cmd->args, delim, &saveptr);
cmd->argv[0] = cmd->args;
while ((token = strtok_r(NULL, delim, &saveptr)) != NULL) { while ((token = strtok_r(NULL, delim, &saveptr)) != NULL) {
if ((argv = realloc(cmd->argv, sizeof(cmd->argv) * (cmd->argc + 2))) == NULL) if ((argv = realloc(cmd->argv, sizeof(cmd->argv) * (cmd->argc + 2))) == NULL)
goto cleanup; goto cleanup;
*cmd->argv = argv; cmd->argv = argv;
if (strcmp(token, HOST_TOKEN) == 0) if (strcmp(token, HOST_TOKEN) == 0)
cmd->pos = cmd->argc + 1; cmd->pos = cmd->argc;
cmd->argv[cmd->argc] = token; cmd->argv[cmd->argc] = token;
cmd->argc++; cmd->argc++;
} }
cmd->argv[cmd->argc + 1] = NULL; cmd->argv[cmd->argc] = NULL;
return cmd; return cmd;
@ -97,7 +106,7 @@ cmd_list_exec(cmd_t *list, const char *ip, time_t timeout) {
if (pid == 0) { if (pid == 0) {
/* child */ /* child */
if (ip && cmd->pos) if (ip && cmd->pos)
cmd->argv[cmd->pos - 1] = ip; cmd->argv[cmd->pos - 1] = strdup(ip);
if (timeout) if (timeout)
alarm(timeout); alarm(timeout);
execv(cmd->args, cmd->argv); execv(cmd->args, cmd->argv);

2
src/config.c

@ -217,6 +217,6 @@ f2b_config_free(f2b_config_section_t *config) {
next_param = config->param->next; next_param = config->param->next;
FREE(config->param); FREE(config->param);
} }
FREE(next_section); FREE(config);
} }
} }

Loading…
Cancel
Save