Commit 0402866c by Stéphane Graber

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: 's avatarStéphane Graber <stgraber@ubuntu.com>
parent d6e179bb
...@@ -71,7 +71,7 @@ int lxc_caps_down(void) ...@@ -71,7 +71,7 @@ int lxc_caps_down(void)
out: out:
cap_free(caps); cap_free(caps);
return 0; return 0;
} }
int lxc_caps_up(void) int lxc_caps_up(void)
...@@ -121,7 +121,7 @@ int lxc_caps_up(void) ...@@ -121,7 +121,7 @@ int lxc_caps_up(void)
out: out:
cap_free(caps); cap_free(caps);
return 0; return 0;
} }
int lxc_caps_init(void) int lxc_caps_init(void)
......
...@@ -33,17 +33,17 @@ extern int lxc_caps_init(void); ...@@ -33,17 +33,17 @@ extern int lxc_caps_init(void);
extern int lxc_caps_last_cap(void); extern int lxc_caps_last_cap(void);
#else #else
static inline int lxc_caps_down(void) { static inline int lxc_caps_down(void) {
return 0; return 0;
} }
static inline int lxc_caps_up(void) { static inline int lxc_caps_up(void) {
return 0; return 0;
} }
static inline int lxc_caps_init(void) { static inline int lxc_caps_init(void) {
return 0; return 0;
} }
static inline int lxc_caps_last_cap(void) { static inline int lxc_caps_last_cap(void) {
return 0; return 0;
} }
#endif #endif
......
...@@ -122,13 +122,13 @@ static void cull_user_controllers(void); ...@@ -122,13 +122,13 @@ static void cull_user_controllers(void);
static void cgm_dbus_disconnect(void) static void cgm_dbus_disconnect(void)
{ {
if (cgroup_manager) { if (cgroup_manager) {
dbus_connection_flush(cgroup_manager->connection); dbus_connection_flush(cgroup_manager->connection);
dbus_connection_close(cgroup_manager->connection); dbus_connection_close(cgroup_manager->connection);
nih_free(cgroup_manager); nih_free(cgroup_manager);
} }
cgroup_manager = NULL; cgroup_manager = NULL;
cgm_unlock(); cgm_unlock();
} }
#define CGMANAGER_DBUS_SOCK "unix:path=/sys/fs/cgroup/cgmanager/sock" #define CGMANAGER_DBUS_SOCK "unix:path=/sys/fs/cgroup/cgmanager/sock"
......
...@@ -1095,10 +1095,10 @@ static int config_group(const char *key, const char *value, ...@@ -1095,10 +1095,10 @@ static int config_group(const char *key, const char *value,
/* in case several groups are specified in a single line /* in case several groups are specified in a single line
* split these groups in a single element for the list */ * split these groups in a single element for the list */
for (groupptr = groups;;groupptr = NULL) { for (groupptr = groups;;groupptr = NULL) {
token = strtok_r(groupptr, " \t", &sptr); token = strtok_r(groupptr, " \t", &sptr);
if (!token) { if (!token) {
ret = 0; ret = 0;
break; break;
} }
grouplist = malloc(sizeof(*grouplist)); grouplist = malloc(sizeof(*grouplist));
...@@ -1115,7 +1115,7 @@ static int config_group(const char *key, const char *value, ...@@ -1115,7 +1115,7 @@ static int config_group(const char *key, const char *value,
} }
lxc_list_add_tail(&lxc_conf->groups, grouplist); lxc_list_add_tail(&lxc_conf->groups, grouplist);
} }
free(groups); free(groups);
...@@ -1450,10 +1450,10 @@ static int config_mount_auto(const char *key, const char *value, ...@@ -1450,10 +1450,10 @@ static int config_mount_auto(const char *key, const char *value,
} }
for (autoptr = autos; ; autoptr = NULL) { for (autoptr = autos; ; autoptr = NULL) {
token = strtok_r(autoptr, " \t", &sptr); token = strtok_r(autoptr, " \t", &sptr);
if (!token) { if (!token) {
ret = 0; ret = 0;
break; break;
} }
for (i = 0; allowed_auto_mounts[i].token; i++) { for (i = 0; allowed_auto_mounts[i].token; i++) {
...@@ -1468,7 +1468,7 @@ static int config_mount_auto(const char *key, const char *value, ...@@ -1468,7 +1468,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].mask;
lxc_conf->auto_mounts |= allowed_auto_mounts[i].flag; lxc_conf->auto_mounts |= allowed_auto_mounts[i].flag;
} }
free(autos); free(autos);
...@@ -1519,10 +1519,10 @@ static int config_cap_keep(const char *key, const char *value, ...@@ -1519,10 +1519,10 @@ static int config_cap_keep(const char *key, const char *value,
/* in case several capability keep is specified in a single line /* in case several capability keep is specified in a single line
* split these caps in a single element for the list */ * split these caps in a single element for the list */
for (keepptr = keepcaps;;keepptr = NULL) { for (keepptr = keepcaps;;keepptr = NULL) {
token = strtok_r(keepptr, " \t", &sptr); token = strtok_r(keepptr, " \t", &sptr);
if (!token) { if (!token) {
ret = 0; ret = 0;
break; break;
} }
keeplist = malloc(sizeof(*keeplist)); keeplist = malloc(sizeof(*keeplist));
...@@ -1539,7 +1539,7 @@ static int config_cap_keep(const char *key, const char *value, ...@@ -1539,7 +1539,7 @@ static int config_cap_keep(const char *key, const char *value,
} }
lxc_list_add_tail(&lxc_conf->keepcaps, keeplist); lxc_list_add_tail(&lxc_conf->keepcaps, keeplist);
} }
free(keepcaps); free(keepcaps);
...@@ -1565,10 +1565,10 @@ static int config_cap_drop(const char *key, const char *value, ...@@ -1565,10 +1565,10 @@ static int config_cap_drop(const char *key, const char *value,
/* in case several capability drop is specified in a single line /* in case several capability drop is specified in a single line
* split these caps in a single element for the list */ * split these caps in a single element for the list */
for (dropptr = dropcaps;;dropptr = NULL) { for (dropptr = dropcaps;;dropptr = NULL) {
token = strtok_r(dropptr, " \t", &sptr); token = strtok_r(dropptr, " \t", &sptr);
if (!token) { if (!token) {
ret = 0; ret = 0;
break; break;
} }
droplist = malloc(sizeof(*droplist)); droplist = malloc(sizeof(*droplist));
...@@ -1585,7 +1585,7 @@ static int config_cap_drop(const char *key, const char *value, ...@@ -1585,7 +1585,7 @@ static int config_cap_drop(const char *key, const char *value,
} }
lxc_list_add_tail(&lxc_conf->caps, droplist); lxc_list_add_tail(&lxc_conf->caps, droplist);
} }
free(dropcaps); free(dropcaps);
...@@ -1814,7 +1814,7 @@ int lxc_fill_elevated_privileges(char *flaglist, int *flags) ...@@ -1814,7 +1814,7 @@ int lxc_fill_elevated_privileges(char *flaglist, int *flags)
/* for the sake of backward compatibility, drop all privileges /* for the sake of backward compatibility, drop all privileges
if none is specified */ if none is specified */
for (i = 0; all_privs[i].token; i++) { for (i = 0; all_privs[i].token; i++) {
*flags |= all_privs[i].flag; *flags |= all_privs[i].flag;
} }
return 0; return 0;
} }
......
...@@ -53,10 +53,10 @@ static int genetlink_resolve_family(const char *family) ...@@ -53,10 +53,10 @@ static int genetlink_resolve_family(const char *family)
request->nlmsghdr.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN); request->nlmsghdr.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN);
request->nlmsghdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; 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 = NLMSG_DATA(&request->nlmsghdr);
genlmsghdr->cmd = CTRL_CMD_GETFAMILY; genlmsghdr->cmd = CTRL_CMD_GETFAMILY;
ret = netlink_open(&handler, NETLINK_GENERIC); ret = netlink_open(&handler, NETLINK_GENERIC);
if (ret) if (ret)
......
...@@ -59,7 +59,7 @@ struct genlmsg { ...@@ -59,7 +59,7 @@ struct genlmsg {
static inline int genetlink_len(const struct genlmsg *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);
} }
/* /*
......
...@@ -72,10 +72,10 @@ static inline void __lxc_list_add(struct lxc_list *new, ...@@ -72,10 +72,10 @@ static inline void __lxc_list_add(struct lxc_list *new,
struct lxc_list *prev, struct lxc_list *prev,
struct lxc_list *next) struct lxc_list *next)
{ {
next->prev = new; next->prev = new;
new->next = next; new->next = next;
new->prev = prev; new->prev = prev;
prev->next = new; prev->next = new;
} }
static inline void lxc_list_add(struct lxc_list *head, struct lxc_list *list) static inline void lxc_list_add(struct lxc_list *head, struct lxc_list *list)
......
...@@ -113,12 +113,12 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg) ...@@ -113,12 +113,12 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
/* -s implies -e */ /* -s implies -e */
lxc_fill_elevated_privileges(NULL, &elevated_privileges); lxc_fill_elevated_privileges(NULL, &elevated_privileges);
break; break;
case 500: /* clear-env */ case 500: /* clear-env */
env_policy = LXC_ATTACH_CLEAR_ENV; env_policy = LXC_ATTACH_CLEAR_ENV;
break; break;
case 501: /* keep-env */ case 501: /* keep-env */
env_policy = LXC_ATTACH_KEEP_ENV; env_policy = LXC_ATTACH_KEEP_ENV;
break; break;
case 502: /* keep-var */ case 502: /* keep-var */
ret = add_to_simple_array(&extra_keep, &extra_keep_size, arg); ret = add_to_simple_array(&extra_keep, &extra_keep_size, arg);
if (ret < 0) { if (ret < 0) {
......
...@@ -117,7 +117,7 @@ int main(int argc, char *argv[]) ...@@ -117,7 +117,7 @@ int main(int argc, char *argv[])
aargv = &argv[optind]; aargv = &argv[optind];
/* /*
* mask all the signals so we are safe to install a * mask all the signals so we are safe to install a
* signal handler and to fork * signal handler and to fork
*/ */
......
...@@ -190,7 +190,7 @@ Options :\n\ ...@@ -190,7 +190,7 @@ Options :\n\
-L, --console-log=FILE Log container console output to FILE\n\ -L, --console-log=FILE Log container console output to FILE\n\
-C, --close-all-fds If any fds are inherited, close them\n\ -C, --close-all-fds If any fds are inherited, close them\n\
If not specified, exit with failure instead\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\ -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\ --share-[net|ipc|uts]=NAME Share a namespace with another container or pid\n\
", ",
......
...@@ -115,8 +115,8 @@ struct start_arg { ...@@ -115,8 +115,8 @@ struct start_arg {
int *flags; int *flags;
uid_t *uid; uid_t *uid;
bool setuid; bool setuid;
int want_default_mounts; int want_default_mounts;
const char *want_hostname; const char *want_hostname;
}; };
static int do_start(void *arg) static int do_start(void *arg)
......
...@@ -2603,7 +2603,7 @@ static int create_file_dirname(char *path, struct lxc_conf *conf) ...@@ -2603,7 +2603,7 @@ static int create_file_dirname(char *path, struct lxc_conf *conf)
if (!p) if (!p)
return -1; return -1;
*p = '\0'; *p = '\0';
ret = do_create_container_dir(path, conf); ret = do_create_container_dir(path, conf);
*p = '/'; *p = '/';
return ret; return ret;
} }
......
...@@ -763,17 +763,17 @@ struct lxc_snapshot { ...@@ -763,17 +763,17 @@ struct lxc_snapshot {
* \brief Specifications for how to create a new backing store * \brief Specifications for how to create a new backing store
*/ */
struct bdev_specs { struct bdev_specs {
char *fstype; /*!< Filesystem type */ char *fstype; /*!< Filesystem type */
uint64_t fssize; /*!< Filesystem size in bytes */ uint64_t fssize; /*!< Filesystem size in bytes */
struct { struct {
char *zfsroot; /*!< ZFS root path */ char *zfsroot; /*!< ZFS root path */
} zfs; } zfs;
struct { struct {
char *vg; /*!< LVM Volume Group name */ char *vg; /*!< LVM Volume Group name */
char *lv; /*!< LVM Logical Volume name */ char *lv; /*!< LVM Logical Volume name */
char *thinpool; /*!< LVM thin pool to use, if any */ char *thinpool; /*!< LVM thin pool to use, if any */
} lvm; } lvm;
char *dir; /*!< Directory path */ char *dir; /*!< Directory path */
}; };
/*! /*!
......
...@@ -74,7 +74,7 @@ extern int nla_put_buffer(struct nlmsg *nlmsg, int attr, ...@@ -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) 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) extern int nla_put_u32(struct nlmsg *nlmsg, int attr, int value)
...@@ -173,23 +173,23 @@ extern void nlmsg_free(struct nlmsg *nlmsg) ...@@ -173,23 +173,23 @@ extern void nlmsg_free(struct nlmsg *nlmsg)
extern int netlink_rcv(struct nl_handler *handler, struct nlmsg *answer) extern int netlink_rcv(struct nl_handler *handler, struct nlmsg *answer)
{ {
int ret; int ret;
struct sockaddr_nl nladdr; struct sockaddr_nl nladdr;
struct iovec iov = { struct iovec iov = {
.iov_base = answer->nlmsghdr, .iov_base = answer->nlmsghdr,
.iov_len = answer->nlmsghdr->nlmsg_len, .iov_len = answer->nlmsghdr->nlmsg_len,
}; };
struct msghdr msg = { struct msghdr msg = {
.msg_name = &nladdr, .msg_name = &nladdr,
.msg_namelen = sizeof(nladdr), .msg_namelen = sizeof(nladdr),
.msg_iov = &iov, .msg_iov = &iov,
.msg_iovlen = 1, .msg_iovlen = 1,
}; };
memset(&nladdr, 0, sizeof(nladdr)); memset(&nladdr, 0, sizeof(nladdr));
nladdr.nl_family = AF_NETLINK; nladdr.nl_family = AF_NETLINK;
nladdr.nl_pid = 0; nladdr.nl_pid = 0;
nladdr.nl_groups = 0; nladdr.nl_groups = 0;
again: again:
ret = recvmsg(handler->fd, &msg, 0); ret = recvmsg(handler->fd, &msg, 0);
...@@ -211,23 +211,23 @@ again: ...@@ -211,23 +211,23 @@ again:
extern int netlink_send(struct nl_handler *handler, struct nlmsg *nlmsg) extern int netlink_send(struct nl_handler *handler, struct nlmsg *nlmsg)
{ {
struct sockaddr_nl nladdr; struct sockaddr_nl nladdr;
struct iovec iov = { struct iovec iov = {
.iov_base = nlmsg->nlmsghdr, .iov_base = nlmsg->nlmsghdr,
.iov_len = nlmsg->nlmsghdr->nlmsg_len, .iov_len = nlmsg->nlmsghdr->nlmsg_len,
}; };
struct msghdr msg = { struct msghdr msg = {
.msg_name = &nladdr, .msg_name = &nladdr,
.msg_namelen = sizeof(nladdr), .msg_namelen = sizeof(nladdr),
.msg_iov = &iov, .msg_iov = &iov,
.msg_iovlen = 1, .msg_iovlen = 1,
}; };
int ret; int ret;
memset(&nladdr, 0, sizeof(nladdr)); memset(&nladdr, 0, sizeof(nladdr));
nladdr.nl_family = AF_NETLINK; nladdr.nl_family = AF_NETLINK;
nladdr.nl_pid = 0; nladdr.nl_pid = 0;
nladdr.nl_groups = 0; nladdr.nl_groups = 0;
ret = sendmsg(handler->fd, &msg, 0); ret = sendmsg(handler->fd, &msg, 0);
if (ret < 0) if (ret < 0)
...@@ -263,45 +263,45 @@ extern int netlink_transaction(struct nl_handler *handler, ...@@ -263,45 +263,45 @@ extern int netlink_transaction(struct nl_handler *handler,
extern int netlink_open(struct nl_handler *handler, int protocol) extern int netlink_open(struct nl_handler *handler, int protocol)
{ {
socklen_t socklen; socklen_t socklen;
int sndbuf = 32768; int sndbuf = 32768;
int rcvbuf = 32768; int rcvbuf = 32768;
memset(handler, 0, sizeof(*handler)); memset(handler, 0, sizeof(*handler));
handler->fd = socket(AF_NETLINK, SOCK_RAW, protocol); handler->fd = socket(AF_NETLINK, SOCK_RAW, protocol);
if (handler->fd < 0) if (handler->fd < 0)
return -errno; return -errno;
if (setsockopt(handler->fd, SOL_SOCKET, SO_SNDBUF, if (setsockopt(handler->fd, SOL_SOCKET, SO_SNDBUF,
&sndbuf, sizeof(sndbuf)) < 0) &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) &rcvbuf,sizeof(rcvbuf)) < 0)
return -errno; return -errno;
memset(&handler->local, 0, sizeof(handler->local)); memset(&handler->local, 0, sizeof(handler->local));
handler->local.nl_family = AF_NETLINK; handler->local.nl_family = AF_NETLINK;
handler->local.nl_groups = 0; 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) sizeof(handler->local)) < 0)
return -errno; return -errno;
socklen = sizeof(handler->local); socklen = sizeof(handler->local);
if (getsockname(handler->fd, (struct sockaddr*)&handler->local, if (getsockname(handler->fd, (struct sockaddr*)&handler->local,
&socklen) < 0) &socklen) < 0)
return -errno; return -errno;
if (socklen != sizeof(handler->local)) if (socklen != sizeof(handler->local))
return -EINVAL; return -EINVAL;
if (handler->local.nl_family != AF_NETLINK) if (handler->local.nl_family != AF_NETLINK)
return -EINVAL; return -EINVAL;
handler->seq = time(NULL); handler->seq = time(NULL);
return 0; return 0;
} }
extern int netlink_close(struct nl_handler *handler) extern int netlink_close(struct nl_handler *handler)
......
...@@ -46,10 +46,10 @@ ...@@ -46,10 +46,10 @@
* @peer: the peer address * @peer: the peer address
*/ */
struct nl_handler { struct nl_handler {
int fd; int fd;
int seq; int seq;
struct sockaddr_nl local; struct sockaddr_nl local;
struct sockaddr_nl peer; struct sockaddr_nl peer;
}; };
/* /*
......
...@@ -505,10 +505,10 @@ static void lxc_abort(const char *name, struct lxc_handler *handler) ...@@ -505,10 +505,10 @@ static void lxc_abort(const char *name, struct lxc_handler *handler)
*/ */
static int container_reboot_supported(void *arg) static int container_reboot_supported(void *arg)
{ {
int *cmd = arg; int *cmd = arg;
int ret; int ret;
ret = reboot(*cmd); ret = reboot(*cmd);
if (ret == -1 && errno == EINVAL) if (ret == -1 && errno == EINVAL)
return 1; return 1;
return 0; return 0;
...@@ -518,10 +518,10 @@ static int must_drop_cap_sys_boot(struct lxc_conf *conf) ...@@ -518,10 +518,10 @@ static int must_drop_cap_sys_boot(struct lxc_conf *conf)
{ {
FILE *f; FILE *f;
int ret, cmd, v, flags; int ret, cmd, v, flags;
long stack_size = 4096; long stack_size = 4096;
void *stack = alloca(stack_size); void *stack = alloca(stack_size);
int status; int status;
pid_t pid; pid_t pid;
f = fopen("/proc/sys/kernel/ctrl-alt-del", "r"); f = fopen("/proc/sys/kernel/ctrl-alt-del", "r");
if (!f) { if (!f) {
...@@ -621,7 +621,7 @@ static int do_start(void *data) ...@@ -621,7 +621,7 @@ static int do_start(void *data)
return -1; 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 * dies before we set the parent death signal, we will detect
* its death with the synchro right after, otherwise we have * its death with the synchro right after, otherwise we have
* a window where the parent can exit before we set the pdeath * a window where the parent can exit before we set the pdeath
...@@ -1102,7 +1102,7 @@ int __lxc_start(const char *name, struct lxc_conf *conf, ...@@ -1102,7 +1102,7 @@ int __lxc_start(const char *name, struct lxc_conf *conf,
* lxc-execute which simply exited. In any case, treat * lxc-execute which simply exited. In any case, treat
* it as a 'halt' * it as a 'halt'
*/ */
if (WIFSIGNALED(status)) { if (WIFSIGNALED(status)) {
switch(WTERMSIG(status)) { switch(WTERMSIG(status)) {
case SIGINT: /* halt */ case SIGINT: /* halt */
DEBUG("Container halting"); DEBUG("Container halting");
...@@ -1118,7 +1118,7 @@ int __lxc_start(const char *name, struct lxc_conf *conf, ...@@ -1118,7 +1118,7 @@ int __lxc_start(const char *name, struct lxc_conf *conf,
DEBUG("unknown exit status for init: %d", WTERMSIG(status)); DEBUG("unknown exit status for init: %d", WTERMSIG(status));
break; break;
} }
} }
DEBUG("Pushing physical nics back to host namespace"); DEBUG("Pushing physical nics back to host namespace");
lxc_rename_phys_nics_on_shutdown(netnsfd, handler->conf); lxc_rename_phys_nics_on_shutdown(netnsfd, handler->conf);
......
...@@ -85,8 +85,8 @@ static void do_function(void *arguments) ...@@ -85,8 +85,8 @@ static void do_function(void *arguments)
} }
if (debug) { if (debug) {
c->set_config_item(c, "lxc.loglevel", "DEBUG"); c->set_config_item(c, "lxc.loglevel", "DEBUG");
c->set_config_item(c, "lxc.logfile", name); c->set_config_item(c, "lxc.logfile", name);
} }
if (strcmp(args->mode, "create") == 0) { if (strcmp(args->mode, "create") == 0) {
...@@ -132,7 +132,7 @@ static void do_function(void *arguments) ...@@ -132,7 +132,7 @@ static void do_function(void *arguments)
out: out:
lxc_container_put(c); lxc_container_put(c);
if (debug) if (debug)
lxc_log_close(); lxc_log_close();
} }
static void *concurrent(void *arguments) static void *concurrent(void *arguments)
...@@ -171,9 +171,9 @@ int main(int argc, char *argv[]) { ...@@ -171,9 +171,9 @@ int main(int argc, char *argv[]) {
case 'q': case 'q':
quiet = 1; quiet = 1;
break; break;
case 'D': case 'D':
debug = 1; debug = 1;
break; break;
case 'm': { case 'm': {
char *mode_tok, *tok, *saveptr = NULL; char *mode_tok, *tok, *saveptr = NULL;
...@@ -187,10 +187,10 @@ int main(int argc, char *argv[]) { ...@@ -187,10 +187,10 @@ int main(int argc, char *argv[]) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
modes[i] = tok; modes[i] = tok;
} }
modes[i] = NULL; modes[i] = NULL;
break; break;
} }
default: /* '?' */ default: /* '?' */
usage(); usage();
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
......
...@@ -35,43 +35,43 @@ int clone(int (*fn)(void *), void *child_stack, int flags, void *arg, ...); ...@@ -35,43 +35,43 @@ int clone(int (*fn)(void *), void *child_stack, int flags, void *arg, ...);
static int do_reboot(void *arg) static int do_reboot(void *arg)
{ {
int *cmd = arg; int *cmd = arg;
if (reboot(*cmd)) if (reboot(*cmd))
printf("failed to reboot(%d): %m\n", *cmd); printf("failed to reboot(%d): %m\n", *cmd);
return 0; return 0;
} }
static int test_reboot(int cmd, int sig) static int test_reboot(int cmd, int sig)
{ {
long stack_size = 4096; long stack_size = 4096;
void *stack = alloca(stack_size) + stack_size; void *stack = alloca(stack_size) + stack_size;
int status; int status;
pid_t ret; pid_t ret;
ret = clone(do_reboot, stack, CLONE_NEWPID | SIGCHLD, &cmd); ret = clone(do_reboot, stack, CLONE_NEWPID | SIGCHLD, &cmd);
if (ret < 0) { if (ret < 0) {
printf("failed to clone: %m\n"); printf("failed to clone: %m\n");
return -1; return -1;
} }
if (wait(&status) < 0) { if (wait(&status) < 0) {
printf("unexpected wait error: %m\n"); printf("unexpected wait error: %m\n");
return -1; return -1;
} }
if (!WIFSIGNALED(status)) { if (!WIFSIGNALED(status)) {
if (sig != -1) if (sig != -1)
printf("child process exited but was not signaled\n"); printf("child process exited but was not signaled\n");
return -1; return -1;
} }
if (WTERMSIG(status) != sig) { if (WTERMSIG(status) != sig) {
printf("signal termination is not the one expected\n"); printf("signal termination is not the one expected\n");
return -1; return -1;
} }
return 0; return 0;
} }
static int have_reboot_patch(void) static int have_reboot_patch(void)
...@@ -95,46 +95,46 @@ static int have_reboot_patch(void) ...@@ -95,46 +95,46 @@ static int have_reboot_patch(void)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int status; int status;
if (getuid() != 0) { if (getuid() != 0) {
printf("Must run as root.\n"); printf("Must run as root.\n");
return 1; return 1;
} }
status = have_reboot_patch(); status = have_reboot_patch();
if (status != 0) { if (status != 0) {
printf("Your kernel does not have the container reboot patch\n"); printf("Your kernel does not have the container reboot patch\n");
return 1; return 1;
} }
status = test_reboot(LINUX_REBOOT_CMD_CAD_ON, -1); status = test_reboot(LINUX_REBOOT_CMD_CAD_ON, -1);
if (status >= 0) { if (status >= 0) {
printf("reboot(LINUX_REBOOT_CMD_CAD_ON) should have failed\n"); printf("reboot(LINUX_REBOOT_CMD_CAD_ON) should have failed\n");
return 1; return 1;
} }
printf("reboot(LINUX_REBOOT_CMD_CAD_ON) has failed as expected\n"); printf("reboot(LINUX_REBOOT_CMD_CAD_ON) has failed as expected\n");
status = test_reboot(LINUX_REBOOT_CMD_RESTART, SIGHUP); status = test_reboot(LINUX_REBOOT_CMD_RESTART, SIGHUP);
if (status < 0) if (status < 0)
return 1; return 1;
printf("reboot(LINUX_REBOOT_CMD_RESTART) succeed\n"); printf("reboot(LINUX_REBOOT_CMD_RESTART) succeed\n");
status = test_reboot(LINUX_REBOOT_CMD_RESTART2, SIGHUP); status = test_reboot(LINUX_REBOOT_CMD_RESTART2, SIGHUP);
if (status < 0) if (status < 0)
return 1; return 1;
printf("reboot(LINUX_REBOOT_CMD_RESTART2) succeed\n"); printf("reboot(LINUX_REBOOT_CMD_RESTART2) succeed\n");
status = test_reboot(LINUX_REBOOT_CMD_HALT, SIGINT); status = test_reboot(LINUX_REBOOT_CMD_HALT, SIGINT);
if (status < 0) if (status < 0)
return 1; return 1;
printf("reboot(LINUX_REBOOT_CMD_HALT) succeed\n"); printf("reboot(LINUX_REBOOT_CMD_HALT) succeed\n");
status = test_reboot(LINUX_REBOOT_CMD_POWER_OFF, SIGINT); status = test_reboot(LINUX_REBOOT_CMD_POWER_OFF, SIGINT);
if (status < 0) if (status < 0)
return 1; return 1;
printf("reboot(LINUX_REBOOT_CMD_POWERR_OFF) succeed\n"); printf("reboot(LINUX_REBOOT_CMD_POWERR_OFF) succeed\n");
printf("All tests passed\n"); printf("All tests passed\n");
return 0; return 0;
} }
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