1716fd348SMartin Matuska /*
2716fd348SMartin Matuska * CDDL HEADER START
3716fd348SMartin Matuska *
4716fd348SMartin Matuska * The contents of this file are subject to the terms of the
5716fd348SMartin Matuska * Common Development and Distribution License (the "License").
6716fd348SMartin Matuska * You may not use this file except in compliance with the License.
7716fd348SMartin Matuska *
8716fd348SMartin Matuska * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*271171e0SMartin Matuska * or https://opensource.org/licenses/CDDL-1.0.
10716fd348SMartin Matuska * See the License for the specific language governing permissions
11716fd348SMartin Matuska * and limitations under the License.
12716fd348SMartin Matuska *
13716fd348SMartin Matuska * When distributing Covered Code, include this CDDL HEADER in each
14716fd348SMartin Matuska * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15716fd348SMartin Matuska * If applicable, add the following below this CDDL HEADER, with the
16716fd348SMartin Matuska * fields enclosed by brackets "[]" replaced with your own identifying
17716fd348SMartin Matuska * information: Portions Copyright [yyyy] [name of copyright owner]
18716fd348SMartin Matuska *
19716fd348SMartin Matuska * CDDL HEADER END
20716fd348SMartin Matuska */
21716fd348SMartin Matuska
22716fd348SMartin Matuska /*
23716fd348SMartin Matuska * Portions Copyright 2020 iXsystems, Inc.
24716fd348SMartin Matuska */
25716fd348SMartin Matuska
26716fd348SMartin Matuska /*
27716fd348SMartin Matuska * Test a corner case : a "doall" send without children datasets.
28716fd348SMartin Matuska */
29716fd348SMartin Matuska
30716fd348SMartin Matuska #include <libzfs.h>
31716fd348SMartin Matuska #include <libzfs_core.h>
32716fd348SMartin Matuska
33716fd348SMartin Matuska #include <fcntl.h>
34716fd348SMartin Matuska #include <stdlib.h>
35716fd348SMartin Matuska #include <string.h>
36716fd348SMartin Matuska #include <unistd.h>
37716fd348SMartin Matuska #include <sysexits.h>
38716fd348SMartin Matuska #include <err.h>
39716fd348SMartin Matuska
40716fd348SMartin Matuska static void
usage(const char * name)41716fd348SMartin Matuska usage(const char *name)
42716fd348SMartin Matuska {
43716fd348SMartin Matuska fprintf(stderr, "usage: %s snap\n", name);
44716fd348SMartin Matuska exit(EX_USAGE);
45716fd348SMartin Matuska }
46716fd348SMartin Matuska
47716fd348SMartin Matuska int
main(int argc,char const * const argv[])48716fd348SMartin Matuska main(int argc, char const * const argv[])
49716fd348SMartin Matuska {
50716fd348SMartin Matuska sendflags_t flags = { 0 };
51716fd348SMartin Matuska libzfs_handle_t *zhdl;
52716fd348SMartin Matuska zfs_handle_t *zhp;
53716fd348SMartin Matuska const char *tofull, *fsname, *tosnap, *p;
54716fd348SMartin Matuska int error;
55716fd348SMartin Matuska
56716fd348SMartin Matuska if (argc != 2)
57716fd348SMartin Matuska usage(argv[0]);
58716fd348SMartin Matuska
59716fd348SMartin Matuska tofull = argv[1];
60716fd348SMartin Matuska
61716fd348SMartin Matuska p = strchr(tofull, '@');
62716fd348SMartin Matuska if (p == NULL)
63716fd348SMartin Matuska usage(argv[0]);
64716fd348SMartin Matuska tosnap = p + 1;
65716fd348SMartin Matuska
66716fd348SMartin Matuska fsname = strndup(tofull, p - tofull);
67716fd348SMartin Matuska
68716fd348SMartin Matuska zhdl = libzfs_init();
69716fd348SMartin Matuska if (zhdl == NULL)
70716fd348SMartin Matuska errx(EX_OSERR, "libzfs_init(): %s", libzfs_error_init(errno));
71716fd348SMartin Matuska
72716fd348SMartin Matuska zhp = zfs_open(zhdl, fsname, ZFS_TYPE_FILESYSTEM);
73716fd348SMartin Matuska if (zhp == NULL)
74716fd348SMartin Matuska err(EX_OSERR, "zfs_open(\"%s\")", fsname);
75716fd348SMartin Matuska
76716fd348SMartin Matuska flags.doall = B_TRUE;
77716fd348SMartin Matuska
78716fd348SMartin Matuska error = zfs_send(zhp, NULL, tosnap, &flags,
79716fd348SMartin Matuska STDOUT_FILENO, NULL, NULL, NULL);
80716fd348SMartin Matuska
81716fd348SMartin Matuska zfs_close(zhp);
82716fd348SMartin Matuska
83716fd348SMartin Matuska libzfs_fini(zhdl);
84716fd348SMartin Matuska free((void *)fsname);
85716fd348SMartin Matuska
86716fd348SMartin Matuska return (error);
87716fd348SMartin Matuska }
88