[lxc-devel] [PATCH 1/2] fix Coding Style
Daniel Lezcano
daniel.lezcano at free.fr
Tue Oct 12 08:54:33 UTC 2010
Fix the coding style, 80 chars lines, etc ...
Fix indentation blocks if ... then ... else ... fi
Signed-off-by: Daniel Lezcano <dlezcano at fr.ibm.com>
---
src/lxc/conf.c | 78 ++++++++++++++++++++++++++++----------------------------
1 files changed, 39 insertions(+), 39 deletions(-)
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 4f1b46c..87d3265 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -186,51 +186,61 @@ static struct caps_opt caps_opt[] = {
{ "mac_admin", CAP_MAC_ADMIN },
};
-static int run_script(const char *name, const char *section, const char *script, ...)
+static int run_script(const char *name, const char *section,
+ const char *script, ...)
{
va_list argp;
int vargc = 4;
+ int status = 0;
+
/* count variable arguments and add 4 for script, container
* and section name as well as the terminating NULL
*/
va_start(argp, script);
while (va_arg(argp, char*)) vargc++;
va_end(argp);
- INFO("Executing script '%s' for container '%s', config section '%s'", script, name, section);
+
+ INFO("Executing script '%s' for container '%s', config section '%s'",
+ script, name, section);
int pid = fork();
if (pid < 0) {
ERROR("Error forking");
- } else if (pid == 0) {
+ return -1;
+ }
+
+ if (pid == 0) {
+
/* prepare command line arguments */
char *args[vargc];
int i;
args[0] = strdup(script);
args[1] = strdup(name);
args[2] = strdup(section);
+
va_start(argp, script);
- for (i=3; i<vargc; i++) {
+ for (i = 3; i < vargc; i++)
args[i] = va_arg(argp, char*);
- }
va_end(argp);
+
args[vargc-1] = (char*) NULL;
execv(script, args);
/* if we cannot exec, we exit this fork */
- SYSERROR("Failed to execute script '%s' for container '%s': %s", script, name, strerror(errno));
+ SYSERROR("Failed to execute script '%s' for container '%s': %s",
+ script, name);
exit(1);
- } else {
- int status = 0;
- waitpid( pid, &status, 0 );
- if (status != 0) {
- /* something weird happened */
- SYSERROR("Script '%s' terminated with non-zero exitcode %d", name, status);
- return -1;
- } else {
- return 0; /* all is well */
- }
}
- return -1;
+
+ waitpid(pid, &status, 0);
+ if (status != 0) {
+ /* something weird happened */
+ SYSERROR("Script '%s' terminated with non-zero exitcode %d",
+ name, status);
+ return -1;
+ }
+
+ return 0;
}
static int find_fstype_cb(char* buffer, void *data)
@@ -1317,13 +1327,10 @@ static int instanciate_veth(struct lxc_handler *handler, struct lxc_netdev *netd
}
if (netdev->upscript) {
- err = run_script(handler->name, "net", netdev->upscript, "up", "veth",
- veth1, (char*) NULL);
- if (err) {
- ERROR("Failed to run script '%s' for container '%s' and interface '%s'",
- netdev->upscript, handler->name, veth1);
+ err = run_script(handler->name, "net", netdev->upscript, "up",
+ "veth", veth1, (char*) NULL);
+ if (err)
goto out_delete;
- }
}
DEBUG("instanciated veth '%s/%s', index is '%d'",
@@ -1370,13 +1377,10 @@ static int instanciate_macvlan(struct lxc_handler *handler, struct lxc_netdev *n
}
if (netdev->upscript) {
- err = run_script(handler->name, "net", netdev->upscript, "up", "macvlan",
- netdev->link, (char*) NULL);
- if (err) {
- ERROR("Failed to run script '%s' for container '%s' and interface '%s'",
- netdev->upscript, handler->name, netdev->link);
+ err = run_script(handler->name, "net", netdev->upscript, "up",
+ "macvlan", netdev->link, (char*) NULL);
+ if (err)
return -1;
- }
}
DEBUG("instanciated macvlan '%s', index is '%d' and mode '%d'",
@@ -1433,13 +1437,10 @@ static int instanciate_phys(struct lxc_handler *handler, struct lxc_netdev *netd
if (netdev->upscript) {
int err;
- err = run_script(handler->name, "net", netdev->upscript, "up", "phys",
- netdev->link, (char*) NULL);
- if (err) {
- ERROR("Failed to run script '%s' for container '%s' and interface '%s'",
- netdev->upscript, handler->name, netdev->link);
+ err = run_script(handler->name, "net", netdev->upscript,
+ "up", "phys", netdev->link, (char*) NULL);
+ if (err)
return -1;
- }
}
return 0;
@@ -1450,11 +1451,10 @@ static int instanciate_empty(struct lxc_handler *handler, struct lxc_netdev *net
netdev->ifindex = 0;
if (netdev->upscript) {
int err;
- err = run_script(handler->name, "net", netdev->upscript, "up", "empty", (char*) NULL);
- if (err) {
- ERROR("Failed to run script '%s' for container '%s'", netdev->upscript, handler->name);
+ err = run_script(handler->name, "net", netdev->upscript,
+ "up", "empty", (char*) NULL);
+ if (err)
return -1;
- }
}
return 0;
}
--
1.7.0.4
More information about the lxc-devel
mailing list