diff options
Diffstat (limited to 'usr/src/cmd/zinject/zinject.c')
-rw-r--r-- | usr/src/cmd/zinject/zinject.c | 63 |
1 files changed, 53 insertions, 10 deletions
diff --git a/usr/src/cmd/zinject/zinject.c b/usr/src/cmd/zinject/zinject.c index 6ab78ad46b..3ba2976df1 100644 --- a/usr/src/cmd/zinject/zinject.c +++ b/usr/src/cmd/zinject/zinject.c @@ -772,6 +772,7 @@ main(int argc, char **argv) if ((zfs_fd = open(ZFS_DEV, O_RDWR)) < 0) { (void) fprintf(stderr, "failed to open ZFS device\n"); + libzfs_fini(g_zfs); return (1); } @@ -787,6 +788,7 @@ main(int argc, char **argv) "information.\n"); } + libzfs_fini(g_zfs); return (0); } @@ -805,6 +807,7 @@ main(int argc, char **argv) (void) fprintf(stderr, "invalid action '%s': " "must be 'degrade' or 'fault'\n", optarg); usage(); + libzfs_fini(g_zfs); return (1); } break; @@ -835,6 +838,7 @@ main(int argc, char **argv) (void) fprintf(stderr, "invalid i/o delay " "value: '%s'\n", optarg); usage(); + libzfs_fini(g_zfs); return (1); } break; @@ -864,6 +868,7 @@ main(int argc, char **argv) "be in the range [0.0001, 100.0]\n", ret == EINVAL ? "invalid value: " : ret == ERANGE ? "out of range: " : ""); + libzfs_fini(g_zfs); return (1); } break; @@ -877,6 +882,7 @@ main(int argc, char **argv) (void) fprintf(stderr, "invalid duration '%s': " "must be a positive integer\n", optarg); usage(); + libzfs_fini(g_zfs); return (1); } /* store duration of txgs as its negative */ @@ -884,6 +890,7 @@ main(int argc, char **argv) break; case 'h': usage(); + libzfs_fini(g_zfs); return (0); case 'I': /* default duration, if one hasn't yet been defined */ @@ -897,6 +904,7 @@ main(int argc, char **argv) (void) fprintf(stderr, "invalid level '%s': " "must be an integer\n", optarg); usage(); + libzfs_fini(g_zfs); return (1); } break; @@ -922,6 +930,7 @@ main(int argc, char **argv) (void) fprintf(stderr, "invalid duration '%s': " "must be a positive integer\n", optarg); usage(); + libzfs_fini(g_zfs); return (1); } break; @@ -941,6 +950,7 @@ main(int argc, char **argv) "'%s': must be 'read', 'write', 'free', " "'claim' or 'all'\n", optarg); usage(); + libzfs_fini(g_zfs); return (1); } break; @@ -950,6 +960,7 @@ main(int argc, char **argv) (void) fprintf(stderr, "invalid type '%s'\n", optarg); usage(); + libzfs_fini(g_zfs); return (1); } break; @@ -962,6 +973,7 @@ main(int argc, char **argv) (void) fprintf(stderr, "invalid label type " "'%s'\n", optarg); usage(); + libzfs_fini(g_zfs); return (1); } break; @@ -969,11 +981,13 @@ main(int argc, char **argv) (void) fprintf(stderr, "option -%c requires an " "operand\n", optopt); usage(); + libzfs_fini(g_zfs); return (1); case '?': (void) fprintf(stderr, "invalid option '%c'\n", optopt); usage(); + libzfs_fini(g_zfs); return (2); } } @@ -994,11 +1008,13 @@ main(int argc, char **argv) (void) fprintf(stderr, "cancel (-c) incompatible with " "any other options\n"); usage(); + libzfs_fini(g_zfs); return (2); } if (argc != 0) { (void) fprintf(stderr, "extraneous argument to '-c'\n"); usage(); + libzfs_fini(g_zfs); return (2); } @@ -1010,6 +1026,7 @@ main(int argc, char **argv) (void) fprintf(stderr, "invalid handle id '%s':" " must be an integer or 'all'\n", cancel); usage(); + libzfs_fini(g_zfs); return (1); } return (cancel_handler(id)); @@ -1027,6 +1044,7 @@ main(int argc, char **argv) (void) fprintf(stderr, "device (-d) incompatible with " "data error injection\n"); usage(); + libzfs_fini(g_zfs); return (2); } @@ -1034,21 +1052,25 @@ main(int argc, char **argv) (void) fprintf(stderr, "device (-d) injection requires " "a single pool name\n"); usage(); + libzfs_fini(g_zfs); return (2); } - (void) strcpy(pool, argv[0]); + (void) strlcpy(pool, argv[0], sizeof (pool)); dataset[0] = '\0'; if (error == ECKSUM) { (void) fprintf(stderr, "device error type must be " "'io' or 'nxio'\n"); + libzfs_fini(g_zfs); return (1); } record.zi_iotype = io_type; - if (translate_device(pool, device, label, &record) != 0) + if (translate_device(pool, device, label, &record) != 0) { + libzfs_fini(g_zfs); return (1); + } if (!error) error = ENXIO; @@ -1062,6 +1084,7 @@ main(int argc, char **argv) (void) fprintf(stderr, "raw (-b) format with " "any other options\n"); usage(); + libzfs_fini(g_zfs); return (2); } @@ -1069,21 +1092,25 @@ main(int argc, char **argv) (void) fprintf(stderr, "raw (-b) format expects a " "single pool name\n"); usage(); + libzfs_fini(g_zfs); return (2); } - (void) strcpy(pool, argv[0]); + (void) strlcpy(pool, argv[0], sizeof (pool)); dataset[0] = '\0'; if (error == ENXIO) { (void) fprintf(stderr, "data error type must be " "'checksum' or 'io'\n"); + libzfs_fini(g_zfs); return (1); } record.zi_cmd = ZINJECT_DATA_FAULT; - if (translate_raw(raw, &record) != 0) + if (translate_raw(raw, &record) != 0) { + libzfs_fini(g_zfs); return (1); + } if (!error) error = EIO; } else if (record.zi_cmd == ZINJECT_PANIC) { @@ -1093,6 +1120,7 @@ main(int argc, char **argv) (void) fprintf(stderr, "panic (-p) incompatible with " "other options\n"); usage(); + libzfs_fini(g_zfs); return (2); } @@ -1100,10 +1128,11 @@ main(int argc, char **argv) (void) fprintf(stderr, "panic (-p) injection requires " "a single pool name and an optional id\n"); usage(); + libzfs_fini(g_zfs); return (2); } - (void) strcpy(pool, argv[0]); + (void) strlcpy(pool, argv[0], sizeof (pool)); if (argv[1] != NULL) record.zi_type = atoi(argv[1]); dataset[0] = '\0'; @@ -1121,21 +1150,24 @@ main(int argc, char **argv) (void) fprintf(stderr, "-s or -g meaningless " "without -I (ignore writes)\n"); usage(); + libzfs_fini(g_zfs); return (2); } else if (dur_secs && dur_txg) { (void) fprintf(stderr, "choose a duration either " "in seconds (-s) or a number of txgs (-g) " "but not both\n"); usage(); + libzfs_fini(g_zfs); return (2); } else if (argc != 1) { (void) fprintf(stderr, "ignore writes (-I) " "injection requires a single pool name\n"); usage(); + libzfs_fini(g_zfs); return (2); } - (void) strcpy(pool, argv[0]); + (void) strlcpy(pool, argv[0], sizeof (pool)); dataset[0] = '\0'; } else if (type == TYPE_INVAL) { if (flags == 0) { @@ -1143,16 +1175,18 @@ main(int argc, char **argv) "'-t', '-a', '-p', '-I' or '-u' " "must be specified\n"); usage(); + libzfs_fini(g_zfs); return (2); } if (argc == 1 && (flags & ZINJECT_UNLOAD_SPA)) { - (void) strcpy(pool, argv[0]); + (void) strlcpy(pool, argv[0], sizeof (pool)); dataset[0] = '\0'; } else if (argc != 0) { (void) fprintf(stderr, "extraneous argument for " "'-f'\n"); usage(); + libzfs_fini(g_zfs); return (2); } @@ -1161,12 +1195,14 @@ main(int argc, char **argv) if (argc != 1) { (void) fprintf(stderr, "missing object\n"); usage(); + libzfs_fini(g_zfs); return (2); } if (error == ENXIO) { (void) fprintf(stderr, "data error type must be " "'checksum' or 'io'\n"); + libzfs_fini(g_zfs); return (1); } @@ -1199,8 +1235,10 @@ main(int argc, char **argv) } if (translate_record(type, argv[0], range, level, &record, pool, - dataset) != 0) + dataset) != 0) { + libzfs_fini(g_zfs); return (1); + } if (!error) error = EIO; } @@ -1211,11 +1249,16 @@ main(int argc, char **argv) * time we access the pool. */ if (dataset[0] != '\0' && domount) { - if ((zhp = zfs_open(g_zfs, dataset, ZFS_TYPE_DATASET)) == NULL) + if ((zhp = zfs_open(g_zfs, dataset, + ZFS_TYPE_DATASET)) == NULL) { + libzfs_fini(g_zfs); return (1); + } - if (zfs_unmount(zhp, NULL, 0) != 0) + if (zfs_unmount(zhp, NULL, 0) != 0) { + libzfs_fini(g_zfs); return (1); + } } record.zi_error = error; |