xref: /freebsd/lib/libbe/tests/target_prog.c (revision cddbc3b40812213ff00041f79174cac0be360a2a)
1*cddbc3b4SKyle Evans /*-
2*cddbc3b4SKyle Evans  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3*cddbc3b4SKyle Evans  *
4*cddbc3b4SKyle Evans  * Copyright (c) 2019 Rob Wing
5*cddbc3b4SKyle Evans  * All rights reserved.
6*cddbc3b4SKyle Evans  *
7*cddbc3b4SKyle Evans  * Redistribution and use in source and binary forms, with or without
8*cddbc3b4SKyle Evans  * modification, are permitted provided that the following conditions
9*cddbc3b4SKyle Evans  * are met:
10*cddbc3b4SKyle Evans  * 1. Redistributions of source code must retain the above copyright
11*cddbc3b4SKyle Evans  *    notice, this list of conditions and the following disclaimer.
12*cddbc3b4SKyle Evans  * 2. Redistributions in binary form must reproduce the above copyright
13*cddbc3b4SKyle Evans  *    notice, this list of conditions and the following disclaimer in the
14*cddbc3b4SKyle Evans  *    documentation and/or other materials provided with the distribution.
15*cddbc3b4SKyle Evans  *
16*cddbc3b4SKyle Evans  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17*cddbc3b4SKyle Evans  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*cddbc3b4SKyle Evans  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*cddbc3b4SKyle Evans  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20*cddbc3b4SKyle Evans  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*cddbc3b4SKyle Evans  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22*cddbc3b4SKyle Evans  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*cddbc3b4SKyle Evans  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*cddbc3b4SKyle Evans  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*cddbc3b4SKyle Evans  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*cddbc3b4SKyle Evans  * SUCH DAMAGE.
27*cddbc3b4SKyle Evans  */
28*cddbc3b4SKyle Evans 
29*cddbc3b4SKyle Evans #include <sys/cdefs.h>
30*cddbc3b4SKyle Evans __FBSDID("$FreeBSD$");
31*cddbc3b4SKyle Evans 
32*cddbc3b4SKyle Evans #include <be.h>
33*cddbc3b4SKyle Evans 
34*cddbc3b4SKyle Evans /*
35*cddbc3b4SKyle Evans  * argv[1] = root boot environment (e.g. zroot/ROOT),
36*cddbc3b4SKyle Evans  * argv[2] = name of boot environment to create
37*cddbc3b4SKyle Evans  * argv[3] = snapshot to create boot environment from
38*cddbc3b4SKyle Evans  * argv[4] = depth
39*cddbc3b4SKyle Evans  */
40*cddbc3b4SKyle Evans int main(int argc, char *argv[]) {
41*cddbc3b4SKyle Evans 
42*cddbc3b4SKyle Evans         libbe_handle_t *lbh;
43*cddbc3b4SKyle Evans 
44*cddbc3b4SKyle Evans 	if (argc != 5)
45*cddbc3b4SKyle Evans 		return -1;
46*cddbc3b4SKyle Evans 
47*cddbc3b4SKyle Evans         if ((lbh = libbe_init(argv[1])) == NULL)
48*cddbc3b4SKyle Evans                 return -1;
49*cddbc3b4SKyle Evans 
50*cddbc3b4SKyle Evans 	libbe_print_on_error(lbh, true);
51*cddbc3b4SKyle Evans 
52*cddbc3b4SKyle Evans 	return (be_create_depth(lbh, argv[2], argv[3], atoi(argv[4])));
53*cddbc3b4SKyle Evans }
54