Changeset View
Standalone View
usr.bin/boottrace/boottrace.c
- This file was added.
/*- | |||||
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD | |||||
* | |||||
* Copyright (c) 2021 NetApp, Inc. | |||||
* | |||||
0mp: Bump to 2022. | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in the | |||||
* documentation and/or other materials provided with the distribution. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||||
*/ | |||||
#include <sys/types.h> | |||||
#include <sys/boottrace.h> | |||||
#include <sys/sysctl.h> | |||||
#include <sys/wait.h> | |||||
#include <err.h> | |||||
#include <errno.h> | |||||
#include <stdio.h> | |||||
#include <stdlib.h> | |||||
#include <string.h> | |||||
#include <unistd.h> | |||||
static void | |||||
usage(void) | |||||
{ | |||||
fprintf(stderr, "usage: boottrace utility [argument ...]\n"); | |||||
exit(1); | |||||
} | |||||
int | |||||
main(int argc, char **argv) | |||||
{ | |||||
pid_t pid; | |||||
int status; | |||||
if (argc < 2) | |||||
usage(); | |||||
argv++; | |||||
RUNTRACE("%s start", *argv); | |||||
siderop1_netapp.comUnsubmitted Not Done Inline ActionsSo if this utility is expected to be called by the RC framework, where do we draw the line between boot times and run times? Here you've chosen the RC scripts are run times, but they are a big part of boot, no? siderop1_netapp.com: So if this utility is expected to be called by the RC framework, where do we draw the line… | |||||
mhorneAuthorUnsubmitted Done Inline ActionsI suppose it is up to interpretation, whether the execution of startup scripts is considered part of "boot" or not. That said, I believe the original patch uses the start of multi-user as the separation point, which is reasonable enough. I will update this patch to use BOOTTRACE() instead. mhorne: I suppose it is up to interpretation, whether the execution of startup scripts is considered… | |||||
siderop1_netapp.comUnsubmitted Not Done Inline ActionsI am honestly fine either way, just wanted to have the justification documented somewhere. siderop1_netapp.com: I am honestly fine either way, just wanted to have the justification documented somewhere. | |||||
pid = fork(); | |||||
if (pid == -1) { | |||||
exit(1); | |||||
} else if (pid == 0) { | |||||
execvp(*argv, argv); | |||||
err(1, "execvp %s", *argv); | |||||
} | |||||
Not Done Inline ActionsI guess it's probably rare, but should the error be logged via boottrace as well? kevans: I guess it's probably rare, but should the error be logged via boottrace as well? | |||||
Not Done Inline ActionsAh, sorry, I guess it still gets the done trace below; disregard. kevans: Ah, sorry, I guess it still gets the `done` trace below; disregard. | |||||
waitpid(pid, &status, 0); | |||||
Not Done Inline ActionsMaybe instead of 1, we could use a higher number like 127 in a similar fashion to timeout(1)? Then there is a lower chance of conflicting exit codes in boottrace and the utility. 0mp: Maybe instead of 1, we could use a higher number like 127 in a similar fashion to timeout(1)? | |||||
Done Inline ActionsSeems to be a common enough pattern to do the following: So, yes I have done this in the committed version. mhorne: Seems to be a common enough pattern to do the following:
`err(errno == ENOENT ? 127 : 126… | |||||
if (!WIFEXITED(status)) | |||||
warnx("command terminated abnormally"); | |||||
RUNTRACE("%s done", *argv); | |||||
return (0); | |||||
} | |||||
Not Done Inline ActionsShouldn't we return the exit status of the executed utility instead of 0? 0mp: Shouldn't we return the exit status of the executed utility instead of 0? | |||||
Not Done Inline ActionsIf the idea is that we could expect to be able to arbitrarily throw whatever command under boottrace in isolation, I think you're right that it should maintain that kind of transparency. kevans: If the idea is that we could expect to be able to arbitrarily throw whatever command under… |
Bump to 2022.