diff options
-rw-r--r-- | cmd/zdb/zdb.c | 4 | ||||
-rw-r--r-- | cmd/zfs/zfs_main.c | 22 | ||||
-rw-r--r-- | cmd/zinject/zinject.c | 23 | ||||
-rw-r--r-- | cmd/zpool/zpool_main.c | 16 | ||||
-rw-r--r-- | lib/libzfs/libzfs_sendrecv.c | 5 | ||||
-rw-r--r-- | lib/libzfs/libzfs_util.c | 7 |
6 files changed, 41 insertions, 36 deletions
diff --git a/cmd/zdb/zdb.c b/cmd/zdb/zdb.c index d0354809d..a5ad7feb8 100644 --- a/cmd/zdb/zdb.c +++ b/cmd/zdb/zdb.c @@ -3036,8 +3036,8 @@ main(int argc, char **argv) } kernel_init(FREAD); - g_zfs = libzfs_init(); - ASSERT(g_zfs != NULL); + if ((g_zfs = libzfs_init()) == NULL) + return (1); if (dump_all) verbose = MAX(verbose, 1); diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index ebcec2d6e..b0e6180ea 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -4102,17 +4102,6 @@ main(int argc, char **argv) opterr = 0; - if ((g_zfs = libzfs_init()) == NULL) { - (void) fprintf(stderr, gettext("internal error: failed to " - "initialize ZFS library\n")); - return (1); - } - - zpool_set_history_str("zfs", argc, argv, history_str); - verify(zpool_stage_history(g_zfs, history_str) == 0); - - libzfs_print_on_error(g_zfs, B_TRUE); - if ((mnttab_file = fopen(MNTTAB, "r")) == NULL) { (void) fprintf(stderr, gettext("internal error: unable to " "open %s\n"), MNTTAB); @@ -4158,9 +4147,18 @@ main(int argc, char **argv) /* * Special case '-?' */ - if (strcmp(cmdname, "-?") == 0) + if ((strcmp(cmdname, "-?") == 0) || + (strcmp(cmdname, "--help") == 0)) usage(B_TRUE); + if ((g_zfs = libzfs_init()) == NULL) + return (1); + + zpool_set_history_str("zfs", argc, argv, history_str); + verify(zpool_stage_history(g_zfs, history_str) == 0); + + libzfs_print_on_error(g_zfs, B_TRUE); + /* * Run the appropriate command. */ diff --git a/cmd/zinject/zinject.c b/cmd/zinject/zinject.c index 643d73e7f..3ad90e329 100644 --- a/cmd/zinject/zinject.c +++ b/cmd/zinject/zinject.c @@ -573,19 +573,6 @@ main(int argc, char **argv) int ret; int flags = 0; - if ((g_zfs = libzfs_init()) == NULL) { - (void) fprintf(stderr, "internal error: failed to " - "initialize ZFS library\n"); - return (1); - } - - libzfs_print_on_error(g_zfs, B_TRUE); - - if ((zfs_fd = open(ZFS_DEV, O_RDWR)) < 0) { - (void) fprintf(stderr, "failed to open ZFS device\n"); - return (1); - } - if (argc == 1) { /* * No arguments. Print the available handlers. If there are no @@ -765,6 +752,16 @@ main(int argc, char **argv) argc -= optind; argv += optind; + if ((g_zfs = libzfs_init()) == NULL) + return (1); + + libzfs_print_on_error(g_zfs, B_TRUE); + + if ((zfs_fd = open(ZFS_DEV, O_RDWR)) < 0) { + (void) fprintf(stderr, "failed to open ZFS device\n"); + return (1); + } + if (cancel != NULL) { /* * '-c' is invalid with any other options. diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c index b1b71acf8..3859bf737 100644 --- a/cmd/zpool/zpool_main.c +++ b/cmd/zpool/zpool_main.c @@ -4712,14 +4712,6 @@ main(int argc, char **argv) (void) setlocale(LC_ALL, ""); (void) textdomain(TEXT_DOMAIN); - if ((g_zfs = libzfs_init()) == NULL) { - (void) fprintf(stderr, gettext("internal error: failed to " - "initialize ZFS library\n")); - return (1); - } - - libzfs_print_on_error(g_zfs, B_TRUE); - opterr = 0; /* @@ -4735,9 +4727,15 @@ main(int argc, char **argv) /* * Special case '-?' */ - if (strcmp(cmdname, "-?") == 0) + if ((strcmp(cmdname, "-?") == 0) || + strcmp(cmdname, "--help") == 0) usage(B_TRUE); + if ((g_zfs = libzfs_init()) == NULL) + return (1); + + libzfs_print_on_error(g_zfs, B_TRUE); + zpool_set_history_str("zpool", argc, argv, history_str); verify(zpool_stage_history(g_zfs, history_str) == 0); diff --git a/lib/libzfs/libzfs_sendrecv.c b/lib/libzfs/libzfs_sendrecv.c index 40d1d2e53..94e64e63f 100644 --- a/lib/libzfs/libzfs_sendrecv.c +++ b/lib/libzfs/libzfs_sendrecv.c @@ -34,6 +34,11 @@ #include <stddef.h> #include <fcntl.h> #include <sys/mount.h> +#include <sys/mntent.h> +#include <sys/mnttab.h> +#include <sys/avl.h> +#include <sys/debug.h> +#include <stddef.h> #include <pthread.h> #include <umem.h> diff --git a/lib/libzfs/libzfs_util.c b/lib/libzfs/libzfs_util.c index 71f81831b..3c4fae5aa 100644 --- a/lib/libzfs/libzfs_util.c +++ b/lib/libzfs/libzfs_util.c @@ -614,6 +614,13 @@ libzfs_init(void) } if ((hdl->libzfs_fd = open(ZFS_DEV, O_RDWR)) < 0) { + (void) fprintf(stderr, gettext("Unable to open %s: %s.\n"), + ZFS_DEV, strerror(errno)); + if (errno == ENOENT) + (void) fprintf(stderr, + gettext("Verify the ZFS module stack is " + "loaded by running '/sbin/modprobe zfs'.\n")); + free(hdl); return (NULL); } |