1 // SPDX-License-Identifier: CDDL-1.0 2 /* 3 * CDDL HEADER START 4 * 5 * The contents of this file are subject to the terms of the 6 * Common Development and Distribution License (the "License"). 7 * You may not use this file except in compliance with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or https://opensource.org/licenses/CDDL-1.0. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 23 /* 24 * Portions Copyright 2020 iXsystems, Inc. 25 */ 26 27 /* 28 * Test a corner case : a "doall" send without children datasets. 29 */ 30 31 #include <libzfs.h> 32 #include <libzfs_core.h> 33 34 #include <fcntl.h> 35 #include <stdlib.h> 36 #include <string.h> 37 #include <unistd.h> 38 #include <sysexits.h> 39 #include <err.h> 40 41 static void 42 usage(const char *name) 43 { 44 fprintf(stderr, "usage: %s snap\n", name); 45 exit(EX_USAGE); 46 } 47 48 int 49 main(int argc, char const * const argv[]) 50 { 51 sendflags_t flags = { 0 }; 52 libzfs_handle_t *zhdl; 53 zfs_handle_t *zhp; 54 const char *tofull, *fsname, *tosnap, *p; 55 int error; 56 57 if (argc != 2) 58 usage(argv[0]); 59 60 tofull = argv[1]; 61 62 p = strchr(tofull, '@'); 63 if (p == NULL) 64 usage(argv[0]); 65 tosnap = p + 1; 66 67 fsname = strndup(tofull, p - tofull); 68 69 zhdl = libzfs_init(); 70 if (zhdl == NULL) 71 errx(EX_OSERR, "libzfs_init(): %s", libzfs_error_init(errno)); 72 73 zhp = zfs_open(zhdl, fsname, ZFS_TYPE_FILESYSTEM); 74 if (zhp == NULL) 75 err(EX_OSERR, "zfs_open(\"%s\")", fsname); 76 77 flags.doall = B_TRUE; 78 79 error = zfs_send(zhp, NULL, tosnap, &flags, 80 STDOUT_FILENO, NULL, NULL, NULL); 81 82 zfs_close(zhp); 83 84 libzfs_fini(zhdl); 85 free((void *)fsname); 86 87 return (error); 88 } 89