Something that really annoys me with zoneadm is that the syntax for its command line is different to the other new commands, ie the subommand comes after the zone name and the zone name needs to have a -z before it.
ugh. So I went and looked at zoneadm.c - it seems well enough structured to make hacking easy.. The attached diffs modify zoneadm to work like this: zoneadm boot fred At present my ability to test seems to be being challenged by networks problems/outages here at Sun, so please forgive me if there are some bugs (obvious or otherwise.) Feedback welcome. Darren p.s. no, there isn't an RFE for this yet...and I didn't see one when I looked during the week...
------- usr/src/cmd/zoneadm/zoneadm.c ------- Index: usr/src/cmd/zoneadm/zoneadm.c *** /biscuit/onnv/usr/src/cmd/zoneadm/zoneadm.c Thu May 29 12:48:36 2008 --- /biscuit/onnv_20080608/usr/src/cmd/zoneadm/zoneadm.c Sun Jun 8 17:49:37 2008 *************** *** 24,30 **** * Use is subject to license terms. */ ! #pragma ident "@(#)zoneadm.c 1.65 08/05/08 SMI" /* * zoneadm is a command interpreter for zone administration. It is all in --- 24,30 ---- * Use is subject to license terms. */ ! #pragma ident "@(#)zoneadm.c 1.66 08/06/08 SMI" /* * zoneadm is a command interpreter for zone administration. It is all in *************** *** 345,350 **** --- 345,352 ---- execname); (void) fprintf(fd, "\t%s {-z <zone>|-u <uuid-match>} <%s>\n", execname, gettext("subcommand")); + (void) fprintf(fd, "\t%s <%s> <zone>\n", execname, + gettext("subcommand")); (void) fprintf(fd, "\n%s:\n\n", gettext("Subcommands")); for (i = CMD_MIN; i <= CMD_MAX; i++) { if (cmdtab[i].short_usage == NULL) *************** *** 5944,5955 **** return (execbasename); } int main(int argc, char **argv) { int arg; zoneid_t zid; - struct stat st; char *zone_lock_env; int err; --- 5946,5972 ---- return (execbasename); } + static void + setroot(char *arg) + { + struct stat st; + + if (*optarg != '/') { + zerror(gettext("root path must be absolute.")); + exit(Z_ERR); + } + if (stat(optarg, &st) == -1 || !S_ISDIR(st.st_mode)) { + zerror(gettext("root path must be a directory.")); + exit(Z_ERR); + } + zonecfg_set_root(optarg); + } + int main(int argc, char **argv) { int arg; zoneid_t zid; char *zone_lock_env; int err; *************** *** 5968,6003 **** if (init_zfs() != Z_OK) exit(Z_ERR); ! while ((arg = getopt(argc, argv, "?u:z:R:")) != EOF) { ! switch (arg) { ! case '?': ! return (usage(B_TRUE)); ! case 'u': ! target_uuid = optarg; ! break; ! case 'z': ! target_zone = optarg; ! break; ! case 'R': /* private option for admin/install use */ ! if (*optarg != '/') { ! zerror(gettext("root path must be absolute.")); ! exit(Z_ERR); } - if (stat(optarg, &st) == -1 || !S_ISDIR(st.st_mode)) { - zerror( - gettext("root path must be a directory.")); - exit(Z_ERR); - } - zonecfg_set_root(optarg); - break; - default: - return (usage(B_FALSE)); } } - if (optind >= argc) - return (usage(B_FALSE)); - if (target_uuid != NULL && *target_uuid != '\0') { uuid_t uuid; static char newtarget[ZONENAME_MAX]; --- 5985,6026 ---- if (init_zfs() != Z_OK) exit(Z_ERR); ! if (argc >= 3 && *argv[1] != '-' && *argv[2] != '-') { ! /* ! * The syntax being looked for is: ! * zoneadm boot zonename ! * but the application expects it to be: ! * zoneadm -z zonename boot ! * so we swap boot/zonename around, swallow the first arg ! * as being the zonename and prepare to continue by bumping ! * optind up to point at the command arg. ! */ ! target_zone = argv[2]; ! argv[2] = argv[1]; ! optind++; ! } else { ! while ((arg = getopt(argc, argv, "?u:z:R:")) != EOF) { ! switch (arg) { ! case '?': ! return (usage(B_TRUE)); ! case 'u': ! target_uuid = optarg; ! break; ! case 'z': ! target_zone = optarg; ! break; ! case 'R': ! setroot(optarg); ! break; ! default: ! return (usage(B_FALSE)); } } + + if (optind >= argc) + return (usage(B_FALSE)); } if (target_uuid != NULL && *target_uuid != '\0') { uuid_t uuid; static char newtarget[ZONENAME_MAX];
_______________________________________________ zones-discuss mailing list zones-discuss@opensolaris.org