113ec1e31SMitchell Horne /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
313ec1e31SMitchell Horne *
413ec1e31SMitchell Horne * Copyright (c) 2022 NetApp, Inc.
513ec1e31SMitchell Horne *
613ec1e31SMitchell Horne * Redistribution and use in source and binary forms, with or without
713ec1e31SMitchell Horne * modification, are permitted provided that the following conditions
813ec1e31SMitchell Horne * are met:
913ec1e31SMitchell Horne * 1. Redistributions of source code must retain the above copyright
1013ec1e31SMitchell Horne * notice, this list of conditions and the following disclaimer.
1113ec1e31SMitchell Horne * 2. Redistributions in binary form must reproduce the above copyright
1213ec1e31SMitchell Horne * notice, this list of conditions and the following disclaimer in the
1313ec1e31SMitchell Horne * documentation and/or other materials provided with the distribution.
1413ec1e31SMitchell Horne *
1513ec1e31SMitchell Horne * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1613ec1e31SMitchell Horne * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1713ec1e31SMitchell Horne * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1813ec1e31SMitchell Horne * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1913ec1e31SMitchell Horne * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2013ec1e31SMitchell Horne * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2113ec1e31SMitchell Horne * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2213ec1e31SMitchell Horne * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2313ec1e31SMitchell Horne * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2413ec1e31SMitchell Horne * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2513ec1e31SMitchell Horne * SUCH DAMAGE.
2613ec1e31SMitchell Horne */
2713ec1e31SMitchell Horne
2813ec1e31SMitchell Horne #include <sys/types.h>
2913ec1e31SMitchell Horne #include <sys/boottrace.h>
3013ec1e31SMitchell Horne #include <sys/sysctl.h>
3113ec1e31SMitchell Horne #include <sys/wait.h>
3213ec1e31SMitchell Horne
3313ec1e31SMitchell Horne #include <err.h>
3413ec1e31SMitchell Horne #include <errno.h>
3513ec1e31SMitchell Horne #include <stdio.h>
3613ec1e31SMitchell Horne #include <stdlib.h>
3713ec1e31SMitchell Horne #include <string.h>
3813ec1e31SMitchell Horne #include <unistd.h>
3913ec1e31SMitchell Horne
4013ec1e31SMitchell Horne static void
usage(void)4113ec1e31SMitchell Horne usage(void)
4213ec1e31SMitchell Horne {
4313ec1e31SMitchell Horne fprintf(stderr, "usage: boottrace utility [argument ...]\n");
4413ec1e31SMitchell Horne exit(1);
4513ec1e31SMitchell Horne }
4613ec1e31SMitchell Horne
4713ec1e31SMitchell Horne int
main(int argc,char ** argv)4813ec1e31SMitchell Horne main(int argc, char **argv)
4913ec1e31SMitchell Horne {
5013ec1e31SMitchell Horne pid_t pid;
5113ec1e31SMitchell Horne int status;
5213ec1e31SMitchell Horne
5313ec1e31SMitchell Horne if (argc < 2)
5413ec1e31SMitchell Horne usage();
5513ec1e31SMitchell Horne argv++;
5613ec1e31SMitchell Horne
5713ec1e31SMitchell Horne BOOTTRACE("%s start", *argv);
5813ec1e31SMitchell Horne pid = fork();
5913ec1e31SMitchell Horne if (pid == -1) {
6013ec1e31SMitchell Horne exit(1);
6113ec1e31SMitchell Horne } else if (pid == 0) {
6213ec1e31SMitchell Horne execvp(*argv, argv);
6313ec1e31SMitchell Horne err(errno == ENOENT ? 127 : 126, "execvp %s", *argv);
6413ec1e31SMitchell Horne }
6513ec1e31SMitchell Horne waitpid(pid, &status, 0);
6613ec1e31SMitchell Horne if (!WIFEXITED(status))
6713ec1e31SMitchell Horne warnx("command terminated abnormally");
6813ec1e31SMitchell Horne BOOTTRACE("%s done", *argv);
6913ec1e31SMitchell Horne
7013ec1e31SMitchell Horne return (WIFEXITED(status) ? WEXITSTATUS(status) : EXIT_FAILURE);
7113ec1e31SMitchell Horne }
72