bectl(8): Consistent style
This commit is contained in:
parent
193203b498
commit
b4e1235d02
@ -59,8 +59,9 @@ libbe_handle_t *be;
|
||||
static int
|
||||
usage(bool explicit)
|
||||
{
|
||||
FILE *fp = explicit ? stdout : stderr;
|
||||
FILE *fp;
|
||||
|
||||
fp = explicit ? stdout : stderr;
|
||||
fprintf(fp,
|
||||
"usage:\tbectl ( -h | -? | subcommand [args...] )\n"
|
||||
"\tbectl activate [-t] beName\n"
|
||||
@ -109,8 +110,9 @@ static struct command_map_entry command_map[] =
|
||||
static int
|
||||
get_cmd_index(char *cmd, int *index)
|
||||
{
|
||||
int map_size = sizeof(command_map) / sizeof(struct command_map_entry);
|
||||
int map_size;
|
||||
|
||||
map_size = nitems(command_map);
|
||||
for (int i = 0; i < map_size; ++i) {
|
||||
if (strcmp(cmd, command_map[i].command) == 0) {
|
||||
*index = i;
|
||||
@ -125,9 +127,9 @@ get_cmd_index(char *cmd, int *index)
|
||||
static int
|
||||
bectl_cmd_activate(int argc, char *argv[])
|
||||
{
|
||||
char *bootenv;
|
||||
int err, opt;
|
||||
bool temp;
|
||||
char *bootenv;
|
||||
|
||||
temp = false;
|
||||
while ((opt = getopt(argc, argv, "t")) != -1) {
|
||||
@ -152,31 +154,29 @@ bectl_cmd_activate(int argc, char *argv[])
|
||||
|
||||
|
||||
/* activate logic goes here */
|
||||
if ((err = be_activate(be, argv[0], temp)) != 0) {
|
||||
// TODO: more specific error msg based on err
|
||||
if ((err = be_activate(be, argv[0], temp)) != 0)
|
||||
/* XXX TODO: more specific error msg based on err */
|
||||
printf("did not successfully activate boot environment %s\n",
|
||||
argv[0]);
|
||||
} else {
|
||||
else
|
||||
printf("successfully activated boot environment %s\n", argv[0]);
|
||||
}
|
||||
|
||||
if (temp) {
|
||||
if (temp)
|
||||
printf("for next boot\n");
|
||||
}
|
||||
|
||||
return (err);
|
||||
}
|
||||
|
||||
|
||||
// TODO: when only one arg is given, and it contains an "@" the this should
|
||||
// create that snapshot
|
||||
/*
|
||||
* TODO: when only one arg is given, and it contains an "@" the this should
|
||||
* create that snapshot
|
||||
*/
|
||||
static int
|
||||
bectl_cmd_create(int argc, char *argv[])
|
||||
{
|
||||
char *bootenv, *snapname, *source;
|
||||
int err, opt;
|
||||
char *snapname;
|
||||
char *bootenv;
|
||||
char *source;
|
||||
|
||||
snapname = NULL;
|
||||
while ((opt = getopt(argc, argv, "e:")) != -1) {
|
||||
@ -202,40 +202,36 @@ bectl_cmd_create(int argc, char *argv[])
|
||||
bootenv = *argv;
|
||||
|
||||
if (snapname != NULL) {
|
||||
if (strchr(snapname, '@') != NULL) {
|
||||
if (strchr(snapname, '@') != NULL)
|
||||
err = be_create_from_existing_snap(be, bootenv,
|
||||
snapname);
|
||||
} else {
|
||||
else
|
||||
err = be_create_from_existing(be, bootenv, snapname);
|
||||
}
|
||||
} else {
|
||||
if ((snapname = strchr(bootenv, '@')) != NULL) {
|
||||
*(snapname++) = '\0';
|
||||
if ((err = be_snapshot(be, (char *)be_active_path(be),
|
||||
snapname, true, NULL)) != BE_ERR_SUCCESS) {
|
||||
snapname, true, NULL)) != BE_ERR_SUCCESS)
|
||||
fprintf(stderr, "failed to create snapshot\n");
|
||||
}
|
||||
asprintf(&source, "%s@%s", be_active_path(be), snapname);
|
||||
err = be_create_from_existing_snap(be, bootenv,
|
||||
source);
|
||||
return (err);
|
||||
} else {
|
||||
} else
|
||||
err = be_create(be, bootenv);
|
||||
}
|
||||
}
|
||||
|
||||
switch (err) {
|
||||
case BE_ERR_SUCCESS:
|
||||
break;
|
||||
default:
|
||||
if (snapname == NULL) {
|
||||
if (snapname == NULL)
|
||||
fprintf(stderr,
|
||||
"failed to create bootenv %s\n", bootenv);
|
||||
} else {
|
||||
else
|
||||
fprintf(stderr,
|
||||
"failed to create bootenv %s from snapshot %s\n",
|
||||
bootenv, snapname);
|
||||
}
|
||||
}
|
||||
|
||||
return (err);
|
||||
@ -245,9 +241,8 @@ bectl_cmd_create(int argc, char *argv[])
|
||||
static int
|
||||
bectl_cmd_export(int argc, char *argv[])
|
||||
{
|
||||
int opt;
|
||||
char *bootenv;
|
||||
|
||||
int opt;
|
||||
|
||||
if (argc == 1) {
|
||||
fprintf(stderr, "bectl export: missing boot environment name\n");
|
||||
@ -278,13 +273,11 @@ bectl_cmd_import(int argc, char *argv[])
|
||||
char *bootenv;
|
||||
int err;
|
||||
|
||||
|
||||
if (argc == 1) {
|
||||
fprintf(stderr, "bectl import: missing boot environment name\n");
|
||||
return (usage(false));
|
||||
}
|
||||
|
||||
|
||||
if (argc > 2) {
|
||||
fprintf(stderr, "bectl import: extra arguments provided\n");
|
||||
return (usage(false));
|
||||
@ -315,7 +308,7 @@ bectl_cmd_add(int argc, char *argv[])
|
||||
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
printf("arg %d: %s\n", i, argv[i]);
|
||||
// TODO catch err
|
||||
/* XXX TODO catch err */
|
||||
be_add_child(be, argv[i], true);
|
||||
}
|
||||
|
||||
@ -326,9 +319,9 @@ bectl_cmd_add(int argc, char *argv[])
|
||||
static int
|
||||
bectl_cmd_destroy(int argc, char *argv[])
|
||||
{
|
||||
char *target;
|
||||
int opt, err;
|
||||
bool force;
|
||||
char *target;
|
||||
|
||||
force = false;
|
||||
while ((opt = getopt(argc, argv, "F")) != -1) {
|
||||
@ -367,7 +360,7 @@ bectl_cmd_jail(int argc, char *argv[])
|
||||
char buf[BE_MAXPATHLEN*2];
|
||||
int err, jid;
|
||||
|
||||
//struct jail be_jail = { 0 };
|
||||
/* struct jail be_jail = { 0 }; */
|
||||
|
||||
if (argc == 1) {
|
||||
fprintf(stderr, "bectl jail: missing boot environment name\n");
|
||||
@ -380,17 +373,23 @@ bectl_cmd_jail(int argc, char *argv[])
|
||||
|
||||
bootenv = argv[1];
|
||||
|
||||
// TODO: if its already mounted, perhaps there should be a flag to
|
||||
// indicate its okay to proceed??
|
||||
if ((err = be_mount(be, bootenv, NULL, 0, mnt_loc)) != BE_ERR_SUCCESS) {
|
||||
/*
|
||||
* XXX TODO: if its already mounted, perhaps there should be a flag to
|
||||
* indicate its okay to proceed??
|
||||
*/
|
||||
if ((err = be_mount(be, bootenv, NULL, 0, mnt_loc)) != BE_ERR_SUCCESS)
|
||||
fprintf(stderr, "could not mount bootenv\n");
|
||||
}
|
||||
|
||||
// NOTE: this is not quite functional:
|
||||
// see https://github.com/vermaden/beadm/blob/master/HOWTO.htm on
|
||||
// neccesary modifications to correctly boot the jail
|
||||
/*
|
||||
* NOTE: this is not quite functional:
|
||||
* see https://github.com/vermaden/beadm/blob/master/HOWTO.htm on
|
||||
* neccesary modifications to correctly boot the jail
|
||||
*/
|
||||
|
||||
//snprintf(buf, BE_MAXPATHLEN*2, "jail %s %s %s /bin/sh /etc/rc", mnt_loc, bootenv, "192.168.1.123");
|
||||
/*
|
||||
* snprintf(buf, BE_MAXPATHLEN*2, "jail %s %s %s /bin/sh /etc/rc",
|
||||
* mnt_loc, bootenv, "192.168.1.123");
|
||||
*/
|
||||
snprintf(buf, BE_MAXPATHLEN*2, "jail %s %s %s /bin/sh", mnt_loc,
|
||||
bootenv, "192.168.1.123");
|
||||
system(buf);
|
||||
@ -418,10 +417,10 @@ bectl_cmd_jail(int argc, char *argv[])
|
||||
static int
|
||||
bectl_cmd_list(int argc, char *argv[])
|
||||
{
|
||||
int opt;
|
||||
bool show_all_datasets, show_space, hide_headers, show_snaps;
|
||||
char *bootenv;
|
||||
nvlist_t *props;
|
||||
int opt;
|
||||
bool show_all_datasets, show_space, hide_headers, show_snaps;
|
||||
|
||||
show_all_datasets = show_space = hide_headers = show_snaps = false;
|
||||
while ((opt = getopt(argc, argv, "aDHs")) != -1) {
|
||||
@ -452,8 +451,7 @@ bectl_cmd_list(int argc, char *argv[])
|
||||
return (usage(false));
|
||||
}
|
||||
|
||||
//props = be_get_bootenv_props(be);
|
||||
|
||||
/* props = be_get_bootenv_props(be); */
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -461,10 +459,9 @@ bectl_cmd_list(int argc, char *argv[])
|
||||
static int
|
||||
bectl_cmd_mount(int argc, char *argv[])
|
||||
{
|
||||
int err;
|
||||
char result_loc[BE_MAXPATHLEN];
|
||||
char *bootenv;
|
||||
char *mountpoint;
|
||||
char *bootenv, *mountpoint;
|
||||
int err;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "bectl mount: missing argument(s)\n");
|
||||
@ -479,7 +476,6 @@ bectl_cmd_mount(int argc, char *argv[])
|
||||
bootenv = argv[1];
|
||||
mountpoint = ((argc == 3) ? argv[2] : NULL);
|
||||
|
||||
|
||||
err = be_mount(be, bootenv, mountpoint, 0, result_loc);
|
||||
|
||||
switch (err) {
|
||||
@ -500,8 +496,7 @@ bectl_cmd_mount(int argc, char *argv[])
|
||||
static int
|
||||
bectl_cmd_rename(int argc, char *argv[])
|
||||
{
|
||||
char *src;
|
||||
char *dest;
|
||||
char *dest, *src;
|
||||
int err;
|
||||
|
||||
if (argc < 3) {
|
||||
@ -534,8 +529,8 @@ bectl_cmd_rename(int argc, char *argv[])
|
||||
static int
|
||||
bectl_cmd_unjail(int argc, char *argv[])
|
||||
{
|
||||
int opt;
|
||||
char *cmd, *target;
|
||||
int opt;
|
||||
bool force;
|
||||
|
||||
/* Store alias used */
|
||||
@ -565,7 +560,6 @@ bectl_cmd_unjail(int argc, char *argv[])
|
||||
target = argv[0];
|
||||
|
||||
/* unjail logic goes here */
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -573,8 +567,8 @@ bectl_cmd_unjail(int argc, char *argv[])
|
||||
static int
|
||||
bectl_cmd_unmount(int argc, char *argv[])
|
||||
{
|
||||
char *bootenv, *cmd;
|
||||
int err, flags, opt;
|
||||
char *cmd, *bootenv;
|
||||
|
||||
/* Store alias used */
|
||||
cmd = argv[0];
|
||||
@ -629,17 +623,14 @@ main(int argc, char *argv[])
|
||||
command = argv[1];
|
||||
|
||||
/* Handle command aliases */
|
||||
if (strcmp(command, "umount") == 0) {
|
||||
if (strcmp(command, "umount") == 0)
|
||||
command = "unmount";
|
||||
}
|
||||
|
||||
if (strcmp(command, "ujail") == 0) {
|
||||
if (strcmp(command, "ujail") == 0)
|
||||
command = "unjail";
|
||||
}
|
||||
|
||||
if ((strcmp(command, "-?") == 0) || (strcmp(command, "-h") == 0)) {
|
||||
if ((strcmp(command, "-?") == 0) || (strcmp(command, "-h") == 0))
|
||||
return (usage(true));
|
||||
}
|
||||
|
||||
if (get_cmd_index(command, &command_index)) {
|
||||
fprintf(stderr, "unknown command: %s\n", command);
|
||||
@ -647,17 +638,14 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
|
||||
if ((be = libbe_init()) == NULL) {
|
||||
if ((be = libbe_init()) == NULL)
|
||||
return (-1);
|
||||
}
|
||||
|
||||
libbe_print_on_error(be, true);
|
||||
|
||||
/* TODO: can be simplified if offset by 2 instead of one */
|
||||
/* XXX TODO: can be simplified if offset by 2 instead of one */
|
||||
rc = command_map[command_index].fn(argc-1, argv+1);
|
||||
|
||||
libbe_close(be);
|
||||
|
||||
|
||||
return (rc);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user