Changeset View
Changeset View
Standalone View
Standalone View
sbin/bectl/bectl_jail.c
Show First 20 Lines • Show All 438 Lines • ▼ Show 20 Lines | bectl_locate_jail(const char *ident) | ||||
} | } | ||||
return (-1); | return (-1); | ||||
} | } | ||||
int | int | ||||
bectl_cmd_unjail(int argc, char *argv[]) | bectl_cmd_unjail(int argc, char *argv[]) | ||||
{ | { | ||||
nvlist_t *belist; | |||||
char path[MAXPATHLEN]; | char path[MAXPATHLEN]; | ||||
char *cmd, *name, *target; | char *cmd, *name, *target; | ||||
int jid; | int jid; | ||||
/* Store alias used */ | /* Store alias used */ | ||||
cmd = argv[0]; | cmd = argv[0]; | ||||
if (argc != 2) { | if (argc != 2) { | ||||
Show All 17 Lines | if (jail_getv(0, "name", name, "path", path, NULL) != jid) { | ||||
fprintf(stderr, | fprintf(stderr, | ||||
"bectl %s: failed to get path for jail requested by '%s'\n", | "bectl %s: failed to get path for jail requested by '%s'\n", | ||||
cmd, target); | cmd, target); | ||||
return (1); | return (1); | ||||
} | } | ||||
free(name); | free(name); | ||||
if (be_mounted_at(be, path, NULL) != 0) { | bectl_jail_cleanup(path, jid); | ||||
if (be_prop_list_alloc(&belist) != 0) { | |||||
fprintf(stderr, "bectl %s: failed to allocate prop nvlist\n", cmd); | |||||
return (1); | |||||
} | |||||
if (be_mounted_at(be, path, belist) != 0) { | |||||
kevans: We can actually simplify this logic entirely and do it without `bename_from_path`, I believe… | |||||
fprintf(stderr, "bectl %s: jail requested by '%s' not a BE\n", | fprintf(stderr, "bectl %s: jail requested by '%s' not a BE\n", | ||||
cmd, target); | cmd, target); | ||||
return (1); | return (1); | ||||
} | } | ||||
bectl_jail_cleanup(path, jid); | nvlist_lookup_string(belist, "name", &name); | ||||
be_unmount(be, target, 0); | |||||
if (be_unmount(be, name, 0) != 0) { | |||||
fprintf(stderr, "bectl %s: failed to unmount %s at %s\n", | |||||
cmd, target, path); | |||||
return (1); | |||||
kevansUnsubmitted Not Done Inline ActionsLet's cleanup the belist here and in the above failure case, then call this good. kevans: Let's cleanup the `belist` here and in the above failure case, then call this good. | |||||
} | |||||
be_prop_list_free(belist); | |||||
return (0); | return (0); | ||||
} | } |
We can actually simplify this logic entirely and do it without bename_from_path, I believe -- that last parameter to be_mounted_at is an nvlist * that will contain the same details returned by be_get_bootenv_props -- just need to allocate the nvlist for it and snatch the name.