From: Stéphane Graber Date: Mon, 21 Sep 2015 20:25:47 +0000 (-0400) Subject: Fix indentation X-Git-Tag: lxc-2.0.0.beta1~130 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d028235de9ec7664e1c2c904c541a447a768997a;p=thirdparty%2Flxc.git Fix indentation I've noticed that a bunch of the code we've included over the past few weeks has been using 8-spaces rather than tabs, making it all very hard to read depending on your tabstop setting. This commit attempts to revert all of that back to proper tabs and fix a few more cases I've noticed here and there. No functional changes are included in this commit. Signed-off-by: Stéphane Graber --- diff --git a/src/lxc/caps.c b/src/lxc/caps.c index 9f3e96cfe..9712e11d2 100644 --- a/src/lxc/caps.c +++ b/src/lxc/caps.c @@ -71,7 +71,7 @@ int lxc_caps_down(void) out: cap_free(caps); - return 0; + return 0; } int lxc_caps_up(void) @@ -121,7 +121,7 @@ int lxc_caps_up(void) out: cap_free(caps); - return 0; + return 0; } int lxc_caps_init(void) diff --git a/src/lxc/caps.h b/src/lxc/caps.h index ac508e321..f39fec65a 100644 --- a/src/lxc/caps.h +++ b/src/lxc/caps.h @@ -33,17 +33,17 @@ extern int lxc_caps_init(void); extern int lxc_caps_last_cap(void); #else static inline int lxc_caps_down(void) { - return 0; + return 0; } static inline int lxc_caps_up(void) { - return 0; + return 0; } static inline int lxc_caps_init(void) { - return 0; + return 0; } static inline int lxc_caps_last_cap(void) { - return 0; + return 0; } #endif diff --git a/src/lxc/cgmanager.c b/src/lxc/cgmanager.c index c143beab9..8386d83ab 100644 --- a/src/lxc/cgmanager.c +++ b/src/lxc/cgmanager.c @@ -122,13 +122,13 @@ static void cull_user_controllers(void); static void cgm_dbus_disconnect(void) { - if (cgroup_manager) { - dbus_connection_flush(cgroup_manager->connection); - dbus_connection_close(cgroup_manager->connection); - nih_free(cgroup_manager); - } - cgroup_manager = NULL; - cgm_unlock(); + if (cgroup_manager) { + dbus_connection_flush(cgroup_manager->connection); + dbus_connection_close(cgroup_manager->connection); + nih_free(cgroup_manager); + } + cgroup_manager = NULL; + cgm_unlock(); } #define CGMANAGER_DBUS_SOCK "unix:path=/sys/fs/cgroup/cgmanager/sock" diff --git a/src/lxc/confile.c b/src/lxc/confile.c index 5f8540e30..670d95740 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -1157,10 +1157,10 @@ static int config_group(const char *key, const char *value, /* in case several groups are specified in a single line * split these groups in a single element for the list */ for (groupptr = groups;;groupptr = NULL) { - token = strtok_r(groupptr, " \t", &sptr); - if (!token) { + token = strtok_r(groupptr, " \t", &sptr); + if (!token) { ret = 0; - break; + break; } grouplist = malloc(sizeof(*grouplist)); @@ -1177,7 +1177,7 @@ static int config_group(const char *key, const char *value, } lxc_list_add_tail(&lxc_conf->groups, grouplist); - } + } free(groups); @@ -1552,10 +1552,10 @@ static int config_mount_auto(const char *key, const char *value, } for (autoptr = autos; ; autoptr = NULL) { - token = strtok_r(autoptr, " \t", &sptr); - if (!token) { + token = strtok_r(autoptr, " \t", &sptr); + if (!token) { ret = 0; - break; + break; } for (i = 0; allowed_auto_mounts[i].token; i++) { @@ -1570,7 +1570,7 @@ static int config_mount_auto(const char *key, const char *value, lxc_conf->auto_mounts &= ~allowed_auto_mounts[i].mask; lxc_conf->auto_mounts |= allowed_auto_mounts[i].flag; - } + } free(autos); @@ -1621,10 +1621,10 @@ static int config_cap_keep(const char *key, const char *value, /* in case several capability keep is specified in a single line * split these caps in a single element for the list */ for (keepptr = keepcaps;;keepptr = NULL) { - token = strtok_r(keepptr, " \t", &sptr); - if (!token) { + token = strtok_r(keepptr, " \t", &sptr); + if (!token) { ret = 0; - break; + break; } if (!strcmp(token, "none")) @@ -1644,7 +1644,7 @@ static int config_cap_keep(const char *key, const char *value, } lxc_list_add_tail(&lxc_conf->keepcaps, keeplist); - } + } free(keepcaps); @@ -1670,10 +1670,10 @@ static int config_cap_drop(const char *key, const char *value, /* in case several capability drop is specified in a single line * split these caps in a single element for the list */ for (dropptr = dropcaps;;dropptr = NULL) { - token = strtok_r(dropptr, " \t", &sptr); - if (!token) { + token = strtok_r(dropptr, " \t", &sptr); + if (!token) { ret = 0; - break; + break; } droplist = malloc(sizeof(*droplist)); @@ -1690,7 +1690,7 @@ static int config_cap_drop(const char *key, const char *value, } lxc_list_add_tail(&lxc_conf->caps, droplist); - } + } free(dropcaps); @@ -2047,7 +2047,7 @@ int lxc_fill_elevated_privileges(char *flaglist, int *flags) /* for the sake of backward compatibility, drop all privileges if none is specified */ for (i = 0; all_privs[i].token; i++) { - *flags |= all_privs[i].flag; + *flags |= all_privs[i].flag; } return 0; } diff --git a/src/lxc/genl.c b/src/lxc/genl.c index 64177648c..b5a582e8a 100644 --- a/src/lxc/genl.c +++ b/src/lxc/genl.c @@ -53,10 +53,10 @@ static int genetlink_resolve_family(const char *family) request->nlmsghdr.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN); request->nlmsghdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; - request->nlmsghdr.nlmsg_type = GENL_ID_CTRL; + request->nlmsghdr.nlmsg_type = GENL_ID_CTRL; genlmsghdr = NLMSG_DATA(&request->nlmsghdr); - genlmsghdr->cmd = CTRL_CMD_GETFAMILY; + genlmsghdr->cmd = CTRL_CMD_GETFAMILY; ret = netlink_open(&handler, NETLINK_GENERIC); if (ret) diff --git a/src/lxc/genl.h b/src/lxc/genl.h index 30806186f..a83b7a7a9 100644 --- a/src/lxc/genl.h +++ b/src/lxc/genl.h @@ -59,7 +59,7 @@ struct genlmsg { static inline int genetlink_len(const struct genlmsg *genlmsg) { - return ((genlmsg->nlmsghdr.nlmsg_len) - GENL_HDRLEN - NLMSG_HDRLEN); + return ((genlmsg->nlmsghdr.nlmsg_len) - GENL_HDRLEN - NLMSG_HDRLEN); } /* diff --git a/src/lxc/list.h b/src/lxc/list.h index f16af54f6..2d8a2a84d 100644 --- a/src/lxc/list.h +++ b/src/lxc/list.h @@ -72,10 +72,10 @@ static inline void __lxc_list_add(struct lxc_list *new, struct lxc_list *prev, struct lxc_list *next) { - next->prev = new; - new->next = next; - new->prev = prev; - prev->next = new; + next->prev = new; + new->next = next; + new->prev = prev; + prev->next = new; } static inline void lxc_list_add(struct lxc_list *head, struct lxc_list *list) diff --git a/src/lxc/lxc_attach.c b/src/lxc/lxc_attach.c index 94f0f7a14..1c2434982 100644 --- a/src/lxc/lxc_attach.c +++ b/src/lxc/lxc_attach.c @@ -113,12 +113,12 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg) /* -s implies -e */ lxc_fill_elevated_privileges(NULL, &elevated_privileges); break; - case 500: /* clear-env */ - env_policy = LXC_ATTACH_CLEAR_ENV; - break; - case 501: /* keep-env */ - env_policy = LXC_ATTACH_KEEP_ENV; - break; + case 500: /* clear-env */ + env_policy = LXC_ATTACH_CLEAR_ENV; + break; + case 501: /* keep-env */ + env_policy = LXC_ATTACH_KEEP_ENV; + break; case 502: /* keep-var */ ret = add_to_simple_array(&extra_keep, &extra_keep_size, arg); if (ret < 0) { diff --git a/src/lxc/lxc_init.c b/src/lxc/lxc_init.c index f4b120db0..5dd29afbe 100644 --- a/src/lxc/lxc_init.c +++ b/src/lxc/lxc_init.c @@ -117,7 +117,7 @@ int main(int argc, char *argv[]) aargv = &argv[optind]; - /* + /* * mask all the signals so we are safe to install a * signal handler and to fork */ diff --git a/src/lxc/lxc_start.c b/src/lxc/lxc_start.c index ec6ee219c..6b942acd1 100644 --- a/src/lxc/lxc_start.c +++ b/src/lxc/lxc_start.c @@ -190,7 +190,7 @@ Options :\n\ -L, --console-log=FILE Log container console output to FILE\n\ -C, --close-all-fds If any fds are inherited, close them\n\ If not specified, exit with failure instead\n\ - Note: --daemon implies --close-all-fds\n\ + Note: --daemon implies --close-all-fds\n\ -s, --define KEY=VAL Assign VAL to configuration variable KEY\n\ --share-[net|ipc|uts]=NAME Share a namespace with another container or pid\n\ ", diff --git a/src/lxc/lxc_unshare.c b/src/lxc/lxc_unshare.c index 59a231e57..e629525c6 100644 --- a/src/lxc/lxc_unshare.c +++ b/src/lxc/lxc_unshare.c @@ -115,8 +115,8 @@ struct start_arg { int *flags; uid_t *uid; bool setuid; - int want_default_mounts; - const char *want_hostname; + int want_default_mounts; + const char *want_hostname; }; static int do_start(void *arg) diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c index dd891dc95..42e23e736 100644 --- a/src/lxc/lxccontainer.c +++ b/src/lxc/lxccontainer.c @@ -2049,49 +2049,49 @@ static bool mod_rdep(struct lxc_container *c0, struct lxc_container *c, bool inc goto out; } } else if (!inc) { - if ((fd = open(path, O_RDWR | O_CLOEXEC)) < 0) - goto out; - - if (fstat(fd, &fbuf) < 0) { - close(fd); - goto out; - } - - if (fbuf.st_size != 0) { - /* write terminating \0-byte to file */ - if (pwrite(fd, "", 1, fbuf.st_size) <= 0) { - close(fd); - goto out; - } - - buf = mmap(NULL, fbuf.st_size + 1, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (buf == MAP_FAILED) { - SYSERROR("Failed to create mapping %s", path); - close(fd); - goto out; - } - - len = strlen(newpath); - while ((del = strstr((char *)buf, newpath))) { - memmove(del, del + len, strlen(del) - len + 1); - bytes += len; - } - - munmap(buf, fbuf.st_size + 1); - if (ftruncate(fd, fbuf.st_size - bytes) < 0) { - SYSERROR("Failed to truncate file %s", path); - close(fd); - goto out; - } - } - close(fd); - } + if ((fd = open(path, O_RDWR | O_CLOEXEC)) < 0) + goto out; + + if (fstat(fd, &fbuf) < 0) { + close(fd); + goto out; + } + + if (fbuf.st_size != 0) { + /* write terminating \0-byte to file */ + if (pwrite(fd, "", 1, fbuf.st_size) <= 0) { + close(fd); + goto out; + } + + buf = mmap(NULL, fbuf.st_size + 1, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + if (buf == MAP_FAILED) { + SYSERROR("Failed to create mapping %s", path); + close(fd); + goto out; + } + + len = strlen(newpath); + while ((del = strstr((char *)buf, newpath))) { + memmove(del, del + len, strlen(del) - len + 1); + bytes += len; + } + + munmap(buf, fbuf.st_size + 1); + if (ftruncate(fd, fbuf.st_size - bytes) < 0) { + SYSERROR("Failed to truncate file %s", path); + close(fd); + goto out; + } + } + close(fd); + } /* If the lxc-snapshot file is empty, remove it. */ if (stat(path, &fbuf) < 0) goto out; - if (!fbuf.st_size) { - remove(path); + if (!fbuf.st_size) { + remove(path); } } @@ -2212,12 +2212,12 @@ static bool has_snapshots(struct lxc_container *c) } static bool do_destroy_container(struct lxc_conf *conf) { - if (am_unpriv()) { - if (userns_exec_1(conf, bdev_destroy_wrapper, conf) < 0) - return false; - return true; - } - return bdev_destroy(conf); + if (am_unpriv()) { + if (userns_exec_1(conf, bdev_destroy_wrapper, conf) < 0) + return false; + return true; + } + return bdev_destroy(conf); } static int lxc_rmdir_onedev_wrapper(void *data) @@ -2281,13 +2281,13 @@ static bool container_destroy(struct lxc_container *c) } } - if (conf && conf->rootfs.path && conf->rootfs.mount) { - if (!do_destroy_container(conf)) { - ERROR("Error destroying rootfs for %s", c->name); - goto out; - } - INFO("Destroyed rootfs for %s", c->name); - } + if (conf && conf->rootfs.path && conf->rootfs.mount) { + if (!do_destroy_container(conf)) { + ERROR("Error destroying rootfs for %s", c->name); + goto out; + } + INFO("Destroyed rootfs for %s", c->name); + } mod_all_rdeps(c, false); @@ -2302,7 +2302,7 @@ static bool container_destroy(struct lxc_container *c) ERROR("Error destroying container directory for %s", c->name); goto out; } - INFO("Destroyed directory for %s", c->name); + INFO("Destroyed directory for %s", c->name); bret = true; @@ -2889,7 +2889,7 @@ static int create_file_dirname(char *path, struct lxc_conf *conf) if (!p) return -1; *p = '\0'; - ret = do_create_container_dir(path, conf); + ret = do_create_container_dir(path, conf); *p = '/'; return ret; } diff --git a/src/lxc/lxccontainer.h b/src/lxc/lxccontainer.h index d60e19af1..d8b20ecd7 100644 --- a/src/lxc/lxccontainer.h +++ b/src/lxc/lxccontainer.h @@ -831,17 +831,17 @@ struct lxc_snapshot { * \brief Specifications for how to create a new backing store */ struct bdev_specs { - char *fstype; /*!< Filesystem type */ - uint64_t fssize; /*!< Filesystem size in bytes */ - struct { - char *zfsroot; /*!< ZFS root path */ - } zfs; - struct { - char *vg; /*!< LVM Volume Group name */ - char *lv; /*!< LVM Logical Volume name */ - char *thinpool; /*!< LVM thin pool to use, if any */ - } lvm; - char *dir; /*!< Directory path */ + char *fstype; /*!< Filesystem type */ + uint64_t fssize; /*!< Filesystem size in bytes */ + struct { + char *zfsroot; /*!< ZFS root path */ + } zfs; + struct { + char *vg; /*!< LVM Volume Group name */ + char *lv; /*!< LVM Logical Volume name */ + char *thinpool; /*!< LVM thin pool to use, if any */ + } lvm; + char *dir; /*!< Directory path */ }; /*! diff --git a/src/lxc/nl.c b/src/lxc/nl.c index dd044f0f7..cfa5cdf22 100644 --- a/src/lxc/nl.c +++ b/src/lxc/nl.c @@ -74,7 +74,7 @@ extern int nla_put_buffer(struct nlmsg *nlmsg, int attr, extern int nla_put_string(struct nlmsg *nlmsg, int attr, const char *string) { - return nla_put(nlmsg, attr, string, strlen(string) + 1); + return nla_put(nlmsg, attr, string, strlen(string) + 1); } extern int nla_put_u32(struct nlmsg *nlmsg, int attr, int value) @@ -173,23 +173,23 @@ extern void nlmsg_free(struct nlmsg *nlmsg) extern int netlink_rcv(struct nl_handler *handler, struct nlmsg *answer) { int ret; - struct sockaddr_nl nladdr; - struct iovec iov = { - .iov_base = answer->nlmsghdr, - .iov_len = answer->nlmsghdr->nlmsg_len, - }; + struct sockaddr_nl nladdr; + struct iovec iov = { + .iov_base = answer->nlmsghdr, + .iov_len = answer->nlmsghdr->nlmsg_len, + }; struct msghdr msg = { - .msg_name = &nladdr, - .msg_namelen = sizeof(nladdr), - .msg_iov = &iov, - .msg_iovlen = 1, - }; + .msg_name = &nladdr, + .msg_namelen = sizeof(nladdr), + .msg_iov = &iov, + .msg_iovlen = 1, + }; - memset(&nladdr, 0, sizeof(nladdr)); - nladdr.nl_family = AF_NETLINK; - nladdr.nl_pid = 0; - nladdr.nl_groups = 0; + memset(&nladdr, 0, sizeof(nladdr)); + nladdr.nl_family = AF_NETLINK; + nladdr.nl_pid = 0; + nladdr.nl_groups = 0; again: ret = recvmsg(handler->fd, &msg, 0); @@ -211,23 +211,23 @@ again: extern int netlink_send(struct nl_handler *handler, struct nlmsg *nlmsg) { - struct sockaddr_nl nladdr; - struct iovec iov = { - .iov_base = nlmsg->nlmsghdr, - .iov_len = nlmsg->nlmsghdr->nlmsg_len, - }; + struct sockaddr_nl nladdr; + struct iovec iov = { + .iov_base = nlmsg->nlmsghdr, + .iov_len = nlmsg->nlmsghdr->nlmsg_len, + }; struct msghdr msg = { - .msg_name = &nladdr, - .msg_namelen = sizeof(nladdr), - .msg_iov = &iov, - .msg_iovlen = 1, - }; + .msg_name = &nladdr, + .msg_namelen = sizeof(nladdr), + .msg_iov = &iov, + .msg_iovlen = 1, + }; int ret; - memset(&nladdr, 0, sizeof(nladdr)); - nladdr.nl_family = AF_NETLINK; - nladdr.nl_pid = 0; - nladdr.nl_groups = 0; + memset(&nladdr, 0, sizeof(nladdr)); + nladdr.nl_family = AF_NETLINK; + nladdr.nl_pid = 0; + nladdr.nl_groups = 0; ret = sendmsg(handler->fd, &msg, 0); if (ret < 0) @@ -263,45 +263,45 @@ extern int netlink_transaction(struct nl_handler *handler, extern int netlink_open(struct nl_handler *handler, int protocol) { socklen_t socklen; - int sndbuf = 32768; - int rcvbuf = 32768; + int sndbuf = 32768; + int rcvbuf = 32768; - memset(handler, 0, sizeof(*handler)); + memset(handler, 0, sizeof(*handler)); - handler->fd = socket(AF_NETLINK, SOCK_RAW, protocol); - if (handler->fd < 0) - return -errno; + handler->fd = socket(AF_NETLINK, SOCK_RAW, protocol); + if (handler->fd < 0) + return -errno; - if (setsockopt(handler->fd, SOL_SOCKET, SO_SNDBUF, + if (setsockopt(handler->fd, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof(sndbuf)) < 0) - return -errno; + return -errno; - if (setsockopt(handler->fd, SOL_SOCKET, SO_RCVBUF, + if (setsockopt(handler->fd, SOL_SOCKET, SO_RCVBUF, &rcvbuf,sizeof(rcvbuf)) < 0) - return -errno; + return -errno; - memset(&handler->local, 0, sizeof(handler->local)); - handler->local.nl_family = AF_NETLINK; - handler->local.nl_groups = 0; + memset(&handler->local, 0, sizeof(handler->local)); + handler->local.nl_family = AF_NETLINK; + handler->local.nl_groups = 0; - if (bind(handler->fd, (struct sockaddr*)&handler->local, + if (bind(handler->fd, (struct sockaddr*)&handler->local, sizeof(handler->local)) < 0) - return -errno; + return -errno; - socklen = sizeof(handler->local); - if (getsockname(handler->fd, (struct sockaddr*)&handler->local, + socklen = sizeof(handler->local); + if (getsockname(handler->fd, (struct sockaddr*)&handler->local, &socklen) < 0) - return -errno; + return -errno; - if (socklen != sizeof(handler->local)) - return -EINVAL; + if (socklen != sizeof(handler->local)) + return -EINVAL; - if (handler->local.nl_family != AF_NETLINK) - return -EINVAL; + if (handler->local.nl_family != AF_NETLINK) + return -EINVAL; handler->seq = time(NULL); - return 0; + return 0; } extern int netlink_close(struct nl_handler *handler) diff --git a/src/lxc/nl.h b/src/lxc/nl.h index f6f2fd0bf..d347835fa 100644 --- a/src/lxc/nl.h +++ b/src/lxc/nl.h @@ -46,10 +46,10 @@ * @peer: the peer address */ struct nl_handler { - int fd; + int fd; int seq; - struct sockaddr_nl local; - struct sockaddr_nl peer; + struct sockaddr_nl local; + struct sockaddr_nl peer; }; /* diff --git a/src/lxc/start.c b/src/lxc/start.c index 4e977c52f..0601333e2 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -529,10 +529,10 @@ void lxc_abort(const char *name, struct lxc_handler *handler) */ static int container_reboot_supported(void *arg) { - int *cmd = arg; + int *cmd = arg; int ret; - ret = reboot(*cmd); + ret = reboot(*cmd); if (ret == -1 && errno == EINVAL) return 1; return 0; @@ -542,10 +542,10 @@ static int must_drop_cap_sys_boot(struct lxc_conf *conf) { FILE *f; int ret, cmd, v, flags; - long stack_size = 4096; - void *stack = alloca(stack_size); - int status; - pid_t pid; + long stack_size = 4096; + void *stack = alloca(stack_size); + int status; + pid_t pid; f = fopen("/proc/sys/kernel/ctrl-alt-del", "r"); if (!f) { @@ -645,7 +645,7 @@ static int do_start(void *data) return -1; } - /* This prctl must be before the synchro, so if the parent + /* This prctl must be before the synchro, so if the parent * dies before we set the parent death signal, we will detect * its death with the synchro right after, otherwise we have * a window where the parent can exit before we set the pdeath @@ -1214,7 +1214,7 @@ int __lxc_start(const char *name, struct lxc_conf *conf, * lxc-execute which simply exited. In any case, treat * it as a 'halt' */ - if (WIFSIGNALED(status)) { + if (WIFSIGNALED(status)) { switch(WTERMSIG(status)) { case SIGINT: /* halt */ DEBUG("Container halting"); @@ -1230,7 +1230,7 @@ int __lxc_start(const char *name, struct lxc_conf *conf, DEBUG("unknown exit status for init: %d", WTERMSIG(status)); break; } - } + } DEBUG("Pushing physical nics back to host namespace"); lxc_rename_phys_nics_on_shutdown(netnsfd, handler->conf); @@ -1356,11 +1356,11 @@ static int lxc_rmdir_onedev_wrapper(void *data) } static bool do_destroy_container(struct lxc_conf *conf) { - if (am_unpriv()) { - if (userns_exec_1(conf, bdev_destroy_wrapper, conf) < 0) - return false; - return true; - } - return bdev_destroy(conf); + if (am_unpriv()) { + if (userns_exec_1(conf, bdev_destroy_wrapper, conf) < 0) + return false; + return true; + } + return bdev_destroy(conf); } diff --git a/src/python-lxc/lxc.c b/src/python-lxc/lxc.c index d349287d5..b4698ad70 100644 --- a/src/python-lxc/lxc.c +++ b/src/python-lxc/lxc.c @@ -542,8 +542,7 @@ Container_attach_interface(Container *self, PyObject *args, PyObject *kwds) assert(dst_name != NULL); } - if (self->container->attach_interface(self->container, src_name, - dst_name)) { + if (self->container->attach_interface(self->container, src_name, dst_name)) { Py_XDECREF(py_src_name); Py_XDECREF(py_dst_name); Py_RETURN_TRUE; diff --git a/src/tests/concurrent.c b/src/tests/concurrent.c index f32411afe..e6899adc5 100644 --- a/src/tests/concurrent.c +++ b/src/tests/concurrent.c @@ -85,8 +85,8 @@ static void do_function(void *arguments) } if (debug) { - c->set_config_item(c, "lxc.loglevel", "DEBUG"); - c->set_config_item(c, "lxc.logfile", name); + c->set_config_item(c, "lxc.loglevel", "DEBUG"); + c->set_config_item(c, "lxc.logfile", name); } if (strcmp(args->mode, "create") == 0) { @@ -132,7 +132,7 @@ static void do_function(void *arguments) out: lxc_container_put(c); if (debug) - lxc_log_close(); + lxc_log_close(); } static void *concurrent(void *arguments) @@ -171,9 +171,9 @@ int main(int argc, char *argv[]) { case 'q': quiet = 1; break; - case 'D': - debug = 1; - break; + case 'D': + debug = 1; + break; case 'm': { char *mode_tok, *tok, *saveptr = NULL; @@ -187,10 +187,10 @@ int main(int argc, char *argv[]) { exit(EXIT_FAILURE); } modes[i] = tok; - } + } modes[i] = NULL; break; - } + } default: /* '?' */ usage(); exit(EXIT_FAILURE); diff --git a/src/tests/reboot.c b/src/tests/reboot.c index 5583332ac..754984ef8 100644 --- a/src/tests/reboot.c +++ b/src/tests/reboot.c @@ -35,43 +35,43 @@ int clone(int (*fn)(void *), void *child_stack, int flags, void *arg, ...); static int do_reboot(void *arg) { - int *cmd = arg; + int *cmd = arg; - if (reboot(*cmd)) - printf("failed to reboot(%d): %m\n", *cmd); + if (reboot(*cmd)) + printf("failed to reboot(%d): %m\n", *cmd); return 0; } static int test_reboot(int cmd, int sig) { - long stack_size = 4096; - void *stack = alloca(stack_size) + stack_size; - int status; - pid_t ret; - - ret = clone(do_reboot, stack, CLONE_NEWPID | SIGCHLD, &cmd); - if (ret < 0) { - printf("failed to clone: %m\n"); - return -1; - } - - if (wait(&status) < 0) { - printf("unexpected wait error: %m\n"); - return -1; - } - - if (!WIFSIGNALED(status)) { + long stack_size = 4096; + void *stack = alloca(stack_size) + stack_size; + int status; + pid_t ret; + + ret = clone(do_reboot, stack, CLONE_NEWPID | SIGCHLD, &cmd); + if (ret < 0) { + printf("failed to clone: %m\n"); + return -1; + } + + if (wait(&status) < 0) { + printf("unexpected wait error: %m\n"); + return -1; + } + + if (!WIFSIGNALED(status)) { if (sig != -1) printf("child process exited but was not signaled\n"); - return -1; - } + return -1; + } - if (WTERMSIG(status) != sig) { - printf("signal termination is not the one expected\n"); - return -1; - } + if (WTERMSIG(status) != sig) { + printf("signal termination is not the one expected\n"); + return -1; + } - return 0; + return 0; } static int have_reboot_patch(void) @@ -95,46 +95,46 @@ static int have_reboot_patch(void) int main(int argc, char *argv[]) { - int status; + int status; if (getuid() != 0) { - printf("Must run as root.\n"); - return 1; + printf("Must run as root.\n"); + return 1; } status = have_reboot_patch(); if (status != 0) { - printf("Your kernel does not have the container reboot patch\n"); - return 1; + printf("Your kernel does not have the container reboot patch\n"); + return 1; } - status = test_reboot(LINUX_REBOOT_CMD_CAD_ON, -1); - if (status >= 0) { - printf("reboot(LINUX_REBOOT_CMD_CAD_ON) should have failed\n"); - return 1; - } - printf("reboot(LINUX_REBOOT_CMD_CAD_ON) has failed as expected\n"); - - status = test_reboot(LINUX_REBOOT_CMD_RESTART, SIGHUP); - if (status < 0) - return 1; - printf("reboot(LINUX_REBOOT_CMD_RESTART) succeed\n"); - - status = test_reboot(LINUX_REBOOT_CMD_RESTART2, SIGHUP); - if (status < 0) - return 1; - printf("reboot(LINUX_REBOOT_CMD_RESTART2) succeed\n"); - - status = test_reboot(LINUX_REBOOT_CMD_HALT, SIGINT); - if (status < 0) - return 1; - printf("reboot(LINUX_REBOOT_CMD_HALT) succeed\n"); - - status = test_reboot(LINUX_REBOOT_CMD_POWER_OFF, SIGINT); - if (status < 0) - return 1; - printf("reboot(LINUX_REBOOT_CMD_POWERR_OFF) succeed\n"); - - printf("All tests passed\n"); - return 0; + status = test_reboot(LINUX_REBOOT_CMD_CAD_ON, -1); + if (status >= 0) { + printf("reboot(LINUX_REBOOT_CMD_CAD_ON) should have failed\n"); + return 1; + } + printf("reboot(LINUX_REBOOT_CMD_CAD_ON) has failed as expected\n"); + + status = test_reboot(LINUX_REBOOT_CMD_RESTART, SIGHUP); + if (status < 0) + return 1; + printf("reboot(LINUX_REBOOT_CMD_RESTART) succeed\n"); + + status = test_reboot(LINUX_REBOOT_CMD_RESTART2, SIGHUP); + if (status < 0) + return 1; + printf("reboot(LINUX_REBOOT_CMD_RESTART2) succeed\n"); + + status = test_reboot(LINUX_REBOOT_CMD_HALT, SIGINT); + if (status < 0) + return 1; + printf("reboot(LINUX_REBOOT_CMD_HALT) succeed\n"); + + status = test_reboot(LINUX_REBOOT_CMD_POWER_OFF, SIGINT); + if (status < 0) + return 1; + printf("reboot(LINUX_REBOOT_CMD_POWERR_OFF) succeed\n"); + + printf("All tests passed\n"); + return 0; }