xref: /freebsd/usr.sbin/sysconf/sysconf.c (revision 3fe5961a0b708da599d42cbb6b5e4f030c28ea45)
1 /*
2  * Copyright (c) 2013-2026 Devin Teske <dteske@FreeBSD.org>
3  * Copyright (c) 2021-2026 Faraz Vahedi <kfv@FreeBSD.org>
4  *
5  * SPDX-License-Identifier: BSD-2-Clause
6  */
7 
8 /*
9  * sysconf(8): CLI entry, option parsing, and program state.
10  */
11 
12 #include "sysconf_priv.h"
13 
14 /* Requests to process (one per name argument) */
15 struct request	*reqs;		/* set by main() */
16 unsigned int	nreqs;		/* set by main() */
17 
18 /* Union of all directives, for `-a' against multi-file targets */
19 struct dumpent	*dumps;		/* set by scan_cb() */
20 size_t		ndumps;		/* set by scan_cb() */
21 size_t		dumpsize;	/* set by scan_cb() */
22 
23 /* Resolved target state */
24 char		**conf_files;	/* ordered backing files */
25 size_t		nconf_files;
26 size_t		conf_scanidx;	/* file being parsed (scan_pass) */
27 size_t		write_idx;	/* default write target index */
28 int		defaults_idx = -1; /* defaults file index in conf_files
29 		                    * (read-only, never listed); -1 if none */
30 enum bsdconf_format format = BSDCONF_FORMAT_GENERIC;
31 
32 /* Extra display information */
33 const char	*pgm;			/* set to getprogname() by main() */
34 bool		check = false;		/* `-c' */
35 bool		defaults_only = false;	/* `-D' */
36 bool		dump_all = false;	/* `-a' */
37 bool		existing_only = false;	/* `-E' */
38 bool		ignore_unknown = false;	/* `-i' */
39 bool		list_all = false;	/* `-L' */
40 bool		list_files = false;	/* `-l' */
41 bool		name_only = false;	/* `-N' */
42 bool		quiet = false;		/* `-q' */
43 bool		remove_mode = false;	/* `-x' */
44 bool		set_knobs = false;	/* `-s' WITH_/WITHOUT_ presence */
45 bool		show_desc = false;	/* `-d' */
46 bool		show_equals = false;	/* `-e' */
47 bool		show_file = false;	/* `-F' */
48 bool		value_only = false;	/* `-n' */
49 bool		verbose = false;	/* `-v' */
50 bool		verbose_trail = false;	/* `-V' */
51 bool		with_defaults = false;	/* `-A' */
52 
53 /* Option arguments */
54 const char	*file = NULL;		/* `-f file' */
55 bool		file_stdin = false;	/* `-f -' given */
56 const char	*jailname = NULL;	/* `-j jail' */
57 const char	*module = NULL;		/* `-k module' */
58 const char	*rootdir = "";		/* `-R dir' */
59 
60 /*
61  * Locate the target keyword in `argv' without consuming or validating
62  * anything: the first argument that is neither an option cluster nor the
63  * argument of one (per OPTSTRING; an unknown option letter is assumed to
64  * take no argument). A `--' ends option scanning as usual. Returns the
65  * argv index of the target, or -1 when there is none. Used before any
66  * getopt(3) processing so that the `rc' pass-through target (see
67  * exec_sysrc() below) can be detected while the command line is still
68  * pristine.
69  *
70  * Attached arguments (`-fPATH', `-R/altroot') are self-contained: the rest
71  * of the cluster is the option's argument, so the following argv element is
72  * not consumed. Only a trailing option letter that takes an argument and
73  * has nothing after it in the cluster (`-f PATH') skips the next element.
74  */
75 static int
76 find_target(int argc, char *argv[])
77 {
78 	int n;
79 	const char *o;
80 	const char *p;
81 
82 	for (n = 1; n < argc; n++) {
83 		if (strcmp(argv[n], "--") == 0)
84 			return (n + 1 < argc ? n + 1 : -1);
85 		if (argv[n][0] == '-' && argv[n][1] != '\0') {
86 			for (p = argv[n] + 1; *p != '\0'; p++) {
87 				o = strchr(OPTSTRING, *p);
88 				if (o != NULL && o[1] == ':') {
89 					/* Takes an argument */
90 					if (p[1] != '\0') {
91 						;
92 						/* attached: rest of argv[n] */
93 					} else if (n + 1 < argc) {
94 						n++;
95 						/* separate argv */
96 					}
97 					break;
98 				}
99 			}
100 			continue;
101 		}
102 		return (n);
103 	}
104 
105 	return (-1);
106 }
107 
108 /*
109  * The `rc' pass-through: rc.conf(5) is sysrc(8)'s domain, and its feature
110  * set is a superset of ours, so no option or argument is validated,
111  * interpreted, or reordered here -- every argument except the target
112  * keyword itself (at argv index `skip') is handed to sysrc(8) verbatim.
113  * Never returns.
114  */
115 static void
116 exec_sysrc(int argc, char *argv[], int skip)
117 {
118 	int n;
119 	int nargc = 0;
120 	char **nargv;
121 
122 	if ((nargv = calloc((size_t)argc + 1, sizeof(*nargv))) == NULL)
123 		err(EXIT_FAILURE, NULL);
124 	nargv[nargc++] = (char *)(uintptr_t)"sysrc";
125 	for (n = 1; n < argc; n++) {
126 		if (n == skip)
127 			continue;
128 		nargv[nargc++] = argv[n];
129 	}
130 	nargv[nargc] = NULL;
131 
132 	execvp("sysrc", nargv);
133 	err(EXIT_FAILURE, "sysrc");
134 }
135 
136 /*
137  * Run the getopt(3) loop over `argv', setting the option globals. Called
138  * once for the options preceding the target keyword and once for those
139  * following it. Returns the number of arguments consumed (optind).
140  */
141 static int
142 parse_options(int argc, char *argv[])
143 {
144 	int ch;
145 
146 	while ((ch = getopt(argc, argv, OPTSTRING)) != -1) {
147 		switch (ch) {
148 		case 'A': /* dump all directives, defaults included */
149 			with_defaults = 1;
150 			break;
151 		case 'a': /* dump all directives */
152 			dump_all = 1;
153 			break;
154 		case 'c': /* check only; do not modify */
155 			check = 1;
156 			break;
157 		case 'd': /* show directive descriptions */
158 			show_desc = 1;
159 			break;
160 		case 'D': /* consult the defaults file only */
161 			defaults_only = 1;
162 			break;
163 		case 'E': /* list existing files only (with -l/-L) */
164 			existing_only = 1;
165 			break;
166 		case 'e': /* show name=value */
167 			show_equals = 1;
168 			break;
169 		case 'F': /* show authoritative file, not value */
170 			show_file = 1;
171 			break;
172 		case 'f': /* explicit file (`-' is standard input) */
173 			if (strcmp(optarg, "-") == 0) {
174 				file = "/dev/stdin";
175 				file_stdin = 1;
176 			} else {
177 				file = optarg;
178 				file_stdin = 0;
179 			}
180 			break;
181 		case 'h': /* help/usage */
182 			usage();
183 			break;
184 		case 'i': /* ignore unknown names */
185 			ignore_unknown = 1;
186 			break;
187 		case 'j': /* jail name or id */
188 			jailname = optarg;
189 			break;
190 		case 'k': /* kernel module drop-in */
191 			module = optarg;
192 			break;
193 		case 'l': /* list backing files */
194 			list_files = 1;
195 			break;
196 		case 'L': /* list all candidate files */
197 			list_all = 1;
198 			break;
199 		case 'n': /* value only */
200 			value_only = 1;
201 			break;
202 		case 'N': /* name only */
203 			name_only = 1;
204 			break;
205 		case 'q': /* quiet */
206 			quiet = 1;
207 			break;
208 		case 'R': /* root dir */
209 			rootdir = optarg;
210 			break;
211 		case 's': /* set empty WITH_/WITHOUT_ knobs (make/src) */
212 			set_knobs = 1;
213 			break;
214 		case 'v': /* verbose (last file + final value) */
215 			verbose = 1;
216 			break;
217 		case 'V': /* verbose trail (every assignment step) */
218 			verbose_trail = 1;
219 			break;
220 		case 'x': /* remove */
221 			remove_mode = 1;
222 			break;
223 		case '?': /* unknown argument (based on optstring) */
224 		default: /* unhandled argument (based on switch) */
225 			usage();
226 		}
227 	}
228 
229 	return (optind);
230 }
231 
232 /*
233  * The native configuration trinity's third member: read and modify
234  * loader.conf(5), sysctl.conf(5), make.conf(5), and arbitrary configuration
235  * files with sysctl(8) assignment syntax.
236  */
237 int
238 main(int argc, char *argv[])
239 {
240 	int have_reads = 0;
241 	int have_writes = 0;
242 	int n;
243 	int rv = EXIT_SUCCESS;
244 	const char *target = NULL;
245 
246 	pgm = getprogname();
247 
248 	/*
249 	 * The `rc' target is a pure pass-through to sysrc(8), detected
250 	 * while the command line is still pristine so that nothing --
251 	 * `--help' and `--version' included -- is intercepted on its way
252 	 * there (see exec_sysrc()).
253 	 */
254 	n = find_target(argc, argv);
255 	if (n > 0 && strcmp(argv[n], "rc") == 0)
256 		exec_sysrc(argc, argv, n); /* never returns */
257 
258 	/*
259 	 * Honor `--help' and `--version' wherever they appear (getopt(3)
260 	 * knows nothing of long options and would reject them as illegal
261 	 * short options). A bare `--' ends option processing as usual.
262 	 */
263 	for (n = 1; n < argc; n++) {
264 		if (strcmp(argv[n], "--") == 0)
265 			break;
266 		if (strcmp(argv[n], "--help") == 0)
267 			help();
268 		if (strcmp(argv[n], "--version") == 0) {
269 			puts(SYSCONF_VERSION);
270 			exit(EXIT_SUCCESS);
271 		}
272 	}
273 
274 	/*
275 	 * Process command-line options
276 	 */
277 	n = parse_options(argc, argv);
278 	argc -= n;
279 	argv += n;
280 
281 	/*
282 	 * Consume the (required) target keyword and allow further options
283 	 * to follow it, mirroring the option placement freedom of
284 	 * sysctl(8) (e.g., `sysconf sysctl -L'). getopt(3) skips over its
285 	 * first argument, so hand it the target keyword's slot as the
286 	 * program name.
287 	 */
288 	if (argc > 0) {
289 		target = argv[0];
290 		argc--;
291 		argv++;
292 #ifdef __FreeBSD__
293 		optreset = 1;
294 		optind = 1;
295 #else
296 		optind = 0; /* glibc and musl re-initialize at zero */
297 #endif
298 		n = parse_options(argc + 1, argv - 1) - 1;
299 		argc -= n;
300 		argv += n;
301 	}
302 
303 	if (jailname != NULL && *rootdir != '\0') {
304 		warnx("-j and -R are mutually exclusive");
305 		usage();
306 	}
307 	if (file != NULL && module != NULL) {
308 		warnx("-f and -k are mutually exclusive");
309 		usage();
310 	}
311 	if (existing_only && !list_files && !list_all) {
312 		warnx("-E requires -l or -L");
313 		usage();
314 	}
315 	if (set_knobs && remove_mode) {
316 		warnx("-s and -x are mutually exclusive");
317 		usage();
318 	}
319 
320 #ifdef __FreeBSD__
321 	if (jailname != NULL) {
322 		int jid;
323 
324 		if ((jid = jail_getid(jailname)) < 0)
325 			errx(EXIT_FAILURE, "%s", jail_errmsg);
326 		if (jail_attach(jid) != 0)
327 			err(EXIT_FAILURE, "jail_attach(%d)", jid);
328 	}
329 #else
330 	if (jailname != NULL)
331 		errx(EXIT_FAILURE, "-j is not supported on this platform");
332 #endif
333 
334 	/* Resolve the target format and its backing files */
335 	resolve_target(target);
336 
337 	/* `-k' requires a target with a module drop-in directory */
338 	if (module != NULL) {
339 		const struct bsdconf_format_def *def;
340 		const struct bsdconf_source *source;
341 		int has_moddir = 0;
342 
343 		def = bsdconf_format_lookup(format);
344 		if (def != NULL && def->sources != NULL)
345 			for (source = def->sources; source->path != NULL;
346 			    source++)
347 				if (source->type == BSDCONF_SOURCE_MODDIR)
348 					has_moddir = 1;
349 		if (!has_moddir) {
350 			warnx("target does not support -k");
351 			usage();
352 		}
353 	}
354 
355 	/*
356 	 * `-d', `-D', and `-A' consult a body of defaults; only targets
357 	 * that have one support them (make.conf and friends have no
358 	 * defaults file, and no directive descriptions to give). The
359 	 * exception is `sysctl -d', whose descriptions come from the
360 	 * running kernel rather than any file.
361 	 */
362 	{
363 		const struct bsdconf_format_def *def;
364 		int has_defaults;
365 
366 		def = bsdconf_format_lookup(format);
367 		has_defaults = def != NULL && def->defaults != NULL;
368 
369 		if (show_desc) {
370 			if (format != BSDCONF_FORMAT_SYSCTL &&
371 			    !has_defaults) {
372 				warnx("target does not support -d");
373 				usage();
374 			}
375 			if (file != NULL) {
376 				warnx("-d and -f are mutually exclusive");
377 				usage();
378 			}
379 			if (list_files || list_all || remove_mode || check ||
380 			    set_knobs) {
381 				warnx("-d cannot be combined with "
382 				    "-c/-l/-L/-s/-x");
383 				usage();
384 			}
385 #ifdef __FreeBSD__
386 			if (format == BSDCONF_FORMAT_SYSCTL &&
387 			    *rootdir != '\0')
388 				errx(EXIT_FAILURE, "sysctl descriptions "
389 				    "come from the running kernel; "
390 				    "-R does not apply");
391 #endif
392 		}
393 		if ((defaults_only || with_defaults) && !has_defaults) {
394 			warnx("target does not support -%c",
395 			    defaults_only ? 'D' : 'A');
396 			usage();
397 		}
398 		if ((defaults_only || with_defaults) && file != NULL) {
399 			warnx("-%c and -f are mutually exclusive",
400 			    defaults_only ? 'D' : 'A');
401 			usage();
402 		}
403 	}
404 
405 	/* File listings take no names and perform no other work */
406 	if (list_files || list_all) {
407 		if (argc != 0 || dump_all) {
408 			warnx("-l/-L take no names");
409 			usage();
410 		}
411 		exit(do_list());
412 	}
413 
414 	/* `-A' with no names dumps everything, defaults included */
415 	if (with_defaults && argc == 0)
416 		dump_all = 1;
417 
418 	/* Display usage and exit if not given at least one name */
419 	if (argc == 0 && !dump_all) {
420 		warnx("no names provided");
421 		usage();
422 	}
423 	if (argc != 0 && dump_all) {
424 		warnx("-a does not take names");
425 		usage();
426 	}
427 
428 	/* Classify the remaining arguments */
429 	nreqs = (unsigned int)argc;
430 	if (nreqs > 0 &&
431 	    (reqs = calloc(nreqs, sizeof(*reqs))) == NULL)
432 		err(EXIT_FAILURE, NULL);
433 	if (set_knobs) {
434 		if (format != BSDCONF_FORMAT_MAKE &&
435 		    format != BSDCONF_FORMAT_SRC) {
436 			warnx("-s is only valid for make and src");
437 			usage();
438 		}
439 		if (argc == 0) {
440 			warnx("-s requires at least one WITH_/WITHOUT_ name");
441 			usage();
442 		}
443 	}
444 	for (n = 0; n < argc; n++) {
445 		split_request(argv[n], &reqs[n], remove_mode);
446 		if (set_knobs) {
447 			if (reqs[n].newvalue != NULL) {
448 				warnx("-s does not take a value "
449 				    "('%s')", argv[n]);
450 				usage();
451 			}
452 			if (!make_knob_name_p(reqs[n].name)) {
453 				if (strcmp(reqs[n].name,
454 				    "WITHOUT_MODULES") == 0)
455 					warnx("WITHOUT_MODULES takes a "
456 					    "module list; use "
457 					    "WITHOUT_MODULES=...");
458 				else
459 					warnx("-s requires a WITH_ or "
460 					    "WITHOUT_ name ('%s')",
461 					    reqs[n].name);
462 				usage();
463 			}
464 			reqs[n].newvalue = "";
465 		}
466 			if (reqs[n].newvalue != NULL && !reqs[n].remove)
467 				warn_with_equals_no(reqs[n].name,
468 				    reqs[n].newvalue, NULL, 0);
469 		if (reqs[n].remove || reqs[n].newvalue != NULL)
470 			have_writes = 1;
471 		else
472 			have_reads = 1;
473 	}
474 	if (check && !have_writes) {
475 		warnx("-c requires at least one name=value or -s name");
476 		usage();
477 	}
478 
479 	/* Descriptions are read-only */
480 	if (show_desc) {
481 		if (have_writes) {
482 			warnx("-d does not take values");
483 			usage();
484 		}
485 #ifndef __FreeBSD__
486 		if (format == BSDCONF_FORMAT_SYSCTL)
487 			errx(EXIT_FAILURE,
488 			    "sysctl descriptions require FreeBSD");
489 #endif
490 		/* Explicit names need no file scan at all */
491 		if (!dump_all) {
492 #ifdef __FreeBSD__
493 			if (format == BSDCONF_FORMAT_SYSCTL)
494 				exit(describe_sysctl());
495 #endif
496 			exit(describe_defaults());
497 		}
498 
499 		/*
500 		 * Dumps (-ad, -Ad, -aDd) pair each scanned directive with
501 		 * its description; harvest the descriptions before the
502 		 * read sandbox slams shut.
503 		 */
504 		if (format != BSDCONF_FORMAT_SYSCTL)
505 			load_descriptions();
506 	}
507 
508 	/* Defaults can be read and checked against, never rewritten */
509 	if ((defaults_only || with_defaults) && have_writes && !check)
510 		errx(EXIT_FAILURE, "defaults are read-only");
511 
512 	/* Standard input can be read and checked, never rewritten */
513 	if (file_stdin && have_writes && !check)
514 		errx(EXIT_FAILURE, "cannot write to standard input");
515 
516 #if defined(__FreeBSD__)
517 	/*
518 	 * Refuse up front to set sysctl OIDs that can never take effect
519 	 * from sysctl.conf(5) (non-leaf, read-only, loader-only tunables)
520 	 * or whose values cannot fit the OID's CTLTYPE (so an overflowing
521 	 * assignment cannot surprise sysctl(8) at boot). Unknown OIDs are
522 	 * warned about but still written -- the module may not be loaded
523 	 * yet, matching init(8)'s handling of sysctl.conf(5). Only
524 	 * meaningful against the running system's sysctl tree, so skipped
525 	 * under -R. -i/-q quiet the unknown-OID warning; -k remains the
526 	 * module drop-in selector.
527 	 */
528 	if (format == BSDCONF_FORMAT_SYSCTL && have_writes && !check &&
529 	    *rootdir == '\0') {
530 		int quiet_unknown = ignore_unknown || quiet;
531 		unsigned int u;
532 
533 		for (u = 0; u < nreqs; u++) {
534 			if (reqs[u].newvalue == NULL)
535 				continue;
536 			if (sysctl_writable(reqs[u].name, reqs[u].newvalue,
537 			    quiet_unknown) != 0) {
538 				/* Convert to a no-op; count the failure */
539 				reqs[u].newvalue = NULL;
540 				reqs[u].remove = 0;
541 				reqs[u].name = "";
542 				rv = EXIT_FAILURE;
543 			}
544 		}
545 		have_writes = 0;
546 		have_reads = 0;
547 		for (u = 0; u < nreqs; u++) {
548 			if (reqs[u].remove || reqs[u].newvalue != NULL)
549 				have_writes = 1;
550 			else if (reqs[u].name[0] != '\0')
551 				have_reads = 1;
552 		}
553 		if (rv != EXIT_SUCCESS && !have_writes && !have_reads)
554 			exit(rv); /* nothing settable remains */
555 	}
556 #endif
557 
558 	/*
559 	 * Scan the backing files to locate each request's authoritative
560 	 * definition. Pure reads and -c checks (do_checks() never calls
561 	 * put) run the scan inside a Capsicum sandbox -- except a sysctl
562 	 * description dump, whose kernel queries the sandbox would deny.
563 	 * Classify by whether we will actually write, not by whether the
564 	 * argv looked like name=value (`-c' sets have_writes for checks).
565 	 */
566 	scan_pass((check || !have_writes) &&
567 	    !(show_desc && format == BSDCONF_FORMAT_SYSCTL));
568 
569 	/* Materialize list edits now that effective values are known */
570 	if (merge_list_requests() != EXIT_SUCCESS)
571 		rv = EXIT_FAILURE;
572 
573 	if (check) {
574 		if (do_make_strikes(1) != EXIT_SUCCESS)
575 			rv = EXIT_FAILURE;
576 		if (do_checks() != EXIT_SUCCESS)
577 			rv = EXIT_FAILURE;
578 		exit(rv);
579 	}
580 
581 	/* Apply writes first so that subsequent reads see the result */
582 	if (have_writes) {
583 		int wrv;
584 
585 		if ((wrv = do_make_strikes(0)) != EXIT_SUCCESS)
586 			rv = wrv;
587 		if ((wrv = do_writes()) != EXIT_SUCCESS)
588 			rv = wrv;
589 
590 		/* Refresh the scan for any trailing read requests */
591 		if (have_reads || dump_all) {
592 			for (n = 0; (unsigned int)n < nreqs; n++) {
593 				size_t ai;
594 
595 				trail_free(reqs[n].trail, reqs[n].ntrail);
596 				reqs[n].trail = NULL;
597 				reqs[n].ntrail = 0;
598 				for (ai = 0; ai < reqs[n].nassigns; ai++)
599 					free(reqs[n].assigns[ai].piece);
600 				free(reqs[n].assigns);
601 				reqs[n].assigns = NULL;
602 				reqs[n].nassigns = 0;
603 				reqs[n].found = 0;
604 				reqs[n].append_present = 0;
605 				reqs[n].srcidx = -1;
606 				reqs[n].line = 0;
607 				memset(reqs[n].infile, 0, nconf_files);
608 			}
609 			scan_pass(0);
610 		}
611 	}
612 
613 	if (have_reads || dump_all) {
614 		int rrv;
615 
616 		if ((rrv = do_reads()) != EXIT_SUCCESS)
617 			rv = rrv;
618 	}
619 
620 	exit(rv);
621 }
622 
623 /*
624  * Print short usage statement to stderr and exit with error status.
625  */
626 void
627 usage(void)
628 {
629 
630 	fprintf(stderr,
631 	    "usage: %s target [-AcDeFinNqsvVx] [-j jail | -R dir]"
632 	    " [-f file | -k module]\n"
633 	    "               name[[+|-]=value] ...\n", pgm);
634 	fprintf(stderr,
635 	    "       %s target [-ADeFnNqvV] [-j jail | -R dir]"
636 	    " [-f file | -k module] -a\n", pgm);
637 	fprintf(stderr,
638 	    "       %s target [-AaDinNq] [-j jail | -R dir]"
639 	    " -d [name ...]\n", pgm);
640 	fprintf(stderr,
641 	    "       %s target [-E] [-j jail | -R dir] [-k module]"
642 	    " -l | -L\n", pgm);
643 	fprintf(stderr,
644 	    "       %s rc [sysrc(8) argument ...]\n", pgm);
645 	fprintf(stderr, "Try `%s --help' for more information.\n", pgm);
646 	exit(EXIT_FAILURE);
647 }
648 
649 /*
650  * Print long usage statement to stderr and exit with error status.
651  */
652 void
653 help(void)
654 {
655 
656 	fprintf(stderr,
657 	    "usage: %s target [-AcDeFinNqsvVx] [-j jail | -R dir]"
658 	    " [-f file | -k module] name[[+|-]=value] ...\n", pgm);
659 	fprintf(stderr, "TARGETS:\n");
660 #define TGTFMT "\t%-9s %s\n"
661 	fprintf(stderr, TGTFMT, "loader",
662 	    "files named by loader_conf_files et al. in");
663 	fprintf(stderr, TGTFMT, "",
664 	    "/boot/defaults/loader.conf (typically /boot/loader.conf,");
665 	fprintf(stderr, TGTFMT, "",
666 	    "loader.conf.d/*.conf, loader.conf.local)");
667 	fprintf(stderr, TGTFMT, "sysctl",
668 	    "/etc/sysctl.conf, sysctl.conf.local, sysctl.kld.d/*.conf");
669 	fprintf(stderr, TGTFMT, "make",
670 	    "/etc/make.conf (or -f for any make-syntax file)");
671 	fprintf(stderr, TGTFMT, "src",
672 	    "/usr/src build triad: src-env.conf, make.conf, src.conf");
673 	fprintf(stderr, TGTFMT, "",
674 	    "(new writes prefer src.conf; env: SRC_ENV_CONF,");
675 	fprintf(stderr, TGTFMT, "",
676 	    "__MAKE_CONF, SRCCONF)");
677 	fprintf(stderr, TGTFMT, "rc",
678 	    "pass-through: all other arguments go to sysrc(8) verbatim");
679 	fprintf(stderr, TGTFMT, "generic",
680 	    "no default files; requires -f file");
681 	fprintf(stderr, "OPTIONS:\n");
682 #define OPTFMT "\t%-9s %s\n"
683 	fprintf(stderr, OPTFMT, "-A",
684 	    "Include the target's defaults file in the sourcing order");
685 	fprintf(stderr, OPTFMT, "",
686 	    "(alone, dumps everything, defaults included).");
687 	fprintf(stderr, OPTFMT, "-a",
688 	    "Dump the union of all directives from the target's files.");
689 	fprintf(stderr, OPTFMT, "-c",
690 	    "Check. Return success if no changes needed, else error.");
691 	fprintf(stderr, OPTFMT, "-D",
692 	    "Consult only the target's defaults file.");
693 	fprintf(stderr, OPTFMT, "-d",
694 	    "Show directive descriptions (from the defaults file's");
695 	fprintf(stderr, OPTFMT, "",
696 	    "comments; for sysctl, from the running kernel). With");
697 	fprintf(stderr, OPTFMT, "",
698 	    "-a, -A, or -D, describe every directive in scope.");
699 	fprintf(stderr, OPTFMT, "-E",
700 	    "With -l or -L, list only files that exist on disk.");
701 	fprintf(stderr, OPTFMT, "-e",
702 	    "Separate name and value with `=' (reads and write echoes).");
703 	fprintf(stderr, OPTFMT, "-F",
704 	    "Show the file holding each directive's effective value.");
705 	fprintf(stderr, OPTFMT, "-f file",
706 	    "Operate on file, in the target's format, instead of the");
707 	fprintf(stderr, OPTFMT, "",
708 	    "target's standard files (`-' means standard input).");
709 	fprintf(stderr, OPTFMT, "-h",
710 	    "Print a short usage statement to stderr and exit.");
711 	fprintf(stderr, OPTFMT, "--help",
712 	    "Print this message to stderr and exit.");
713 	fprintf(stderr, OPTFMT, "--version",
714 	    "Print version information to stdout and exit.");
715 	fprintf(stderr, OPTFMT, "-i",
716 	    "Ignore unknown names (and quiet unknown sysctl OID warnings).");
717 	fprintf(stderr, OPTFMT, "-j jail",
718 	    "Operate within the jail `jail' (name or numeric id).");
719 	fprintf(stderr, OPTFMT, "-k module",
720 	    "Include the kernel module drop-in file for `module'.");
721 	fprintf(stderr, OPTFMT, "-l",
722 	    "List the pathnames of the target's backing files.");
723 	fprintf(stderr, OPTFMT, "-L",
724 	    "List all candidate files, including module drop-ins.");
725 	fprintf(stderr, OPTFMT, "-n",
726 	    "Show only directive values, not their names.");
727 	fprintf(stderr, OPTFMT, "-N",
728 	    "Show only directive names, not their values.");
729 	fprintf(stderr, OPTFMT, "-q",
730 	    "Quiet. Suppress unknown-directive warnings and the");
731 	fprintf(stderr, OPTFMT, "",
732 	    "`old -> new' echo of writes.");
733 	fprintf(stderr, OPTFMT, "-R dir",
734 	    "Operate within the root directory `dir' rather than `/'.");
735 	fprintf(stderr, OPTFMT, "-s",
736 	    "Set empty WITH_/WITHOUT_ knobs (make and src only).");
737 	fprintf(stderr, OPTFMT, "-v",
738 	    "Verbose. Print the pathname of the configuration file");
739 	fprintf(stderr, OPTFMT, "",
740 	    "holding the final effective value.");
741 	fprintf(stderr, OPTFMT, "-V",
742 	    "Trail. Reads: each assignment step (file:line, operator,");
743 	fprintf(stderr, OPTFMT, "",
744 	    "fragment, running effective). Writes: file:line:");
745 	fprintf(stderr, OPTFMT, "",
746 	    "name=old -> name=new (or name=value (unchanged)).");
747 	fprintf(stderr, OPTFMT, "-x",
748 	    "Remove name(s) from the target's files.");
749 	fprintf(stderr, "ENVIRONMENT:\n");
750 	fprintf(stderr, OPTFMT, "LOADER_DEFAULTS",
751 	    "Defaults file for the loader target (in place of");
752 	fprintf(stderr, OPTFMT, "",
753 	    "/boot/defaults/loader.conf).");
754 	fprintf(stderr, OPTFMT, "SRC_ENV_CONF",
755 	    "src-env.conf for the src target (default /etc/src-env.conf).");
756 	fprintf(stderr, OPTFMT, "__MAKE_CONF",
757 	    "make.conf for the src target (default /etc/make.conf).");
758 	fprintf(stderr, OPTFMT, "SRCCONF",
759 	    "src.conf for the src target (default /etc/src.conf).");
760 	exit(EXIT_FAILURE);
761 }
762