conf: cleanup macros run_script_argv

parent cc6a0e78
...@@ -345,9 +345,8 @@ int run_script_argv(const char *name, unsigned int hook_version, ...@@ -345,9 +345,8 @@ int run_script_argv(const char *name, unsigned int hook_version,
const char *section, const char *script, const char *section, const char *script,
const char *hookname, char **argv) const char *hookname, char **argv)
{ {
__do_free char *buffer = NULL;
int buf_pos, i, ret; int buf_pos, i, ret;
char *buffer;
int fret = -1;
size_t size = 0; size_t size = 0;
if (hook_version == 0) if (hook_version == 0)
...@@ -391,7 +390,7 @@ int run_script_argv(const char *name, unsigned int hook_version, ...@@ -391,7 +390,7 @@ int run_script_argv(const char *name, unsigned int hook_version,
buf_pos = snprintf(buffer, size, "exec %s", script); buf_pos = snprintf(buffer, size, "exec %s", script);
if (buf_pos < 0 || (size_t)buf_pos >= size) { if (buf_pos < 0 || (size_t)buf_pos >= size) {
ERROR("Failed to create command line for script \"%s\"", script); ERROR("Failed to create command line for script \"%s\"", script);
goto on_error; return -1;
} }
if (hook_version == 1) { if (hook_version == 1) {
...@@ -399,7 +398,7 @@ int run_script_argv(const char *name, unsigned int hook_version, ...@@ -399,7 +398,7 @@ int run_script_argv(const char *name, unsigned int hook_version,
if (ret < 0) { if (ret < 0) {
SYSERROR("Failed to set environment variable: " SYSERROR("Failed to set environment variable: "
"LXC_HOOK_TYPE=%s", hookname); "LXC_HOOK_TYPE=%s", hookname);
goto on_error; return -1;
} }
TRACE("Set environment variable: LXC_HOOK_TYPE=%s", hookname); TRACE("Set environment variable: LXC_HOOK_TYPE=%s", hookname);
...@@ -407,7 +406,7 @@ int run_script_argv(const char *name, unsigned int hook_version, ...@@ -407,7 +406,7 @@ int run_script_argv(const char *name, unsigned int hook_version,
if (ret < 0) { if (ret < 0) {
SYSERROR("Failed to set environment variable: " SYSERROR("Failed to set environment variable: "
"LXC_HOOK_SECTION=%s", section); "LXC_HOOK_SECTION=%s", section);
goto on_error; return -1;
} }
TRACE("Set environment variable: LXC_HOOK_SECTION=%s", section); TRACE("Set environment variable: LXC_HOOK_SECTION=%s", section);
...@@ -415,13 +414,13 @@ int run_script_argv(const char *name, unsigned int hook_version, ...@@ -415,13 +414,13 @@ int run_script_argv(const char *name, unsigned int hook_version,
char *parent; char *parent;
if (!argv || !argv[0]) if (!argv || !argv[0])
goto on_error; return -1;
ret = setenv("LXC_NET_TYPE", argv[0], 1); ret = setenv("LXC_NET_TYPE", argv[0], 1);
if (ret < 0) { if (ret < 0) {
SYSERROR("Failed to set environment variable: " SYSERROR("Failed to set environment variable: "
"LXC_NET_TYPE=%s", argv[0]); "LXC_NET_TYPE=%s", argv[0]);
goto on_error; return -1;
} }
TRACE("Set environment variable: LXC_NET_TYPE=%s", argv[0]); TRACE("Set environment variable: LXC_NET_TYPE=%s", argv[0]);
...@@ -432,7 +431,7 @@ int run_script_argv(const char *name, unsigned int hook_version, ...@@ -432,7 +431,7 @@ int run_script_argv(const char *name, unsigned int hook_version,
if (ret < 0) { if (ret < 0) {
SYSERROR("Failed to set environment " SYSERROR("Failed to set environment "
"variable: LXC_NET_PARENT=%s", parent); "variable: LXC_NET_PARENT=%s", parent);
goto on_error; return -1;
} }
TRACE("Set environment variable: LXC_NET_PARENT=%s", parent); TRACE("Set environment variable: LXC_NET_PARENT=%s", parent);
} else if (strcmp(argv[0], "phys") == 0) { } else if (strcmp(argv[0], "phys") == 0) {
...@@ -440,7 +439,7 @@ int run_script_argv(const char *name, unsigned int hook_version, ...@@ -440,7 +439,7 @@ int run_script_argv(const char *name, unsigned int hook_version,
if (ret < 0) { if (ret < 0) {
SYSERROR("Failed to set environment " SYSERROR("Failed to set environment "
"variable: LXC_NET_PARENT=%s", parent); "variable: LXC_NET_PARENT=%s", parent);
goto on_error; return -1;
} }
TRACE("Set environment variable: LXC_NET_PARENT=%s", parent); TRACE("Set environment variable: LXC_NET_PARENT=%s", parent);
} else if (strcmp(argv[0], "veth") == 0) { } else if (strcmp(argv[0], "veth") == 0) {
...@@ -450,7 +449,7 @@ int run_script_argv(const char *name, unsigned int hook_version, ...@@ -450,7 +449,7 @@ int run_script_argv(const char *name, unsigned int hook_version,
if (ret < 0) { if (ret < 0) {
SYSERROR("Failed to set environment " SYSERROR("Failed to set environment "
"variable: LXC_NET_PEER=%s", peer); "variable: LXC_NET_PEER=%s", peer);
goto on_error; return -1;
} }
TRACE("Set environment variable: LXC_NET_PEER=%s", peer); TRACE("Set environment variable: LXC_NET_PEER=%s", peer);
...@@ -458,7 +457,7 @@ int run_script_argv(const char *name, unsigned int hook_version, ...@@ -458,7 +457,7 @@ int run_script_argv(const char *name, unsigned int hook_version,
if (ret < 0) { if (ret < 0) {
SYSERROR("Failed to set environment " SYSERROR("Failed to set environment "
"variable: LXC_NET_PARENT=%s", parent); "variable: LXC_NET_PARENT=%s", parent);
goto on_error; return -1;
} }
TRACE("Set environment variable: LXC_NET_PARENT=%s", parent); TRACE("Set environment variable: LXC_NET_PARENT=%s", parent);
} }
...@@ -471,16 +470,12 @@ int run_script_argv(const char *name, unsigned int hook_version, ...@@ -471,16 +470,12 @@ int run_script_argv(const char *name, unsigned int hook_version,
ret = snprintf(buffer + buf_pos, len, " %s", argv[i]); ret = snprintf(buffer + buf_pos, len, " %s", argv[i]);
if (ret < 0 || (size_t)ret >= len) { if (ret < 0 || (size_t)ret >= len) {
ERROR("Failed to create command line for script \"%s\"", script); ERROR("Failed to create command line for script \"%s\"", script);
goto on_error; return -1;
} }
buf_pos += ret; buf_pos += ret;
} }
fret = run_buffer(buffer); return run_buffer(buffer);
on_error:
free(buffer);
return fret;
} }
int run_script(const char *name, const char *section, const char *script, ...) int run_script(const char *name, const char *section, const char *script, ...)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment