On Fri, Mar 19, 2021 at 09:41:32PM +1000, Jonathan Matthew wrote:
> I'd like to add some regress tests for the btrace(8) parser.
> To do that, it would help to have a dry-run mode where it just parses the
> file and exits.
>
> The way I've implemented it here, it exits immediately after parsing, so it
> won't open /dev/dt and try to find the probes the program uses. This means
> it doesn't require privileges and can be run on kernels without dt(4)
> compiled in, but it can't catch typos in probe names.
Makes sense.
Later on, this could perhaps adapt the pfctl approach: open the device
and validate against kernel also if possible, otherwise exit gracefully
on open(2) failure if dry-run is requested.
> Index: btrace.8
> ===================================================================
> RCS file: /cvs/src/usr.sbin/btrace/btrace.8,v
> retrieving revision 1.2
> diff -u -p -u -p -r1.2 btrace.8
> --- btrace.8 11 Sep 2020 08:16:15 -0000 1.2
> +++ btrace.8 19 Mar 2021 11:22:41 -0000
> @@ -41,6 +41,9 @@ in
> .Pp
> The options are as follows:
> .Bl -tag -width Ds
> +.It Fl d
I argue it should be `-n' like all the daemons, e.g. vmd(8) and other
parsers such as pfctl(8) do.
> +Dry run.
> +Parse the program and then exit.
> .It Fl e Ar program
> Execute
> .Ar program .
> Index: btrace.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/btrace/btrace.c,v
> retrieving revision 1.26
> diff -u -p -u -p -r1.26 btrace.c
> --- btrace.c 7 Dec 2020 18:28:09 -0000 1.26
> +++ btrace.c 19 Mar 2021 11:22:41 -0000
> @@ -123,7 +123,7 @@ main(int argc, char *argv[])
> int fd = -1, ch, error = 0;
> const char *filename = NULL, *btscript = NULL;
> const char *errstr;
> - int showprobes = 0, tracepid = -1;
> + int showprobes = 0, tracepid = -1, dryrun = 0;
>
> setlocale(LC_ALL, "");
>
> @@ -132,8 +132,11 @@ main(int argc, char *argv[])
> err(1, "pledge");
> #endif
>
> - while ((ch = getopt(argc, argv, "e:lp:v")) != -1) {
> + while ((ch = getopt(argc, argv, "de:lp:v")) != -1) {
> switch (ch) {
> + case 'd':
> + dryrun = 1;
> + break;
> case 'e':
> btscript = optarg;
> break;
> @@ -177,6 +180,9 @@ main(int argc, char *argv[])
> return error;
> }
>
> + if (dryrun)
> + return error;
> +
> if (showprobes || g_nprobes > 0) {
> fd = open(__PATH_DEVDT, O_RDONLY);
> if (fd == -1)
> @@ -200,7 +206,7 @@ main(int argc, char *argv[])
> __dead void
> usage(void)
> {
> - fprintf(stderr, "usage: %s [-lv] [-p pid] [-e program|file]\n",
> + fprintf(stderr, "usage: %s [-dlv] [-p pid] [-e program|file]\n",
While here, can you add the missing spaces arounge "|"?
> getprogname());
> exit(1);
> }
>