make conf_pasta_ns() exit immediately after logging error
As with conf_ports, this allows us to make the function return void. Signed-off-by: Laine Stump <laine@redhat.com> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
b20fe11b36
commit
fe2a54e86e
1 changed files with 11 additions and 24 deletions
33
conf.c
33
conf.c
|
@ -497,21 +497,15 @@ static int conf_netns_opt(char *netns, const char *arg)
|
||||||
* @optind: Index of first non-option argument
|
* @optind: Index of first non-option argument
|
||||||
* @argc: Number of arguments
|
* @argc: Number of arguments
|
||||||
* @argv: Command line arguments
|
* @argv: Command line arguments
|
||||||
*
|
|
||||||
* Return: 0 on success, negative error code otherwise
|
|
||||||
*/
|
*/
|
||||||
static int conf_pasta_ns(int *netns_only, char *userns, char *netns,
|
static void conf_pasta_ns(int *netns_only, char *userns, char *netns,
|
||||||
int optind, int argc, char *argv[])
|
int optind, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (*netns_only && *userns) {
|
if (*netns_only && *userns)
|
||||||
err("Both --userns and --netns-only given");
|
die("Both --userns and --netns-only given");
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*netns && optind != argc) {
|
if (*netns && optind != argc)
|
||||||
err("Both --netns and PID or command given");
|
die("Both --netns and PID or command given");
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (optind + 1 == argc) {
|
if (optind + 1 == argc) {
|
||||||
char *endptr;
|
char *endptr;
|
||||||
|
@ -520,10 +514,8 @@ static int conf_pasta_ns(int *netns_only, char *userns, char *netns,
|
||||||
pidval = strtol(argv[optind], &endptr, 10);
|
pidval = strtol(argv[optind], &endptr, 10);
|
||||||
if (!*endptr) {
|
if (!*endptr) {
|
||||||
/* Looks like a pid */
|
/* Looks like a pid */
|
||||||
if (pidval < 0 || pidval > INT_MAX) {
|
if (pidval < 0 || pidval > INT_MAX)
|
||||||
err("Invalid PID %s", argv[optind]);
|
die("Invalid PID %s", argv[optind]);
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(netns, PATH_MAX, "/proc/%ld/ns/net", pidval);
|
snprintf(netns, PATH_MAX, "/proc/%ld/ns/net", pidval);
|
||||||
if (!*userns)
|
if (!*userns)
|
||||||
|
@ -535,8 +527,6 @@ static int conf_pasta_ns(int *netns_only, char *userns, char *netns,
|
||||||
/* Attaching to a netns/PID, with no userns given */
|
/* Attaching to a netns/PID, with no userns given */
|
||||||
if (*netns && !*userns)
|
if (*netns && !*userns)
|
||||||
*netns_only = 1;
|
*netns_only = 1;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** conf_ip4_prefix() - Parse an IPv4 prefix length or netmask
|
/** conf_ip4_prefix() - Parse an IPv4 prefix length or netmask
|
||||||
|
@ -1560,13 +1550,10 @@ void conf(struct ctx *c, int argc, char **argv)
|
||||||
}
|
}
|
||||||
} while (name != -1);
|
} while (name != -1);
|
||||||
|
|
||||||
if (c->mode == MODE_PASTA) {
|
if (c->mode == MODE_PASTA)
|
||||||
if (conf_pasta_ns(&netns_only, userns, netns,
|
conf_pasta_ns(&netns_only, userns, netns, optind, argc, argv);
|
||||||
optind, argc, argv) < 0)
|
else if (optind != argc)
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
} else if (optind != argc) {
|
|
||||||
usage(argv[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
isolate_user(uid, gid, !netns_only, userns, c->mode);
|
isolate_user(uid, gid, !netns_only, userns, c->mode);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue