Illumos #2067: uninitialized variables in zfs(1M) may make snapshots undestroyable
[zfs.git] / cmd / zfs / zfs_main.c
index 444869a..e20d570 100644 (file)
@@ -229,7 +229,7 @@ get_usage(zfs_help_t idx)
                return (gettext("\tlist [-rH][-d max] "
                    "[-o property[,...]] [-t type[,...]] [-s property] ...\n"
                    "\t    [-S property] ... "
-                   "[filesystem|volume|snapshot] ...\n"));
+                   "[filesystem|volume|snapshot|snap] ...\n"));
        case HELP_MOUNT:
                return (gettext("\tmount\n"
                    "\tmount [-vO] [-o opts] <-a | filesystem>\n"));
@@ -254,7 +254,7 @@ get_usage(zfs_help_t idx)
        case HELP_SHARE:
                return (gettext("\tshare <-a | filesystem>\n"));
        case HELP_SNAPSHOT:
-               return (gettext("\tsnapshot [-r] [-o property=value] ... "
+               return (gettext("\tsnapshot|snap [-r] [-o property=value] ... "
                    "<filesystem@snapname|volume@snapname>\n"));
        case HELP_UNMOUNT:
                return (gettext("\tunmount [-f] "
@@ -572,7 +572,7 @@ zfs_do_clone(int argc, char **argv)
        zfs_handle_t *zhp = NULL;
        boolean_t parents = B_FALSE;
        nvlist_t *props;
-       int ret;
+       int ret = 0;
        int c;
 
        if (nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0)
@@ -1058,7 +1058,7 @@ zfs_do_destroy(int argc, char **argv)
         * named snapshot may not exist.  Go straight to libzfs.
         */
        if (cb.cb_recurse && (cp = strchr(argv[0], '@'))) {
-               int ret;
+               int ret = 0;
 
                *cp = '\0';
                if ((zhp = zfs_open(g_zfs, argv[0], ZFS_TYPE_DATASET)) == NULL)
@@ -1285,7 +1285,7 @@ zfs_do_get(int argc, char **argv)
        zprop_get_cbdata_t cb = { 0 };
        int i, c, flags = ZFS_ITER_ARGS_CAN_BE_PATHS;
        char *value, *fields;
-       int ret;
+       int ret = 0;
        int limit = 0;
        zprop_list_t fake_name = { 0 };
 
@@ -1522,7 +1522,7 @@ zfs_do_inherit(int argc, char **argv)
        zfs_prop_t prop;
        inherit_cbdata_t cb = { 0 };
        char *propname;
-       int ret;
+       int ret = 0;
        int flags = 0;
        boolean_t received = B_FALSE;
 
@@ -1728,7 +1728,7 @@ zfs_do_upgrade(int argc, char **argv)
 {
        boolean_t all = B_FALSE;
        boolean_t showversions = B_FALSE;
-       int ret;
+       int ret = 0;
        upgrade_cbdata_t cb = { 0 };
        signed char c;
        int flags = ZFS_ITER_ARGS_CAN_BE_PATHS;
@@ -2020,7 +2020,7 @@ userspace_cb(void *arg, const char *domain, uid_t rid, uint64_t space)
                char sid[ZFS_MAXNAMELEN+32];
                uid_t id;
                uint64_t classes;
-               int err;
+               int err = 0;
                directory_error_t e;
 
                (void) snprintf(sid, sizeof (sid), "%s-%u", domain, rid);
@@ -2374,7 +2374,7 @@ zfs_do_userspace(int argc, char **argv)
        boolean_t prtnum = B_FALSE;
        boolean_t parseable = B_FALSE;
        boolean_t sid2posix = B_FALSE;
-       int error;
+       int error = 0;
        int c;
        zfs_sort_column_t *default_sortcol = NULL;
        zfs_sort_column_t *sortcol = NULL;
@@ -2725,7 +2725,7 @@ zfs_do_list(int argc, char **argv)
        list_cbdata_t cb = { 0 };
        char *value;
        int limit = 0;
-       int ret;
+       int ret = 0;
        zfs_sort_column_t *sortcol = NULL;
        int flags = ZFS_ITER_PROP_LISTSNAPS | ZFS_ITER_ARGS_CAN_BE_PATHS;
 
@@ -2766,7 +2766,7 @@ zfs_do_list(int argc, char **argv)
                        flags &= ~ZFS_ITER_PROP_LISTSNAPS;
                        while (*optarg != '\0') {
                                static char *type_subopts[] = { "filesystem",
-                                   "volume", "snapshot", "all", NULL };
+                                   "volume", "snapshot", "snap", "all", NULL };
 
                                switch (getsubopt(&optarg, type_subopts,
                                    &value)) {
@@ -2777,9 +2777,10 @@ zfs_do_list(int argc, char **argv)
                                        types |= ZFS_TYPE_VOLUME;
                                        break;
                                case 2:
+                               case 3:
                                        types |= ZFS_TYPE_SNAPSHOT;
                                        break;
-                               case 3:
+                               case 4:
                                        types = ZFS_TYPE_DATASET;
                                        break;
 
@@ -2834,7 +2835,7 @@ zfs_do_list(int argc, char **argv)
        zfs_free_sort_columns(sortcol);
 
        if (ret == 0 && cb.cb_first && !cb.cb_scripted)
-               (void) printf(gettext("no datasets available\n"));
+               (void) fprintf(stderr, gettext("no datasets available\n"));
 
        return (ret);
 }
@@ -2854,7 +2855,7 @@ zfs_do_rename(int argc, char **argv)
 {
        zfs_handle_t *zhp;
        int c;
-       int ret;
+       int ret = 0;
        boolean_t recurse = B_FALSE;
        boolean_t parents = B_FALSE;
 
@@ -2933,7 +2934,7 @@ static int
 zfs_do_promote(int argc, char **argv)
 {
        zfs_handle_t *zhp;
-       int ret;
+       int ret = 0;
 
        /* check options */
        if (argc > 1 && argv[1][0] == '-') {
@@ -3054,7 +3055,7 @@ rollback_check(zfs_handle_t *zhp, void *data)
 static int
 zfs_do_rollback(int argc, char **argv)
 {
-       int ret;
+       int ret = 0;
        int c;
        boolean_t force = B_FALSE;
        rollback_cbdata_t cb = { 0 };
@@ -3172,7 +3173,7 @@ static int
 zfs_do_set(int argc, char **argv)
 {
        set_cbdata_t cb;
-       int ret;
+       int ret = 0;
 
        /* check for options */
        if (argc > 1 && argv[1][0] == '-') {
@@ -3226,7 +3227,7 @@ static int
 zfs_do_snapshot(int argc, char **argv)
 {
        boolean_t recursive = B_FALSE;
-       int ret;
+       int ret = 0;
        signed char c;
        nvlist_t *props;
 
@@ -4457,7 +4458,7 @@ construct_fsacl_list(boolean_t un, struct allow_opts *opts, nvlist_t **nvlp)
 
                while (curr < end) {
                        const char *who;
-                       zfs_deleg_who_type_t who_type;
+                       zfs_deleg_who_type_t who_type = ZFS_DELEG_WHO_UNKNOWN;
                        char *endch;
                        char *delim = strchr(curr, ',');
                        char errbuf[256];
@@ -5070,7 +5071,7 @@ zfs_do_holds(int argc, char **argv)
        holds_cbdata_t cb = { 0 };
 
        int limit = 0;
-       int ret;
+       int ret = 0;
        int flags = 0;
 
        /* check options */
@@ -5139,7 +5140,7 @@ zfs_do_holds(int argc, char **argv)
        print_holds(scripted, cb.cb_max_namelen, cb.cb_max_taglen, nvl);
 
        if (nvlist_empty(nvl))
-               (void) printf(gettext("no datasets available\n"));
+               (void) fprintf(stderr, gettext("no datasets available\n"));
 
        nvlist_free(nvl);
 
@@ -5469,7 +5470,7 @@ share_mount(int op, int argc, char **argv)
        int flags = 0;
 
        /* check options */
-       while ((c = getopt(argc, argv, op == OP_MOUNT ? ":avo:" : "a"))
+       while ((c = getopt(argc, argv, op == OP_MOUNT ? ":avo:O" : "a"))
            != -1) {
                switch (c) {
                case 'a':
@@ -5491,7 +5492,9 @@ share_mount(int op, int argc, char **argv)
                        /* option validation is done later */
                        append_options(options, optarg);
                        break;
-
+               case 'O':
+                       flags |= MS_OVERLAY;
+                       break;
                case ':':
                        (void) fprintf(stderr, gettext("missing argument for "
                            "'%c' option\n"), optopt);
@@ -5644,7 +5647,7 @@ static int
 unshare_unmount_path(int op, char *path, int flags, boolean_t is_manual)
 {
        zfs_handle_t *zhp;
-       int ret;
+       int ret = 0;
        struct stat64 statbuf;
        struct extmnttab entry;
        const char *cmdname = (op == OP_SHARE) ? "unshare" : "unmount";
@@ -6052,7 +6055,7 @@ zfs_do_diff(int argc, char **argv)
        char *tosnap = NULL;
        char *fromsnap = NULL;
        char *atp, *copy;
-       int err;
+       int err = 0;
        int c;
 
        while ((c = getopt(argc, argv, "FHt")) != -1) {
@@ -6122,7 +6125,7 @@ zfs_do_diff(int argc, char **argv)
 int
 main(int argc, char **argv)
 {
-       int ret;
+       int ret = 0;
        int i = 0;
        char *cmdname;
 
@@ -6160,6 +6163,12 @@ main(int argc, char **argv)
                cmdname = "receive";
 
        /*
+        * The 'snap' command is an alias for 'snapshot'
+        */
+       if (strcmp(cmdname, "snap") == 0)
+               cmdname = "snapshot";
+
+       /*
         * Special case '-?'
         */
        if ((strcmp(cmdname, "-?") == 0) ||