Unverified Commit 623cfa35 by Christian Brauner Committed by GitHub

Merge pull request #2468 from 2xsec/bugfix

tools: lxc-unshare: apply argument parser of lxc and log system of lxc
parents 94fd0bd6 35bfea7a
...@@ -115,6 +115,7 @@ pid_t lxc_raw_clone(unsigned long flags) ...@@ -115,6 +115,7 @@ pid_t lxc_raw_clone(unsigned long flags)
: "=r"(in_child), "=r"(child_pid) : "=r"(in_child), "=r"(child_pid)
: "i"(__NR_clone), "r"(flags | SIGCHLD) : "i"(__NR_clone), "r"(flags | SIGCHLD)
: "%o1", "%o0", "%g1"); : "%o1", "%o0", "%g1");
if (in_child) if (in_child)
return 0; return 0;
else else
...@@ -174,6 +175,7 @@ const struct ns_info ns_info[LXC_NS_MAX] = { ...@@ -174,6 +175,7 @@ const struct ns_info ns_info[LXC_NS_MAX] = {
int lxc_namespace_2_cloneflag(const char *namespace) int lxc_namespace_2_cloneflag(const char *namespace)
{ {
int i; int i;
for (i = 0; i < LXC_NS_MAX; i++) for (i = 0; i < LXC_NS_MAX; i++)
if (!strcasecmp(ns_info[i].proc_name, namespace)) if (!strcasecmp(ns_info[i].proc_name, namespace))
return ns_info[i].clone_flag; return ns_info[i].clone_flag;
...@@ -185,6 +187,7 @@ int lxc_namespace_2_cloneflag(const char *namespace) ...@@ -185,6 +187,7 @@ int lxc_namespace_2_cloneflag(const char *namespace)
int lxc_namespace_2_ns_idx(const char *namespace) int lxc_namespace_2_ns_idx(const char *namespace)
{ {
int i; int i;
for (i = 0; i < LXC_NS_MAX; i++) for (i = 0; i < LXC_NS_MAX; i++)
if (!strcmp(ns_info[i].proc_name, namespace)) if (!strcmp(ns_info[i].proc_name, namespace))
return i; return i;
...@@ -239,7 +242,6 @@ int lxc_fill_namespace_flags(char *flaglist, int *flags) ...@@ -239,7 +242,6 @@ int lxc_fill_namespace_flags(char *flaglist, int *flags)
token = strtok_r(flaglist, "|", &saveptr); token = strtok_r(flaglist, "|", &saveptr);
while (token) { while (token) {
aflag = lxc_namespace_2_cloneflag(token); aflag = lxc_namespace_2_cloneflag(token);
if (aflag < 0) if (aflag < 0)
return -1; return -1;
...@@ -248,5 +250,6 @@ int lxc_fill_namespace_flags(char *flaglist, int *flags) ...@@ -248,5 +250,6 @@ int lxc_fill_namespace_flags(char *flaglist, int *flags)
token = strtok_r(NULL, "|", &saveptr); token = strtok_r(NULL, "|", &saveptr);
} }
return 0; return 0;
} }
...@@ -50,7 +50,6 @@ static int build_shortopts(const struct option *a_options, char *a_shortopts, ...@@ -50,7 +50,6 @@ static int build_shortopts(const struct option *a_options, char *a_shortopts,
return -1; return -1;
for (opt = a_options; opt->name; opt++) { for (opt = a_options; opt->name; opt++) {
if (!isascii(opt->val)) if (!isascii(opt->val))
continue; continue;
...@@ -163,6 +162,7 @@ See the %s man page for further information.\n\n", ...@@ -163,6 +162,7 @@ See the %s man page for further information.\n\n",
if (args->helpfn) if (args->helpfn)
args->helpfn(args); args->helpfn(args);
exit(code); exit(code);
} }
...@@ -183,6 +183,7 @@ static int lxc_arguments_lxcpath_add(struct lxc_arguments *args, ...@@ -183,6 +183,7 @@ static int lxc_arguments_lxcpath_add(struct lxc_arguments *args,
lxc_error(args, "no memory"); lxc_error(args, "no memory");
return -ENOMEM; return -ENOMEM;
} }
args->lxcpath[args->lxcpath_cnt++] = lxcpath; args->lxcpath[args->lxcpath_cnt++] = lxcpath;
return 0; return 0;
} }
...@@ -207,6 +208,7 @@ extern int lxc_arguments_parse(struct lxc_arguments *args, int argc, ...@@ -207,6 +208,7 @@ extern int lxc_arguments_parse(struct lxc_arguments *args, int argc,
c = getopt_long(argc, argv, shortopts, args->options, &index); c = getopt_long(argc, argv, shortopts, args->options, &index);
if (c == -1) if (c == -1)
break; break;
switch (c) { switch (c) {
case 'n': case 'n':
args->name = optarg; args->name = optarg;
...@@ -261,7 +263,8 @@ extern int lxc_arguments_parse(struct lxc_arguments *args, int argc, ...@@ -261,7 +263,8 @@ extern int lxc_arguments_parse(struct lxc_arguments *args, int argc,
} }
/* Check the command options */ /* Check the command options */
if (!args->name && strcmp(args->progname, "lxc-autostart") != 0) { if (!args->name && strncmp(args->progname, "lxc-autostart", strlen(args->progname)) != 0
&& strncmp(args->progname, "lxc-unshare", strlen(args->progname)) != 0) {
if (args->argv) { if (args->argv) {
args->name = argv[optind]; args->name = argv[optind];
optind++; optind++;
...@@ -277,9 +280,11 @@ extern int lxc_arguments_parse(struct lxc_arguments *args, int argc, ...@@ -277,9 +280,11 @@ extern int lxc_arguments_parse(struct lxc_arguments *args, int argc,
if (args->checker) if (args->checker)
ret = args->checker(args); ret = args->checker(args);
error: error:
if (ret) if (ret)
lxc_error(args, "could not parse command line"); lxc_error(args, "could not parse command line");
return ret; return ret;
} }
......
...@@ -94,7 +94,7 @@ struct lxc_arguments { ...@@ -94,7 +94,7 @@ struct lxc_arguments {
char *rbdname, *rbdpool; char *rbdname, *rbdpool;
char *zfsroot, *lowerdir, *dir; char *zfsroot, *lowerdir, *dir;
/* lxc-execute */ /* lxc-execute and lxc-unshare */
uid_t uid; uid_t uid;
gid_t gid; gid_t gid;
...@@ -137,6 +137,12 @@ struct lxc_arguments { ...@@ -137,6 +137,12 @@ struct lxc_arguments {
/* lxc-copy */ /* lxc-copy */
bool tmpfs; bool tmpfs;
/* lxc-unshare */
int flags;
int want_default_mounts;
const char *want_hostname;
bool setuid;
/* remaining arguments */ /* remaining arguments */
char *const *argv; char *const *argv;
int argc; int argc;
......
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