diff options
Diffstat (limited to 'usr.bin')
43 files changed, 815 insertions, 438 deletions
diff --git a/usr.bin/apply/apply.1 b/usr.bin/apply/apply.1 index f1c114d40814..1e0115364e81 100644 --- a/usr.bin/apply/apply.1 +++ b/usr.bin/apply/apply.1 @@ -96,7 +96,7 @@ The following environment variable affects the execution of .Bl -tag -width SHELL .It Ev SHELL Pathname of shell to use. -If this variable is not defined, the Bourne shell is used. +If this variable is not defined, the POSIX shell is used. .El .Sh FILES .Bl -tag -width /bin/sh -compact diff --git a/usr.bin/backlight/backlight.8 b/usr.bin/backlight/backlight.8 index 25fa91c0060c..291d1628d5ea 100644 --- a/usr.bin/backlight/backlight.8 +++ b/usr.bin/backlight/backlight.8 @@ -73,10 +73,10 @@ A trailing .Dq % is valid. .It Cm incr Ns | Ns Cm + Op Ar value -Decrement the backlight level. +Increment the backlight level. If no value is specified a default of 10 percent is used. .It Cm decr Ns | Ns Cm - Op Ar value -Increment the backlight level. +Decrement the backlight level. If no value is specified a default of 10 percent is used. .El .Sh EXAMPLES diff --git a/usr.bin/bmake/Makefile b/usr.bin/bmake/Makefile index a8bcdfd9f859..8d23bb8dd203 100644 --- a/usr.bin/bmake/Makefile +++ b/usr.bin/bmake/Makefile @@ -11,7 +11,7 @@ CFLAGS+= -I${.CURDIR} CLEANDIRS+= FreeBSD CLEANFILES+= bootstrap -# $Id: Makefile,v 1.133 2025/03/08 20:12:56 sjg Exp $ +# $Id: Makefile,v 1.137 2026/03/13 15:37:22 sjg Exp $ PROG?= ${.CURDIR:T} @@ -40,9 +40,6 @@ SRCS= \ .MAIN: all -MAN= ${PROG}.1 -SRCS.${MAN}= ${srcdir}/make.1 - .-include "Makefile.inc" # this file gets generated by configure @@ -57,6 +54,9 @@ prefix?= /usr srcdir?= ${.PARSEDIR} srcdir:= ${srcdir} +MAN?= ${PROG}.1 +SRCS.${MAN}?= ${srcdir}/make.1 + DEFAULT_SYS_PATH?= ${prefix}/share/mk CPPFLAGS+= -DUSE_META @@ -66,7 +66,13 @@ CFLAGS+= -I. -I${srcdir} ${XDEFS} -DMAKE_NATIVE CFLAGS+= ${COPTS.${.ALLSRC:M*.c:T:u}} COPTS.main.c+= "-DMAKE_VERSION=\"${_MAKE_VERSION}\"" -.for x in FORCE_MAKE_OS FORCE_MACHINE FORCE_MACHINE_ARCH +# bmake defaults to the traditional behavior +MAKE_SAVE_DOLLARS_DEFAULT?= no + +VARS.main+= FORCE_MAKE_OS FORCE_MACHINE FORCE_MACHINE_ARCH \ + MAKE_SAVE_DOLLARS_DEFAULT \ + +.for x in ${VARS.main} .ifdef $x COPTS.main.c+= "-D$x=\"${$x}\"" .endif @@ -164,7 +170,8 @@ SHAREDIR= ${SHAREDIR.bmake:U${prefix}/share} BINDIR= ${BINDIR.bmake:U${prefix}/bin} MANDIR= ${MANDIR.bmake:U${SHAREDIR}/man} -${OBJS}: config.h +${OBJS}: .META config.h +${PROG}: .META # A simple unit-test driver to help catch regressions diff --git a/usr.bin/bmake/Makefile.config b/usr.bin/bmake/Makefile.config index 16cce3e1658a..5ba662b3145e 100644 --- a/usr.bin/bmake/Makefile.config +++ b/usr.bin/bmake/Makefile.config @@ -6,7 +6,7 @@ SRCTOP?= ${.CURDIR:H:H} # things set by configure -_MAKE_VERSION?=20251111 +_MAKE_VERSION?=20260313 prefix?= /usr srcdir= ${SRCTOP}/contrib/bmake diff --git a/usr.bin/bmake/unit-tests/Makefile b/usr.bin/bmake/unit-tests/Makefile index d04a45b93247..c7ac7ee5fed1 100644 --- a/usr.bin/bmake/unit-tests/Makefile +++ b/usr.bin/bmake/unit-tests/Makefile @@ -1,9 +1,9 @@ # This is a generated file, do NOT edit! # See contrib/bmake/bsd.after-import.mk # -# $Id: Makefile,v 1.251 2025/11/15 17:17:18 sjg Exp $ +# $Id: Makefile,v 1.260 2026/03/10 15:45:51 sjg Exp $ # -# $NetBSD: Makefile,v 1.373 2025/11/12 22:14:08 sjg Exp $ +# $NetBSD: Makefile,v 1.383 2026/03/10 15:38:26 sjg Exp $ # # Unit tests for make(1) # @@ -632,6 +632,9 @@ SED_CMDS.opt-chdir= -e 's,\(nonexistent\).[1-9][0-9]*,\1,' \ -e 's,no such,No such,' \ -e 's,Filename,File name,' +SED_CMDS.gnode-submake= ${STD_SED_CMDS.dj} +SED_CMDS.gnode-submake= ${STD_SED_CMDS.dg2} + # meta line numbers can vary based on filemon implementation SED_CMDS.meta-ignore= -e 's,\(\.meta:\)[1-9][0-9]*:,\1<line>:,' @@ -645,6 +648,7 @@ SED_CMDS.opt-debug-lint+= ${STD_SED_CMDS.regex} SED_CMDS.opt-jobs-no-action= ${STD_SED_CMDS.hide-from-output} SED_CMDS.opt-no-action-runflags= ${STD_SED_CMDS.hide-from-output} SED_CMDS.opt-where-am-i= -e '/usr.obj/d' +SED_CMDS.opt-where-am-i+= -e '/\/\//d' # For Compat_RunCommand, useShell == false. SED_CMDS.sh-dots= -e 's,^.*\.\.\.:.*,<not found: ...>,' # For Compat_RunCommand, useShell == true. @@ -665,6 +669,7 @@ SED_CMDS.var-op-shell+= -e '/command/s,No such.*,not found,' SED_CMDS.var-op-shell+= ${STD_SED_CMDS.white-space} SED_CMDS.vardebug+= -e 's,${.SHELL},</path/to/shell>,' SED_CMDS.varmod-mtime+= -e "s,\(mtime for .*\): .*,\1: <ENOENT>," +SED_CMDS.varmod-subst+= ${STD_SED_CMDS.regex} SED_CMDS.varmod-subst-regex+= ${STD_SED_CMDS.regex} SED_CMDS.varparse-errors+= ${STD_SED_CMDS.timestamp} SED_CMDS.varname-dot-make-meta-ignore_filter+= ${SED_CMDS.meta-ignore} @@ -680,7 +685,10 @@ SED_CMDS.varname-empty= ${.OBJDIR .PARSEDIR .PATH .SHELL .SYSPATH:L:@v@-e '/\\$ # Some tests need an additional round of postprocessing. POSTPROC.depsrc-wait= sed -e '/^---/d' -e 's,^\(: Making 3[abc]\)[123]$$,\1,' POSTPROC.deptgt-suffixes= awk '/^\#\*\*\* Suffixes/,/^never-stop/' -POSTPROC.gnode-submake= awk '/Begin input graph/, /^$$/' +POSTPROC.gnode-submake= \ + awk '/Begin input graph/, /^\# \.END/ { \ + if (/made,/) print $$0 \ + }' POSTPROC.varname-dot-make-mode= sed 's,^\(: Making [abc]\)[123]$$,\1,' # Some tests reuse other tests, which makes them unnecessarily fragile. @@ -703,6 +711,7 @@ STD_SED_CMDS.dg1= -e '/\#.* \.$$/d' STD_SED_CMDS.dg1+= -e '/\.MAKE.PATH_FILEMON/d' STD_SED_CMDS.dg1+= -e '/^\#.*\/mk/d' STD_SED_CMDS.dg1+= -e 's, ${DEFSYSPATH:U/usr/share/mk}$$, <defsyspath>,' +STD_SED_CMDS.dg1+= -e '/^\.MAKE\.PATH_FILEMON/d' STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE *=\) .*,\1 <details omitted>,' STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE\.[A-Z_]* *=\) .*,\1 <details omitted>,' STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE\.JOBS\.C *=\) .*,\1 <details omitted>,' @@ -713,6 +722,7 @@ STD_SED_CMDS.dg1+= -e '/\.SYSPATH/d' STD_SED_CMDS.dg2= ${STD_SED_CMDS.dg1} STD_SED_CMDS.dg2+= -e 's,\(last modified\) ..:..:.. ... ..\, ....,\1 <timestamp>,' + STD_SED_CMDS.dg3= ${STD_SED_CMDS.dg2} # Omit details such as process IDs from the output of the -dj option. @@ -795,6 +805,16 @@ clean: rm -f ${CLEANFILES} TEST_MAKE?= ${.MAKE} +.if ${TEST_MAKE:M/*} == "" +# we want an absolute path for TEST_MAKE +tm!= for d in ${PATH:S,:, ,g:M/*}; do \ + test -x $$d/${TEST_MAKE} || continue; \ + echo $$d/${TEST_MAKE}; break; done +.if ${tm:M/*} +TEST_MAKE:= ${tm} +.endif +.endif + TOOL_SED?= sed TOOL_TR?= tr TOOL_DIFF?= diff @@ -834,7 +854,7 @@ LIMIT_RESOURCES?= : # each other, and because they use different environment variables and # command line options. .SUFFIXES: .mk .rawout .out -.mk.rawout: +.mk.rawout: .META @${_MKMSG_TEST:Uecho '# test '} ${.PREFIX} @set -eu; \ ${LIMIT_RESOURCES}; \ @@ -876,7 +896,8 @@ _SED_CMDS+= -e 's,^usage: ${TEST_MAKE:T:S,.,\\.,g} ,usage: make ,' _SED_CMDS+= -e 's,${TEST_MAKE:T:S,.,\\.,g}\(\[[1-9][0-9]*\][: ]\),make\1,' _SED_CMDS+= -e 's,<curdir>/,,g' _SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g' -_SED_CMDS+= -e '/MAKE_VERSION/d' +_SED_CMDS+= -e 's,\(\.make\)[1-9][0-9]*,\1,g' +_SED_CMDS+= -e '/MAKE.VERSION/d' _SED_CMDS+= -e '/EGREP=/d' # on AT&T derived systems: false exits 255 not 1 @@ -889,7 +910,7 @@ SED_CMDS.opt-debug-jobs+= -e 's,Command: ksh -v,Command: <shell>,' SED_CMDS.opt-debug-jobs+= -e 's,Command: <shell> -v,Command: <shell>,' .endif -.rawout.out: +.rawout.out: .META @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.PREFIX:T}} ${_SED_CMDS_LAST} \ < ${.IMPSRC} > ${.TARGET}.tmp @${POSTPROC.${.PREFIX:T}:D \ diff --git a/usr.bin/calendar/calendars/calendar.freebsd b/usr.bin/calendar/calendars/calendar.freebsd index 37dad2d237a7..9084ed0589ec 100644 --- a/usr.bin/calendar/calendars/calendar.freebsd +++ b/usr.bin/calendar/calendars/calendar.freebsd @@ -337,6 +337,7 @@ 08/14 Stefan Esser <se@FreeBSD.org> born in Cologne, Nordrhein-Westfalen, Germany, 1961 08/16 Andrey Chernov <ache@FreeBSD.org> died in Moscow, Russian Federation, 2017 08/17 Olivier Houchard <cognet@FreeBSD.org> born in Nancy, France, 1980 +08/18 Pierre Pronchery <khorben@FreeBSD.org> born in Nantes, France, 1982 08/19 Chin-San Huang <chinsan@FreeBSD.org> born in Yi-Lan, Taiwan, Republic of China, 1979 08/19 Pav Lucistnik <pav@FreeBSD.org> born in Kutna Hora, Czech Republic, 1980 08/20 Michael Heffner <mikeh@FreeBSD.org> born in Cleona, Pennsylvania, United States, 1981 diff --git a/usr.bin/chpass/chpass.1 b/usr.bin/chpass/chpass.1 index 0891f3f28c92..0321d748a1a4 100644 --- a/usr.bin/chpass/chpass.1 +++ b/usr.bin/chpass/chpass.1 @@ -227,7 +227,7 @@ The field is the command interpreter the user prefers. If the .Ar shell -field is empty, the Bourne shell, +field is empty, the POSIX shell, .Pa /bin/sh , is assumed. When altering a login shell, and not the super-user, the user diff --git a/usr.bin/clang/llvm.prog.mk b/usr.bin/clang/llvm.prog.mk index 00f319a246fb..fa9abf020295 100644 --- a/usr.bin/clang/llvm.prog.mk +++ b/usr.bin/clang/llvm.prog.mk @@ -14,7 +14,7 @@ LIBPRIV= LIBEXT= a .else LIBDEPS+= llvm -.if ${MK_LLVM_LINK_STATIC_LIBRARIES} == "yes" +.if defined(TOOLS_PREFIX) || ${MK_LLVM_LINK_STATIC_LIBRARIES} == "yes" LIBPRIV= LIBEXT= a .else diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c index 8dcf55a7190b..5c1147bf2730 100644 --- a/usr.bin/diff/diffreg.c +++ b/usr.bin/diff/diffreg.c @@ -542,6 +542,11 @@ opentemp(const char *f) return (NULL); } } + if (nread == -1) { + close(ifd); + close(ofd); + return (NULL); + } close(ifd); lseek(ofd, (off_t)0, SEEK_SET); return (fdopen(ofd, "r")); diff --git a/usr.bin/diff/pr.c b/usr.bin/diff/pr.c index 189e6b34649e..e8a4162d8b18 100644 --- a/usr.bin/diff/pr.c +++ b/usr.bin/diff/pr.c @@ -29,8 +29,10 @@ #include <err.h> #include <errno.h> +#include <fcntl.h> #include <paths.h> #include <signal.h> +#include <spawn.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -41,6 +43,8 @@ #define _PATH_PR "/usr/bin/pr" +extern char **environ; + struct pr * start_pr(char *file1, char *file2) { @@ -48,40 +52,49 @@ start_pr(char *file1, char *file2) pid_t pid; char *header; struct pr *pr; + posix_spawn_file_actions_t fa; + posix_spawnattr_t sa; + int error; pr = xcalloc(1, sizeof(*pr)); xasprintf(&header, "%s %s %s", diffargs, file1, file2); signal(SIGPIPE, SIG_IGN); fflush(stdout); - if (pipe(pfd) == -1) + if (pipe2(pfd, O_CLOEXEC) == -1) err(2, "pipe"); - switch ((pid = pdfork(&pr->procd, PD_CLOEXEC))) { - case -1: - err(2, "No more processes"); - case 0: - /* child */ - if (pfd[0] != STDIN_FILENO) { - dup2(pfd[0], STDIN_FILENO); - close(pfd[0]); + + if ((error = posix_spawnattr_init(&sa)) != 0) + errc(2, error, "posix_spawnattr_init"); + if ((error = posix_spawn_file_actions_init(&fa)) != 0) + errc(2, error, "posix_spawn_file_actions_init"); + + posix_spawnattr_setprocdescp_np(&sa, &pr->procd, 0); + + if (pfd[0] != STDIN_FILENO) + posix_spawn_file_actions_adddup2(&fa, pfd[0], STDIN_FILENO); + + char *argv[] = { __DECONST(char *, _PATH_PR), + __DECONST(char *, "-h"), header, NULL }; + error = posix_spawn(&pid, _PATH_PR, &fa, &sa, argv, environ); + if (error != 0) + errc(2, error, "could not spawn pr"); + + posix_spawn_file_actions_destroy(&fa); + posix_spawnattr_destroy(&sa); + + /* parent */ + if (pfd[1] == STDOUT_FILENO) { + pr->ostdout = STDOUT_FILENO; + } else { + if ((pr->ostdout = dup(STDOUT_FILENO)) < 0 || + dup2(pfd[1], STDOUT_FILENO) < 0) { + err(2, "stdout"); } close(pfd[1]); - execl(_PATH_PR, _PATH_PR, "-h", header, (char *)0); - _exit(127); - default: - /* parent */ - if (pfd[1] == STDOUT_FILENO) { - pr->ostdout = STDOUT_FILENO; - } else { - if ((pr->ostdout = dup(STDOUT_FILENO)) < 0 || - dup2(pfd[1], STDOUT_FILENO) < 0) { - err(2, "stdout"); - } - close(pfd[1]); - } - close(pfd[0]); - free(header); } + close(pfd[0]); + free(header); return (pr); } diff --git a/usr.bin/diff3/diff3.c b/usr.bin/diff3/diff3.c index d85a5da94b10..bbef1f0d21a5 100644 --- a/usr.bin/diff3/diff3.c +++ b/usr.bin/diff3/diff3.c @@ -73,14 +73,17 @@ #include <capsicum_helpers.h> #include <ctype.h> #include <err.h> +#include <fcntl.h> #include <getopt.h> #include <inttypes.h> #include <limits.h> +#include <spawn.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> +extern char **environ; /* * "from" is first in range of changed lines; "to" is last+1 * from=to=line after point of insertion for added lines. @@ -301,23 +304,27 @@ readin(int fd, struct diff **dd) } static int -diffexec(const char *diffprog, char **diffargv, int fd[]) +diffexec(char **diffargv, int fd[]) { - int pd; + posix_spawnattr_t sa; + posix_spawn_file_actions_t fa; + pid_t pid; + int pd, error; - switch (pdfork(&pd, PD_CLOEXEC)) { - case 0: - close(fd[0]); - if (dup2(fd[1], STDOUT_FILENO) == -1) - err(2, "child could not duplicate descriptor"); - close(fd[1]); - execvp(diffprog, diffargv); - err(2, "could not execute diff: %s", diffprog); - break; - case -1: - err(2, "could not fork"); - break; - } + if ((error = posix_spawnattr_init(&sa)) != 0) + errc(2, error, "posix_spawnattr_init"); + if ((error = posix_spawn_file_actions_init(&fa)) != 0) + errc(2, error, "posix_spawn_file_actions_init"); + + posix_spawnattr_setprocdescp_np(&sa, &pd, 0); + posix_spawn_file_actions_adddup2(&fa, fd[1], STDOUT_FILENO); + + error = posix_spawn(&pid, diffargv[0], &fa, &sa, diffargv, environ); + if (error != 0) + errc(2, error, "could not spawn diff"); + + posix_spawn_file_actions_destroy(&fa); + posix_spawnattr_destroy(&sa); close(fd[1]); return (pd); } @@ -937,6 +944,7 @@ wait_and_check(int pd) if (errno != EINTR) err(2, "pdwait"); } + close(pd); if (WIFEXITED(status) && WEXITSTATUS(status) >= 2) errx(2, "diff exited abnormally"); @@ -1004,7 +1012,7 @@ main(int argc, char **argv) eflag = EFLAG_OVERLAP; break; case DIFFPROG_OPT: - diffprog = optarg; + diffargv[0] = optarg; break; case STRIPCR_OPT: strip_cr = 1; @@ -1074,18 +1082,18 @@ main(int argc, char **argv) if (caph_rights_limit(fileno(fp[2]), &rights_ro) < 0) err(2, "unable to limit rights on: %s", file3); - if (pipe(fd13)) + if (pipe2(fd13, O_CLOEXEC)) err(2, "pipe"); - if (pipe(fd23)) + if (pipe2(fd23, O_CLOEXEC)) err(2, "pipe"); diffargv[diffargc] = file1; diffargv[diffargc + 1] = file3; diffargv[diffargc + 2] = NULL; - pd13 = diffexec(diffprog, diffargv, fd13); + pd13 = diffexec(diffargv, fd13); diffargv[diffargc] = file2; - pd23 = diffexec(diffprog, diffargv, fd23); + pd23 = diffexec(diffargv, fd23); caph_cache_catpages(); if (caph_enter() < 0) diff --git a/usr.bin/du/du.1 b/usr.bin/du/du.1 index 1b6d800b0285..3b330de7bc5b 100644 --- a/usr.bin/du/du.1 +++ b/usr.bin/du/du.1 @@ -25,7 +25,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd July 16, 2025 +.Dd April 15, 2026 .Dt DU 1 .Os .Sh NAME @@ -225,8 +225,8 @@ Also display a grand total at the end: .Xr chflags 2 , .Xr fts 3 , .Xr libxo 3 , -.Xr xo_options 7 , .Xr symlink 7 , +.Xr xo_options 7 , .Xr quot 8 .Sh STANDARDS The diff --git a/usr.bin/du/du.c b/usr.bin/du/du.c index 16ca05fa9edc..bf138b1b5e36 100644 --- a/usr.bin/du/du.c +++ b/usr.bin/du/du.c @@ -35,7 +35,7 @@ #include <sys/param.h> #include <sys/queue.h> #include <sys/stat.h> -#include <err.h> + #include <errno.h> #include <fnmatch.h> #include <fts.h> @@ -67,8 +67,8 @@ struct ignentry { static bool check_threshold(FTSENT *); static void ignoreadd(const char *); static void ignoreclean(void); -static int ignorep(FTSENT *); -static int linkchk(FTSENT *); +static bool ignorep(FTSENT *); +static bool linkchk(FTSENT *); static void print_file_size(FTSENT *); static void prthumanval(const char *, int64_t); static void record_file_size(FTSENT *); @@ -91,6 +91,7 @@ main(int argc, char *argv[]) { FTS *fts; FTSENT *p; + int64_t num; off_t savednumber; int ftsoptions; int depth; @@ -189,11 +190,12 @@ main(int argc, char *argv[]) case 'r': /* Compatibility. */ break; case 't': - if (expand_number(optarg, &threshold) != 0 || - threshold == 0) { + if (expand_number(optarg, &num) != 0 || num == 0) { xo_warnx("invalid threshold: %s", optarg); usage(); - } else if (threshold < 0) + } + threshold = num; + if (threshold < 0) threshold_sign = -1; break; case 'x': @@ -239,7 +241,7 @@ main(int argc, char *argv[]) if (sflag) depth = 0; - if (!*argv) { + if (argc == 0) { argv = save; argv[0] = dot; argv[1] = NULL; @@ -262,13 +264,12 @@ main(int argc, char *argv[]) (void)signal(SIGINFO, siginfo); if ((fts = fts_open(argv, ftsoptions, NULL)) == NULL) - err(1, "fts_open"); - + xo_err(1, "fts_open"); xo_set_version(DU_XO_VERSION); xo_open_container("disk-usage-information"); xo_open_list("paths"); - while (errno = 0, (p = fts_read(fts)) != NULL) { + for (errno = 0; (p = fts_read(fts)) != NULL; errno = 0) { switch (p->fts_info) { case FTS_D: /* Ignore. */ if (ignorep(p)) @@ -313,7 +314,7 @@ main(int argc, char *argv[]) } xo_close_list("paths"); - if (errno) + if (errno != 0) xo_err(1, "fts_read"); if (cflag) { @@ -334,7 +335,7 @@ main(int argc, char *argv[]) exit(rval); } -static int +static bool linkchk(FTSENT *p) { struct links_entry { @@ -362,7 +363,7 @@ linkchk(FTSENT *p) number_buckets = links_hash_initial_size; buckets = malloc(number_buckets * sizeof(buckets[0])); if (buckets == NULL) - errx(1, "No memory for hardlink detection"); + xo_errx(1, "No memory for hardlink detection"); for (i = 0; i < number_buckets; i++) buckets[i] = NULL; } @@ -433,12 +434,12 @@ linkchk(FTSENT *p) free_list = le; } } - return (1); + return (true); } } if (stop_allocating) - return (0); + return (false); /* Add this entry to the links cache. */ if (free_list != NULL) { @@ -451,7 +452,7 @@ linkchk(FTSENT *p) if (le == NULL) { stop_allocating = 1; xo_warnx("No more memory for tracking hard links"); - return (0); + return (false); } le->dev = st->st_dev; le->ino = st->st_ino; @@ -462,7 +463,7 @@ linkchk(FTSENT *p) if (buckets[hash] != NULL) buckets[hash]->previous = le; buckets[hash] = le; - return (0); + return (false); } static void @@ -500,10 +501,10 @@ ignoreadd(const char *mask) ign = calloc(1, sizeof(*ign)); if (ign == NULL) - errx(1, "cannot allocate memory"); + xo_errx(1, "cannot allocate memory"); ign->mask = strdup(mask); if (ign->mask == NULL) - errx(1, "cannot allocate memory"); + xo_errx(1, "cannot allocate memory"); SLIST_INSERT_HEAD(&ignores, ign, next); } @@ -520,17 +521,18 @@ ignoreclean(void) } } -static int +static bool ignorep(FTSENT *ent) { struct ignentry *ign; if (nodumpflag && (ent->fts_statp->st_flags & UF_NODUMP)) - return (1); - SLIST_FOREACH(ign, &ignores, next) + return (true); + SLIST_FOREACH(ign, &ignores, next) { if (fnmatch(ign->mask, ent->fts_name, 0) != FNM_NOMATCH) - return (1); - return (0); + return (true); + } + return (false); } static void diff --git a/usr.bin/du/tests/du_test.sh b/usr.bin/du/tests/du_test.sh index 27076be8dc3e..58ff1c3ecbd8 100755 --- a/usr.bin/du/tests/du_test.sh +++ b/usr.bin/du/tests/du_test.sh @@ -276,7 +276,7 @@ si_flag_body() atf_check -o inline:'1.5M\tA\n1.6M\tB\n' du -A --si A B } -atf_add_test_case t_flag +atf_test_case t_flag t_flag_head() { atf_set "descr" "Verify -t output" @@ -295,6 +295,23 @@ t_flag_body() sort du.out } +atf_test_case stdout +stdout_head() +{ + atf_set "descr" "Failure to write to stdout" +} +stdout_body() +{ + ( + trap "" PIPE + sleep 1 + du 2>stderr + echo $? >result + ) | true + atf_check -o inline:"1\n" cat result + atf_check -o match:"stdout" cat stderr +} + atf_init_test_cases() { atf_add_test_case A_flag @@ -314,4 +331,5 @@ atf_init_test_cases() atf_add_test_case s_flag atf_add_test_case si_flag atf_add_test_case t_flag + atf_add_test_case stdout } diff --git a/usr.bin/find/extern.h b/usr.bin/find/extern.h index 02c85d06a34c..250b5fb6689c 100644 --- a/usr.bin/find/extern.h +++ b/usr.bin/find/extern.h @@ -122,6 +122,8 @@ exec_f f_sparse; exec_f f_type; exec_f f_user; exec_f f_writable; +exec_f f_xattr; +exec_f f_xattrname; extern int ftsoptions, ignore_readdir_race, isdepth, isoutput; extern int issort, isxargs; diff --git a/usr.bin/find/find.1 b/usr.bin/find/find.1 index 98521a98762d..afe10a36607d 100644 --- a/usr.bin/find/find.1 +++ b/usr.bin/find/find.1 @@ -28,7 +28,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd July 26, 2025 +.Dd February 14, 2026 .Dt FIND 1 .Os .Sh NAME @@ -976,6 +976,23 @@ This test makes use of the .Xr access 2 system call, and so can be fooled by NFS servers which do UID mapping (or root-squashing). This is a GNU find extension. +.It Ic -xattr +Matches files which have extended attributes set in any supported namespace. +.It Ic -xattrname Ar xattr +Matches files which have the specified +.Ar xattr +extended attribute set. +All supported namespaces are searched by default, but +.Ar xattr +may be prefixed with +.Dq user: +or +.Dq system: +to filter by namespace. +.Pp +Note that named attributes are not supported, only extended attributes as set +by, e.g., +.Xr setextattr 8 . .El .Sh OPERATORS The primaries may be combined using the following operators. @@ -1245,6 +1262,7 @@ section below for details. .Xr whereis 1 , .Xr which 1 , .Xr xargs 1 , +.Xr extattr 2 , .Xr stat 2 , .Xr acl 3 , .Xr fts 3 , @@ -1253,7 +1271,8 @@ section below for details. .Xr strmode 3 , .Xr ascii 7 , .Xr re_format 7 , -.Xr symlink 7 +.Xr symlink 7 , +.Xr setextattr 8 .Sh STANDARDS The .Nm diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c index b260a71ef4a9..c62ac39a9e82 100644 --- a/usr.bin/find/function.c +++ b/usr.bin/find/function.c @@ -37,6 +37,7 @@ #include <sys/stat.h> #include <sys/types.h> #include <sys/acl.h> +#include <sys/extattr.h> #include <sys/wait.h> #include <sys/mount.h> @@ -49,6 +50,7 @@ #include <limits.h> #include <pwd.h> #include <regex.h> +#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -57,6 +59,8 @@ #include "find.h" +static const char * const xattr_ns[] = EXTATTR_NAMESPACE_NAMES; + static PLAN *palloc(OPTION *); static long long find_parsenum(PLAN *, const char *, char *, char *); static long long find_parsetime(PLAN *, const char *, char *); @@ -1753,6 +1757,96 @@ c_user(OPTION *option, char ***argvp) } /* + * -xattr functions -- + * + * True if the entry has any extended attribute in any namespace. + */ +int +f_xattr(PLAN *plan __unused, FTSENT *entry) +{ + ssize_t asz; + bool deref_link; + + deref_link = (ftsoptions & FTS_LOGICAL) != 0; + if (entry->fts_level == 0 && (ftsoptions & FTS_COMFOLLOW) != 0) + deref_link = true; + + for (size_t ns = 0; ns < nitems(xattr_ns); ns++) { + if (ns == EXTATTR_NAMESPACE_EMPTY) + continue; + + if (deref_link) + asz = extattr_list_file(entry->fts_accpath, ns, NULL, 0); + else + asz = extattr_list_link(entry->fts_accpath, ns, NULL, 0); + if (asz > 0) + return 1; + } + + return 0; +} + +static bool +find_has_xattr(const char *path, int ns, const char *aname, bool deref_link) +{ + size_t asz; + + if (deref_link) + asz = extattr_get_file(path, ns, aname, NULL, 0); + else + asz = extattr_get_link(path, ns, aname, NULL, 0); + + return asz != (size_t)-1; +} + +/* + * -xattrname xattr functions -- + * + * True if the entry has the given extended attribute xattr. The xattr + * may be prefixed with "user:" or "system:" to scope the search + * explicitly, otherwise we assume the user namespace is requested. + */ +int +f_xattrname(PLAN *plan, FTSENT *entry) +{ + const char *aname; + bool deref_link; + + deref_link = (ftsoptions & FTS_LOGICAL) != 0; + if (entry->fts_level == 0 && (ftsoptions & FTS_COMFOLLOW) != 0) + deref_link = true; + + aname = plan->c_data; + for (size_t ns = 0; ns < nitems(xattr_ns); ns++) { + const char *name; + size_t namelen; + + if (ns == EXTATTR_NAMESPACE_EMPTY) + continue; + + name = xattr_ns[ns]; + namelen = strlen(xattr_ns[ns]); + if (strncmp(aname, name, namelen) == 0 && + aname[namelen] == ':') { + aname += namelen + 1; + return find_has_xattr(entry->fts_accpath, ns, aname, + deref_link); + } + } + + for (size_t ns = 0; ns < nitems(xattr_ns); ns++) { + if (ns == EXTATTR_NAMESPACE_EMPTY) + continue; + + if (find_has_xattr(entry->fts_accpath, ns, aname, + deref_link)) + return 1; + } + + return 0; +} + +/* * -xdev functions -- * * Always true, causes find not to descend past directories that have a diff --git a/usr.bin/find/option.c b/usr.bin/find/option.c index fa09231a3152..fe3d9b00f90f 100644 --- a/usr.bin/find/option.c +++ b/usr.bin/find/option.c @@ -162,6 +162,8 @@ static OPTION const options[] = { { "-user", c_user, f_user, 0 }, { "-wholename", c_name, f_path, 0 }, { "-writable", c_simple, f_writable, 0 }, + { "-xattr", c_simple, f_xattr, 0 }, + { "-xattrname", c_name, f_xattrname, 0 }, { "-xdev", c_xdev, f_always_true, 0 }, // -xtype }; diff --git a/usr.bin/find/tests/find_test.sh b/usr.bin/find/tests/find_test.sh index 99d2f6af4d45..deb6a66a8dfb 100755 --- a/usr.bin/find/tests/find_test.sh +++ b/usr.bin/find/tests/find_test.sh @@ -174,9 +174,89 @@ find_printf_body() find -s dir -printf '%Te\n' } +atf_test_case find_xattr +find_xattr_head() +{ + atf_set "descr" "Test the -xattr primary" +} +find_xattr_body() +{ + mkdir dir + ln -s dir dirlink + + # No xattrs here + atf_check find dir -xattr + atf_check find dirlink -xattr + + # Set one on the directory and be sure that we also dereference symlinks + # as appropriate with -H/-L. + if ! setextattr user find_test.attr val dir; then + atf_skip "Failed to set xattr (not supported on this fs?)" + fi + + atf_check -o match:"dir$" find dir -xattr + atf_check -o match:"dirlink$" find -H dirlink -xattr + atf_check -o match:"dirlink$" find -L dirlink -xattr + + atf_check -o match:"dir$" -o match:"dirlink" find -sL . -xattr + atf_check -o match:"dir$" -o not-match:"dirlink$" find -sH . -xattr + atf_check -o match:"dir$" -o not-match:"dirlink$" find -s . -xattr +} + +atf_test_case find_xattrname +find_xattrname_head() +{ + atf_set "descr" "Test the -xattrname primary" + atf_set "require.user" "root" +} +find_xattrname_body() +{ + touch foo bar baz none + + ln -s foo link + if ! setextattr user find_test.special1 val foo; then + atf_skip "Failed to set xattr (not supported on this fs?)" + fi + + atf_check setextattr user find_test.special2 val bar + atf_check setextattr user find_test.special2 val baz + + # We want an unqualified 'find_test.special2' search to find all three + # of these, while 'user:' and 'system:' filter appropriately. + atf_check setextattr system find_test.special2 val foo + + atf_check find . -xattrname 'find_test.special3' + + # Be sure that we get symlink dereferencing right, so that one can use + # -H/-L/-P to get the right behavior. + atf_check -o match:foo -o not-match:"bar|baz|link|none" \ + find . -xattrname 'find_test.special1' + atf_check -o match:foo -o match:link \ + find -H foo link -xattrname 'find_test.special1' + atf_check -o match:foo -o match:link -o not-match:"bar|baz|none" \ + find -L . -xattrname 'find_test.special1' + + atf_check -o match:foo -o match:bar -o match:baz \ + -o not-match:"none|link" find . -xattrname 'find_test.special2' + atf_check -o not-match:"foo|none|link" -o match:bar -o match:baz \ + find . -xattrname 'user:find_test.special2' + atf_check -o match:foo -o not-match:"bar|baz|none|link" \ + find . -xattrname 'system:find_test.special2' + + # Now set an extattr on the link itself and be sure that find(1) can + # detect it. With -L, we shouldn't see anything with a special3 xattr + # as symlinks are dereferenced. + atf_check setextattr -h user find_test.special3 val link + atf_check -o match:link find . -xattrname "find_test.special3" + atf_check find -L . -xattrname "find_test.special3" + atf_check find -H link -xattrname "find_test.special3" +} + atf_init_test_cases() { atf_add_test_case find_newer_link atf_add_test_case find_samefile_link atf_add_test_case find_printf + atf_add_test_case find_xattr + atf_add_test_case find_xattrname } diff --git a/usr.bin/fortune/datfiles/freebsd-tips b/usr.bin/fortune/datfiles/freebsd-tips index 379f772fea88..47fd3c755626 100644 --- a/usr.bin/fortune/datfiles/freebsd-tips +++ b/usr.bin/fortune/datfiles/freebsd-tips @@ -180,7 +180,7 @@ directory sizes. nc(1) (or netcat) is useful not only for redirecting input/output to TCP or UDP connections, but also for proxying them with inetd(8). % -sh (the default Bourne shell in FreeBSD) supports command-line editing. Just +sh (the default POSIX shell in FreeBSD) supports command-line editing. Just ``set -o emacs'' or ``set -o vi'' to enable it. Use "<TAB>" key to complete paths. % @@ -415,7 +415,7 @@ if you leave the shell idle for more than 30 minutes. % You can use aliases to decrease the amount of typing you need to do to get commands you commonly use. Examples of fairly popular aliases include (in -Bourne shell style, as in /bin/sh, bash, ksh, and zsh): +POSIX shell style, as in /bin/sh, bash, ksh, and zsh): alias lf="ls -FA" alias ll="ls -lA" diff --git a/usr.bin/gzip/Makefile b/usr.bin/gzip/Makefile index 33fbdb85d78c..fae01959596c 100644 --- a/usr.bin/gzip/Makefile +++ b/usr.bin/gzip/Makefile @@ -5,13 +5,7 @@ PROG= gzip MAN= gzip.1 gzexe.1 zdiff.1 zforce.1 zmore.1 znew.1 -LIBADD= z lzma zstd - -.if ${MK_BZIP2_SUPPORT} != "no" -LIBADD+= bz2 -.else -CFLAGS+= -DNO_BZIP2_SUPPORT -.endif +LIBADD= bz2 lzma z zstd CFLAGS+= -I${SRCTOP}/sys/contrib/zstd/lib diff --git a/usr.bin/lockf/lockf.1 b/usr.bin/lockf/lockf.1 index 40b4497bc80c..406ccd4caa39 100644 --- a/usr.bin/lockf/lockf.1 +++ b/usr.bin/lockf/lockf.1 @@ -1,4 +1,6 @@ .\" +.\" SPDX-License-Identifier: BSD-2-Clause +.\" .\" Copyright (C) 1998 John D. Polstra. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -22,7 +24,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd June 24, 2025 +.Dd February 26, 2026 .Dt LOCKF 1 .Os .Sh NAME @@ -104,15 +106,10 @@ that if the option is not used, then no guarantees around lock ordering can be made. .Pp The following options are supported: -.Bl -tag -width ".Fl t Ar seconds" +.Bl -tag -width "-t seconds" .It Fl k Causes the lock file to be kept (not removed) after the command completes. -.It Fl s -Causes -.Nm -to operate silently. -Failure to acquire the lock is indicated only in the exit status. .It Fl n Causes .Nm @@ -136,6 +133,11 @@ This option will cause to open .Ar file for writing rather than reading. +.It Fl s +Causes +.Nm +to operate silently. +Failure to acquire the lock is indicated only in the exit status. .It Fl T Upon receipt of a .Dv SIGTERM , @@ -191,32 +193,32 @@ successfully acquires the lock, it returns the exit status produced by Otherwise, it returns one of the exit codes defined in .Xr sysexits 3 , as follows: -.Bl -tag -width ".Dv EX_CANTCREAT" -.It Dv EX_TEMPFAIL -The specified lock file was already locked by another process. -.It Dv EX_CANTCREAT -The +.Bl -tag -width "EX_UNAVAILABLE (69)" +.It Er EX_OSERR Pq 61 +A system call, e.g., +.Xr fork 2 , +failed unexpectedly. +.It Er EX_USAGE Pq 64 +There was an error on the .Nm -utility -was unable to create the lock file, e.g., because of insufficient access -privileges. -.It Dv EX_UNAVAILABLE +command line. +.It Er EX_UNAVAILABLE Pq 69 The .Fl n option is specified and the specified lock file does not exist. -.It Dv EX_USAGE -There was an error on the -.Nm -command line. -.It Dv EX_OSERR -A system call (e.g., -.Xr fork 2 ) -failed unexpectedly. -.It Dv EX_SOFTWARE +.It Er EX_SOFTWARE Pq 70 The .Ar command did not exit normally, but may have been signaled or stopped. +.It Er EX_CANTCREAT Pq 73 +The +.Nm +utility +was unable to create the lock file, e.g., because of insufficient access +privileges. +.It Er EX_TEMPFAIL Pq 75 +The specified lock file was already locked by another process. .El .Sh EXAMPLES The first job takes a lock and sleeps for 5 seconds in the background. @@ -237,9 +239,10 @@ $ lockf mylock sleep 1 & lockf -t 5 mylock echo "Success" Success [1]+ Done lockf mylock sleep 1 .Ed +.Pp Lock a file and run a script, return immediately if the lock is not -available. Do not delete the file afterward so lock order is -guaranteed. +available. +Do not delete the file afterward so lock order is guaranteed. .Pp .Dl $ lockf -t 0 -k /tmp/my.lock myscript .Pp diff --git a/usr.bin/m4/eval.c b/usr.bin/m4/eval.c index 0963a61a2914..4f088e0415e0 100644 --- a/usr.bin/m4/eval.c +++ b/usr.bin/m4/eval.c @@ -60,17 +60,17 @@ static void dodefn(const char *); static void dopushdef(const char *, const char *); -static void dodump(const char *[], int); +static void dodumpdef(const char *[], int); static void dotrace(const char *[], int, int); static void doifelse(const char *[], int); -static int doincl(const char *); +static int doinclude(const char *); static int dopaste(const char *); -static void dochq(const char *[], int); -static void dochc(const char *[], int); +static void dochangequote(const char *[], int); +static void dochangecom(const char *[], int); static void dom4wrap(const char *); -static void dodiv(int); -static void doundiv(const char *[], int); -static void dosub(const char *[], int); +static void dodivert(int); +static void doundivert(const char *[], int); +static void dosubstr(const char *[], int); static void map(char *, const char *, const char *, const char *); static const char *handledash(char *, char *, const char *); static void expand_builtin(const char *[], int, int); @@ -108,7 +108,7 @@ eval(const char *argv[], int argc, int td, int is_traced) m4errx(1, "expanding recursive definition for %s.", argv[1]); if (is_traced) mark = trace(argv, argc, infile+ilevel); - if (td == MACRTYPE) + if (td == MACROTYPE) expand_macro(argv, argc); else expand_builtin(argv, argc, td); @@ -149,18 +149,18 @@ expand_builtin(const char *argv[], int argc, int td) switch (td & TYPEMASK) { - case DEFITYPE: + case DEFINETYPE: if (argc > 2) dodefine(argv[2], (argc > 3) ? argv[3] : null); break; - case PUSDTYPE: + case PUSHDEFTYPE: if (argc > 2) dopushdef(argv[2], (argc > 3) ? argv[3] : null); break; - case DUMPTYPE: - dodump(argv, argc); + case DUMPDEFTYPE: + dodumpdef(argv, argc); break; case TRACEONTYPE: @@ -171,10 +171,9 @@ expand_builtin(const char *argv[], int argc, int td) dotrace(argv, argc, 0); break; - case EXPRTYPE: + case EVALTYPE: /* - * doexpr - evaluate arithmetic - * expression + * doeval - evaluate arithmetic expression */ { int base = 10; @@ -184,14 +183,14 @@ expand_builtin(const char *argv[], int argc, int td) if (argc > 3 && *argv[3] != '\0') { base = strtonum(argv[3], 2, 36, &errstr); if (errstr) { - m4errx(1, "expr: base is %s: %s.", + m4errx(1, "eval: base is %s: %s.", errstr, argv[3]); } } if (argc > 4) { mindigits = strtonum(argv[4], 0, INT_MAX, &errstr); if (errstr) { - m4errx(1, "expr: mindigits is %s: %s.", + m4errx(1, "eval: mindigits is %s: %s.", errstr, argv[4]); } } @@ -200,15 +199,14 @@ expand_builtin(const char *argv[], int argc, int td) break; } - case IFELTYPE: + case IFELSETYPE: doifelse(argv, argc); break; - case IFDFTYPE: + case IFDEFTYPE: /* - * doifdef - select one of two - * alternatives based on the existence of - * another definition + * doifdef - select one of two alternatives based + * on the existence of another definition */ if (argc > 3) { if (lookup_macro_definition(argv[2]) != NULL) @@ -218,18 +216,16 @@ expand_builtin(const char *argv[], int argc, int td) } break; - case LENGTYPE: + case LENTYPE: /* - * dolen - find the length of the - * argument + * dolen - find the length of the argument */ pbnum((argc > 2) ? strlen(argv[2]) : 0); break; case INCRTYPE: /* - * doincr - increment the value of the - * argument + * doincr - increment the value of the argument */ if (argc > 2) { n = strtonum(argv[2], INT_MIN, INT_MAX-1, &errstr); @@ -242,8 +238,7 @@ expand_builtin(const char *argv[], int argc, int td) case DECRTYPE: /* - * dodecr - decrement the value of the - * argument + * dodecr - decrement the value of the argument */ if (argc > 2) { n = strtonum(argv[2], INT_MIN+1, INT_MAX, &errstr); @@ -254,9 +249,9 @@ expand_builtin(const char *argv[], int argc, int td) } break; - case SYSCTYPE: + case SYSCMDTYPE: /* - * dosys - execute system command + * dosyscmd - execute system command */ if (argc > 2) { fflush(stdout); @@ -264,10 +259,9 @@ expand_builtin(const char *argv[], int argc, int td) } break; - case SYSVTYPE: + case SYSVALTYPE: /* - * dosysval - return value of the last - * system call. + * dosysval - return value of the last system call. * */ pbnum(sysval); @@ -277,9 +271,9 @@ expand_builtin(const char *argv[], int argc, int td) if (argc > 2) doesyscmd(argv[2]); break; - case INCLTYPE: + case INCLUDETYPE: if (argc > 2) { - if (!doincl(argv[2])) { + if (!doinclude(argv[2])) { if (mimic_gnu) { warn("%s at line %lu: include(%s)", CURRENT_NAME, CURRENT_LINE, argv[2]); @@ -295,19 +289,20 @@ expand_builtin(const char *argv[], int argc, int td) } break; - case SINCTYPE: + case SINCLUDETYPE: + /* like include, but don't error out if file not found */ if (argc > 2) - (void) doincl(argv[2]); + (void) doinclude(argv[2]); break; #ifdef EXTENDED - case PASTTYPE: + case PASTETYPE: if (argc > 2) if (!dopaste(argv[2])) - err(1, "%s at line %lu: paste(%s)", + err(1, "%s at line %lu: paste(%s)", CURRENT_NAME, CURRENT_LINE, argv[2]); break; - case SPASTYPE: + case SPASTETYPE: if (argc > 2) (void) dopaste(argv[2]); break; @@ -315,28 +310,27 @@ expand_builtin(const char *argv[], int argc, int td) doformat(argv, argc); break; #endif - case CHNQTYPE: - dochq(argv, ac); + case CHANGEQUOTETYPE: + dochangequote(argv, ac); break; - case CHNCTYPE: - dochc(argv, argc); + case CHANGECOMTYPE: + dochangecom(argv, argc); break; - case SUBSTYPE: + case SUBSTRTYPE: /* - * dosub - select substring + * dosubstr - select substring * */ if (argc > 3) - dosub(argv, argc); + dosubstr(argv, argc); break; - case SHIFTYPE: + case SHIFTTYPE: /* - * doshift - push back all arguments - * except the first one (i.e. skip - * argv[2]) + * doshift - push back all arguments except the first one + * (i.e. skip argv[2]) */ if (argc > 3) { for (n = argc - 1; n > 3; n--) { @@ -351,57 +345,55 @@ expand_builtin(const char *argv[], int argc, int td) } break; - case DIVRTYPE: + case DIVERTTYPE: if (argc > 2) { n = strtonum(argv[2], INT_MIN, INT_MAX, &errstr); if (errstr) m4errx(1, "divert: argument is %s: %s.", errstr, argv[2]); if (n != 0) { - dodiv(n); - break; + dodivert(n); + break; } } active = stdout; oindex = 0; break; - case UNDVTYPE: - doundiv(argv, argc); + case UNDIVERTTYPE: + doundivert(argv, argc); break; - case DIVNTYPE: + case DIVNUMTYPE: /* - * dodivnum - return the number of - * current output diversion + * dodivnum - return the number of current output diversion */ pbnum(oindex); break; - case UNDFTYPE: + case UNDEFINETYPE: /* - * doundefine - undefine a previously - * defined macro(s) or m4 keyword(s). + * doundefine - undefine a previously defined macro(s) or m4 + * keyword(s). */ if (argc > 2) for (n = 2; n < argc; n++) macro_undefine(argv[n]); break; - case POPDTYPE: + case POPDEFTYPE: /* - * dopopdef - remove the topmost - * definitions of macro(s) or m4 - * keyword(s). + * dopopdef - remove the topmost definitions of macro(s) + * or m4 keyword(s). */ if (argc > 2) for (n = 2; n < argc; n++) macro_popdef(argv[n]); break; - case MKTMTYPE: + case MKSTEMPTYPE: /* - * dotemp - create a temporary file + * domkstemp - safely create a temporary file */ if (argc > 2) { int fd; @@ -420,11 +412,10 @@ expand_builtin(const char *argv[], int argc, int td) } break; - case TRNLTYPE: + case TRANSLITTYPE: /* - * dotranslit - replace all characters in - * the source string that appears in the - * "from" string with the corresponding + * dotranslit - replace all characters in the source string + * that appear in the "from" string with the corresponding * characters in the "to" string. */ if (argc > 3) { @@ -441,19 +432,17 @@ expand_builtin(const char *argv[], int argc, int td) pbstr(argv[2]); break; - case INDXTYPE: + case INDEXTYPE: /* - * doindex - find the index of the second - * argument string in the first argument - * string. -1 if not present. + * doindex - find the index of the second argument string + * in the first argument string. -1 if not present. */ - pbnum((argc > 3) ? indx(argv[2], argv[3]) : -1); + pbnum((argc > 3) ? doindex(argv[2], argv[3]) : -1); break; - case ERRPTYPE: + case ERRPRINTTYPE: /* - * doerrp - print the arguments to stderr - * file + * doerrprint - print the arguments to stderr */ if (argc > 2) { for (n = 2; n < argc; n++) @@ -462,16 +451,15 @@ expand_builtin(const char *argv[], int argc, int td) } break; - case DNLNTYPE: + case DNLTYPE: /* - * dodnl - eat-up-to and including - * newline + * dodnl - eat-up-to and including newline */ while ((c = gpbc()) != '\n' && c != EOF) ; break; - case M4WRTYPE: + case M4WRAPTYPE: /* * dom4wrap - set up for * wrap-up/wind-down activity @@ -480,9 +468,9 @@ expand_builtin(const char *argv[], int argc, int td) dom4wrap(argv[2]); break; - case EXITTYPE: + case M4EXITTYPE: /* - * doexit - immediate exit from m4. + * dom4exit - immediate exit from m4. */ killdiv(); exit((argc > 2) ? atoi(argv[2]) : 0); @@ -504,7 +492,7 @@ expand_builtin(const char *argv[], int argc, int td) dobuiltin(argv, argc); break; - case PATSTYPE: + case PATSUBSTTYPE: if (argc > 2) dopatsubst(argv, argc); break; @@ -625,7 +613,7 @@ dodefn(const char *name) struct macro_definition *p; if ((p = lookup_macro_definition(name)) != NULL) { - if ((p->type & TYPEMASK) == MACRTYPE) { + if ((p->type & TYPEMASK) == MACROTYPE) { pbstr(rquote); pbstr(p->defn); pbstr(lquote); @@ -661,7 +649,7 @@ dump_one_def(const char *name, struct macro_definition *p) if (!traceout) traceout = stderr; if (mimic_gnu) { - if ((p->type & TYPEMASK) == MACRTYPE) + if ((p->type & TYPEMASK) == MACROTYPE) fprintf(traceout, "%s:\t%s\n", name, p->defn); else { fprintf(traceout, "%s:\t<%s>\n", name, p->defn); @@ -676,7 +664,7 @@ dump_one_def(const char *name, struct macro_definition *p) * hash table is dumped. */ static void -dodump(const char *argv[], int argc) +dodumpdef(const char *argv[], int argc) { int n; struct macro_definition *p; @@ -728,7 +716,7 @@ doifelse(const char *argv[], int argc) * doinclude - include a given file. */ static int -doincl(const char *ifile) +doinclude(const char *ifile) { if (ilevel + 1 == MAXINP) m4errx(1, "too many include files."); @@ -765,10 +753,10 @@ dopaste(const char *pfile) #endif /* - * dochq - change quote characters + * dochangequote - change quote characters */ static void -dochq(const char *argv[], int ac) +dochangequote(const char *argv[], int ac) { if (ac == 2) { lquote[0] = LQUOTE; lquote[1] = EOS; @@ -784,10 +772,10 @@ dochq(const char *argv[], int ac) } /* - * dochc - change comment characters + * dochangecom - change comment characters */ static void -dochc(const char *argv[], int argc) +dochangecom(const char *argv[], int argc) { /* XXX Note that there is no difference between no argument and a single * empty argument. @@ -826,7 +814,7 @@ dom4wrap(const char *text) * dodivert - divert the output to a temporary file */ static void -dodiv(int n) +dodivert(int n) { int fd; @@ -856,7 +844,7 @@ dodiv(int n) * other outputs, in numerical order. */ static void -doundiv(const char *argv[], int argc) +doundivert(const char *argv[], int argc) { int ind; int n; @@ -881,10 +869,10 @@ doundiv(const char *argv[], int argc) } /* - * dosub - select substring + * dosubstr - select substring */ static void -dosub(const char *argv[], int argc) +dosubstr(const char *argv[], int argc) { const char *ap, *fc, *k; int nc; @@ -912,11 +900,11 @@ dosub(const char *argv[], int argc) * map every character of s1 that is specified in from * into s3 and replace in s. (source s1 remains untouched) * - * This is derived from the a standard implementation of map(s,from,to) - * function of ICON language. Within mapvec, we replace every character - * of "from" with the corresponding character in "to". - * If "to" is shorter than "from", than the corresponding entries are null, - * which means that those characters disappear altogether. + * This is derived from the a standard implementation of map(s,from,to) + * function of ICON language. Within mapvec, we replace every character + * of "from" with the corresponding character in "to". + * If "to" is shorter than "from", than the corresponding entries are null, + * which means that those characters disappear altogether. */ static void map(char *dest, const char *src, const char *from, const char *to) @@ -1006,7 +994,7 @@ handledash(char *buffer, char *end, const char *src) if (src[1] == '-' && src[2]) { unsigned char i; if ((unsigned char)src[0] <= (unsigned char)src[2]) { - for (i = (unsigned char)src[0]; + for (i = (unsigned char)src[0]; i <= (unsigned char)src[2]; i++) { *p++ = i; if (p == end) { @@ -1015,7 +1003,7 @@ handledash(char *buffer, char *end, const char *src) } } } else { - for (i = (unsigned char)src[0]; + for (i = (unsigned char)src[0]; i >= (unsigned char)src[2]; i--) { *p++ = i; if (p == end) { diff --git a/usr.bin/m4/expr.c b/usr.bin/m4/expr.c index 7910403d74f0..859be1557d83 100644 --- a/usr.bin/m4/expr.c +++ b/usr.bin/m4/expr.c @@ -32,7 +32,7 @@ int yyerror(const char *msg) { fprintf(stderr, "m4: %s in expr %s\n", msg, copy_toeval); - return(0); + return 0; } int diff --git a/usr.bin/m4/extern.h b/usr.bin/m4/extern.h index 94eb66314bf4..a411cb6d5891 100644 --- a/usr.bin/m4/extern.h +++ b/usr.bin/m4/extern.h @@ -95,7 +95,7 @@ extern int exit_code; extern void chrsave(int); extern char *compute_prevep(void); extern void getdiv(int); -extern ptrdiff_t indx(const char *, const char *); +extern ptrdiff_t doindex(const char *, const char *); extern void initspaces(void); extern void killdiv(void); extern void onintr(int); diff --git a/usr.bin/m4/look.c b/usr.bin/m4/look.c index d7ad94b18bd0..c1fccd7dd8e5 100644 --- a/usr.bin/m4/look.c +++ b/usr.bin/m4/look.c @@ -127,7 +127,7 @@ setup_definition(struct macro_definition *d, const char *defn, const char *name) d->defn = __DECONST(char *, null); else d->defn = xstrdup(defn); - d->type = MACRTYPE; + d->type = MACROTYPE; } if (STREQ(name, defn)) d->type |= RECDEF; @@ -137,8 +137,8 @@ static ndptr create_entry(const char *name) { const char *end = NULL; - unsigned int i; ndptr n; + unsigned int i; i = ohash_qlookupi(¯os, name, &end); n = ohash_find(¯os, i); @@ -146,7 +146,7 @@ create_entry(const char *name) n = ohash_create_entry(¯o_info, name, &end); ohash_insert(¯os, i, n); n->trace_flags = FLAG_NO_TRACE; - n->builtin_type = MACRTYPE; + n->builtin_type = MACROTYPE; n->d = NULL; } return n; @@ -156,6 +156,7 @@ void macro_define(const char *name, const char *defn) { ndptr n = create_entry(name); + if (n->d != NULL) { if (n->d->defn != null) free_definition(n->d->defn); @@ -183,6 +184,7 @@ void macro_undefine(const char *name) { ndptr n = lookup(name); + if (n != NULL) { struct macro_definition *r, *r2; @@ -271,7 +273,7 @@ macro_getbuiltin(const char *name) ndptr p; p = lookup(name); - if (p == NULL || p->builtin_type == MACRTYPE) + if (p == NULL || p->builtin_type == MACROTYPE) return NULL; else return p; @@ -295,21 +297,21 @@ keep(char *ptr) kept_capacity *= 2; else kept_capacity = 50; - kept = xreallocarray(kept, kept_capacity, - sizeof(char *), "Out of memory while saving %d strings\n", + kept = xreallocarray(kept, kept_capacity, + sizeof(char *), "Out of memory while saving %d strings\n", kept_capacity); } kept[kept_size++] = ptr; } static int -string_in_use(const char *ptr) +string_in_use(const char *ptr) { int i; - for (i = 0; i <= sp; i++) { + + for (i = 0; i <= sp; i++) if (sstack[i] == STORAGE_MACRO && mstack[i].sstr == ptr) return 1; - } return 0; } @@ -324,7 +326,7 @@ free_definition(char *ptr) if (!string_in_use(kept[i])) { kept_size--; free(kept[i]); - if (i != kept_size) + if (i != kept_size) kept[i] = kept[kept_size]; i--; } @@ -336,4 +338,3 @@ free_definition(char *ptr) else free(ptr); } - diff --git a/usr.bin/m4/main.c b/usr.bin/m4/main.c index d68069cb10a8..5daae7fd22c2 100644 --- a/usr.bin/m4/main.c +++ b/usr.bin/m4/main.c @@ -86,7 +86,7 @@ int maxout; FILE *active; /* active output file pointer */ int ilevel = 0; /* input file stack pointer */ int oindex = 0; /* diversion index.. */ -const char *null = ""; /* as it says.. just a null.. */ +const char *null = ""; /* as it says.. just a null.. */ char **m4wraps = NULL; /* m4wraps array. */ int maxwraps = 0; /* size of m4wraps array */ int wrapindex = 0; /* current offset in m4wraps */ @@ -105,53 +105,54 @@ struct keyblk { }; static struct keyblk keywrds[] = { /* m4 keywords to be installed */ - { "include", INCLTYPE }, - { "sinclude", SINCTYPE }, - { "define", DEFITYPE }, + { "include", INCLUDETYPE }, + { "sinclude", SINCLUDETYPE }, + { "define", DEFINETYPE }, { "defn", DEFNTYPE }, - { "divert", DIVRTYPE | NOARGS }, - { "expr", EXPRTYPE }, - { "eval", EXPRTYPE }, - { "substr", SUBSTYPE }, - { "ifelse", IFELTYPE }, - { "ifdef", IFDFTYPE }, - { "len", LENGTYPE }, + { "divert", DIVERTTYPE | NOARGS }, + { "eval", EVALTYPE }, + { "expr", EVALTYPE }, + { "substr", SUBSTRTYPE }, + { "ifelse", IFELSETYPE }, + { "ifdef", IFDEFTYPE }, + { "len", LENTYPE }, { "incr", INCRTYPE }, { "decr", DECRTYPE }, - { "dnl", DNLNTYPE | NOARGS }, - { "changequote", CHNQTYPE | NOARGS }, - { "changecom", CHNCTYPE | NOARGS }, - { "index", INDXTYPE }, + { "dnl", DNLTYPE | NOARGS }, + { "changequote", CHANGEQUOTETYPE | NOARGS }, + { "changecom", CHANGECOMTYPE | NOARGS }, + { "index", INDEXTYPE }, #ifdef EXTENDED - { "paste", PASTTYPE }, - { "spaste", SPASTYPE }, + { "paste", PASTETYPE }, + { "spaste", SPASTETYPE }, /* Newer extensions, needed to handle gnu-m4 scripts */ { "indir", INDIRTYPE}, { "builtin", BUILTINTYPE}, - { "patsubst", PATSTYPE}, + { "patsubst", PATSUBSTTYPE}, { "regexp", REGEXPTYPE}, { "esyscmd", ESYSCMDTYPE}, { "__file__", FILENAMETYPE | NOARGS}, { "__line__", LINETYPE | NOARGS}, #endif - { "popdef", POPDTYPE }, - { "pushdef", PUSDTYPE }, - { "dumpdef", DUMPTYPE | NOARGS }, - { "shift", SHIFTYPE | NOARGS }, - { "translit", TRNLTYPE }, - { "undefine", UNDFTYPE }, - { "undivert", UNDVTYPE | NOARGS }, - { "divnum", DIVNTYPE | NOARGS }, - { "maketemp", MKTMTYPE }, - { "mkstemp", MKTMTYPE }, - { "errprint", ERRPTYPE | NOARGS }, - { "m4wrap", M4WRTYPE | NOARGS }, - { "m4exit", EXITTYPE | NOARGS }, - { "syscmd", SYSCTYPE }, - { "sysval", SYSVTYPE | NOARGS }, + { "popdef", POPDEFTYPE }, + { "pushdef", PUSHDEFTYPE }, + { "dumpdef", DUMPDEFTYPE | NOARGS }, + { "shift", SHIFTTYPE | NOARGS }, + { "translit", TRANSLITTYPE }, + { "undefine", UNDEFINETYPE }, + { "undivert", UNDIVERTTYPE | NOARGS }, + { "divnum", DIVNUMTYPE | NOARGS }, + { "maketemp", MKSTEMPTYPE }, + { "mkstemp", MKSTEMPTYPE }, + { "errprint", ERRPRINTTYPE | NOARGS }, + { "m4wrap", M4WRAPTYPE | NOARGS }, + { "m4exit", M4EXITTYPE | NOARGS }, + { "syscmd", SYSCMDTYPE }, + { "sysval", SYSVALTYPE | NOARGS }, { "traceon", TRACEONTYPE | NOARGS }, { "traceoff", TRACEOFFTYPE | NOARGS }, +/* Macro that expands to itself, signature of the current OS */ { "unix", SELFTYPE | NOARGS }, }; @@ -387,8 +388,7 @@ macro(void) CHRSAVE(l); } } - } - while (nlpar != 0); + } while (nlpar != 0); } else if (sp < 0 && LOOK_AHEAD(t, scommt)) { reallyoutputstr(scommt); diff --git a/usr.bin/m4/mdef.h b/usr.bin/m4/mdef.h index d4fa5b0e0c14..259d4d2baa55 100644 --- a/usr.bin/m4/mdef.h +++ b/usr.bin/m4/mdef.h @@ -41,50 +41,50 @@ # define UNUSED #endif -#define MACRTYPE 1 -#define DEFITYPE 2 -#define EXPRTYPE 3 -#define SUBSTYPE 4 -#define IFELTYPE 5 -#define LENGTYPE 6 -#define CHNQTYPE 7 -#define SYSCTYPE 8 -#define UNDFTYPE 9 -#define INCLTYPE 10 -#define SINCTYPE 11 -#define PASTTYPE 12 -#define SPASTYPE 13 -#define INCRTYPE 14 -#define IFDFTYPE 15 -#define PUSDTYPE 16 -#define POPDTYPE 17 -#define SHIFTYPE 18 -#define DECRTYPE 19 -#define DIVRTYPE 20 -#define UNDVTYPE 21 -#define DIVNTYPE 22 -#define MKTMTYPE 23 -#define ERRPTYPE 24 -#define M4WRTYPE 25 -#define TRNLTYPE 26 -#define DNLNTYPE 27 -#define DUMPTYPE 28 -#define CHNCTYPE 29 -#define INDXTYPE 30 -#define SYSVTYPE 31 -#define EXITTYPE 32 -#define DEFNTYPE 33 -#define SELFTYPE 34 -#define INDIRTYPE 35 -#define BUILTINTYPE 36 -#define PATSTYPE 37 -#define FILENAMETYPE 38 -#define LINETYPE 39 -#define REGEXPTYPE 40 -#define ESYSCMDTYPE 41 -#define TRACEONTYPE 42 -#define TRACEOFFTYPE 43 -#define FORMATTYPE 44 +#define MACROTYPE 1 +#define DEFINETYPE 2 +#define EVALTYPE 3 +#define SUBSTRTYPE 4 +#define IFELSETYPE 5 +#define LENTYPE 6 +#define CHANGEQUOTETYPE 7 +#define SYSCMDTYPE 8 +#define UNDEFINETYPE 9 +#define INCLUDETYPE 10 +#define SINCLUDETYPE 11 +#define PASTETYPE 12 +#define SPASTETYPE 13 +#define INCRTYPE 14 +#define IFDEFTYPE 15 +#define PUSHDEFTYPE 16 +#define POPDEFTYPE 17 +#define SHIFTTYPE 18 +#define DECRTYPE 19 +#define DIVERTTYPE 20 +#define UNDIVERTTYPE 21 +#define DIVNUMTYPE 22 +#define MKSTEMPTYPE 23 +#define ERRPRINTTYPE 24 +#define M4WRAPTYPE 25 +#define TRANSLITTYPE 26 +#define DNLTYPE 27 +#define DUMPDEFTYPE 28 +#define CHANGECOMTYPE 29 +#define INDEXTYPE 30 +#define SYSVALTYPE 31 +#define M4EXITTYPE 32 +#define DEFNTYPE 33 +#define SELFTYPE 34 +#define INDIRTYPE 35 +#define BUILTINTYPE 36 +#define PATSUBSTTYPE 37 +#define FILENAMETYPE 38 +#define LINETYPE 39 +#define REGEXPTYPE 40 +#define ESYSCMDTYPE 41 +#define TRACEONTYPE 42 +#define TRACEOFFTYPE 43 +#define FORMATTYPE 44 #define BUILTIN_MARKER "__builtin_" @@ -204,7 +204,7 @@ struct input_file { mstack[sp].sstr = macro_getdef(p)->defn;\ sstack[sp] = STORAGE_MACRO; \ } while (0) - + /* * . . diff --git a/usr.bin/m4/misc.c b/usr.bin/m4/misc.c index fd72292aeac0..24e91c572f4d 100644 --- a/usr.bin/m4/misc.c +++ b/usr.bin/m4/misc.c @@ -68,7 +68,7 @@ unsigned char *endpbb; /* end of push-back buffer */ * find the index of second str in the first str. */ ptrdiff_t -indx(const char *s1, const char *s2) +doindex(const char *s1, const char *s2) { char *t; @@ -135,8 +135,7 @@ pbnumbase(int n, int base, int d) do { pushback(digits[num % base]); printed++; - } - while ((num /= base) > 0); + } while ((num /= base) > 0); while (printed++ < d) pushback('0'); @@ -153,8 +152,7 @@ pbunsigned(unsigned long n) { do { pushback(n % 10 + '0'); - } - while ((n /= 10) > 0); + } while ((n /= 10) > 0); } void @@ -186,9 +184,9 @@ enlarge_strspace(void) memcpy(newstrspace, strspace, strsize/2); for (i = 0; i <= sp; i++) if (sstack[i] == STORAGE_STRSPACE) - mstack[i].sstr = (mstack[i].sstr - strspace) - + newstrspace; - ep = (ep-strspace) + newstrspace; + mstack[i].sstr = (mstack[i].sstr - strspace) + + newstrspace; + ep = (ep - strspace) + newstrspace; free(strspace); strspace = newstrspace; endest = strspace + strsize; diff --git a/usr.bin/mdo/mdo.1 b/usr.bin/mdo/mdo.1 index 1de694c69e40..c1a0295535df 100644 --- a/usr.bin/mdo/mdo.1 +++ b/usr.bin/mdo/mdo.1 @@ -9,7 +9,7 @@ .\" <olce@FreeBSD.org> at Kumacom SARL under sponsorship from the FreeBSD .\" Foundation. .\" -.Dd November 26, 2025 +.Dd March 22, 2026 .Dt MDO 1 .Os .Sh NAME @@ -232,7 +232,8 @@ mdo -k --euid root --svuid root id .Sh SEE ALSO .Xr su 1 , .Xr setcred 2 , -.Xr mac_do 4 +.Xr mac_do 4 , +.Xr security 7 .Sh HISTORY The .Nm diff --git a/usr.bin/mkimg/mkimg.c b/usr.bin/mkimg/mkimg.c index c625b49dc29a..4a288d66be81 100644 --- a/usr.bin/mkimg/mkimg.c +++ b/usr.bin/mkimg/mkimg.c @@ -446,6 +446,8 @@ mkimg(void) { FILE *fp; struct part *part; + struct stat sb; + char *p; lba_t block, blkoffset; uint64_t bytesize, byteoffset; char *size, *offset; @@ -468,12 +470,28 @@ mkimg(void) /* Look for an offset. Set size too if we can. */ switch (part->kind) { case PART_KIND_SIZE: - case PART_KIND_FILE: offset = part->contents; size = strsep(&offset, ":"); - if (part->kind == PART_KIND_SIZE && - expand_number(size, &bytesize) == -1) + if (expand_number(size, &bytesize) == -1) error = errno; + break; + case PART_KIND_FILE: + size = part->contents; + if (stat(part->contents, &sb) == 0) { + if (S_ISDIR(sb.st_mode)) { + errc(EX_IOERR, EISDIR, "partition %d", + part->index + 1); + } + offset = NULL; + } else { + p = strrchr(part->contents, ':'); + if (p != NULL) { + *p = '\0'; + offset = p + 1; + } else { + offset = NULL; + } + } if (offset != NULL) { if (*offset != '+') abs_offset = true; diff --git a/usr.bin/netstat/if.c b/usr.bin/netstat/if.c index 7ee03eb3689b..637aa4738d40 100644 --- a/usr.bin/netstat/if.c +++ b/usr.bin/netstat/if.c @@ -396,7 +396,7 @@ intpr(void (*pfunc)(char *), int af) u_int npkt_len = 8, nbyte_len = 10, nerr_len = 5; if (interval) - return sidewaysintpr(); + return (sidewaysintpr()); if (getifaddrs(&ifap) != 0) xo_err(EX_OSERR, "getifaddrs"); @@ -652,6 +652,21 @@ catchalarm(int signo __unused) signalled = true; } +static void +running_stats_banner(void) +{ + xo_emit("{T:/%17s} {T:/%14s} {T:/%16s}\n", "input", + interface != NULL ? interface : "(Total)", "output"); + xo_emit("{T:/%10s} {T:/%5s} {T:/%5s} {T:/%10s} {T:/%10s} {T:/%5s} " + "{T:/%10s} {T:/%5s}", + "packets", "errs", "idrops", "bytes", "packets", "errs", "bytes", + "colls"); + if (dflag) + xo_emit(" {T:/%5.5s}", "drops"); + xo_emit("\n"); + xo_flush(); +} + /* * Print a running summary of interface statistics. * Repeat display every interval seconds, showing statistics @@ -675,71 +690,82 @@ sidewaysintpr(void) interval_it.it_interval.tv_usec = 0; interval_it.it_value = interval_it.it_interval; setitimer(ITIMER_REAL, &interval_it, NULL); + xo_open_list("interface-statistics"); -banner: - xo_emit("{T:/%17s} {T:/%14s} {T:/%16s}\n", "input", - interface != NULL ? interface : "(Total)", "output"); - xo_emit("{T:/%10s} {T:/%5s} {T:/%5s} {T:/%10s} {T:/%10s} {T:/%5s} " - "{T:/%10s} {T:/%5s}", - "packets", "errs", "idrops", "bytes", "packets", "errs", "bytes", - "colls"); - if (dflag) - xo_emit(" {T:/%5.5s}", "drops"); - xo_emit("\n"); - xo_flush(); + /* + * We print the first banner right away, even if we'll have to wait for + * the specified interval to get the first statistics line. Next + * banners will be printed only when the next statistics line is + * available. + */ + running_stats_banner(); + /* Number of written statistics line since latest banner. */ line = 0; -loop: - if ((noutputs != 0) && (--noutputs == 0)) { - xo_close_list("interface-statistics"); - return; - } - oldmask = sigblock(sigmask(SIGALRM)); - while (!signalled) - sigpause(0); - signalled = false; - sigsetmask(oldmask); - line++; + for (;;) { + /* Wait for next interval. */ + oldmask = sigblock(sigmask(SIGALRM)); + while (!signalled) + sigpause(0); + signalled = false; + sigsetmask(oldmask); - fill_iftot(new); + fill_iftot(new); - xo_open_instance("stats"); - show_stat("lu", 10, "received-packets", - new->ift_ip - old->ift_ip, 1, 1); - show_stat("lu", 5, "received-errors", - new->ift_ie - old->ift_ie, 1, 1); - show_stat("lu", 5, "dropped-packets", - new->ift_id - old->ift_id, 1, 1); - show_stat("lu", 10, "received-bytes", - new->ift_ib - old->ift_ib, 1, 0); - show_stat("lu", 10, "sent-packets", - new->ift_op - old->ift_op, 1, 1); - show_stat("lu", 5, "send-errors", - new->ift_oe - old->ift_oe, 1, 1); - show_stat("lu", 10, "sent-bytes", - new->ift_ob - old->ift_ob, 1, 0); - show_stat("NRSlu", 5, "collisions", - new->ift_co - old->ift_co, 1, 1); - if (dflag) - show_stat("LSlu", 5, "dropped-packets", - new->ift_od - old->ift_od, 1, 1); - xo_close_instance("stats"); - xo_emit("\n"); - xo_flush(); + /* + * We want that, on a 24-line display, when the previous banner + * reaches exactly the top of the screen, a new banner is + * printed before the next statistics line. This ensures that + * at least one banner is visible on screen at all time + * (provided the screen has at least 24 lines). Since the + * banner takes 2 lines, and the last screen line is occupied by + * the cursor, it's after having written 21 statistics lines + * that we must output the banner. + */ + if (line == 21) { + running_stats_banner(); + line = 0; + } + ++line; - if (new == &ift[0]) { - new = &ift[1]; - old = &ift[0]; - } else { - new = &ift[0]; - old = &ift[1]; - } + xo_open_instance("stats"); + show_stat("lu", 10, "received-packets", + new->ift_ip - old->ift_ip, 1, 1); + show_stat("lu", 5, "received-errors", + new->ift_ie - old->ift_ie, 1, 1); + show_stat("lu", 5, "dropped-packets", + new->ift_id - old->ift_id, 1, 1); + show_stat("lu", 10, "received-bytes", + new->ift_ib - old->ift_ib, 1, 0); + show_stat("lu", 10, "sent-packets", + new->ift_op - old->ift_op, 1, 1); + show_stat("lu", 5, "send-errors", + new->ift_oe - old->ift_oe, 1, 1); + show_stat("lu", 10, "sent-bytes", + new->ift_ob - old->ift_ob, 1, 0); + show_stat("NRSlu", 5, "collisions", + new->ift_co - old->ift_co, 1, 1); + if (dflag) + show_stat("LSlu", 5, "dropped-packets", + new->ift_od - old->ift_od, 1, 1); + xo_close_instance("stats"); + xo_emit("\n"); + xo_flush(); - if (line == 21) - goto banner; - else - goto loop; + if ((noutputs != 0) && (--noutputs == 0)) { + xo_close_list("interface-statistics"); + return; + } + + if (new == &ift[0]) { + new = &ift[1]; + old = &ift[0]; + } else { + new = &ift[0]; + old = &ift[1]; + } + } /* NOTREACHED */ } diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index 79830049948a..0084426540f6 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -389,8 +389,6 @@ main(int argc, char *argv[]) break; case 'q': noutputs = atoi(optarg); - if (noutputs != 0) - noutputs++; break; case 'r': rflag = true; @@ -552,6 +550,8 @@ main(int argc, char *argv[]) if (gflag) { + if (fib != -1 && setfib(fib) < 0) + xo_errx(EX_DATAERR, "setfib: %s", strerror(errno)); xo_open_container("statistics"); xo_set_version(NETSTAT_XO_VERSION); if (sflag) { diff --git a/usr.bin/netstat/netstat.1 b/usr.bin/netstat/netstat.1 index 1931c38a1fad..5c7f2336c06b 100644 --- a/usr.bin/netstat/netstat.1 +++ b/usr.bin/netstat/netstat.1 @@ -25,7 +25,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd July 16, 2025 +.Dd April 7, 2026 .Dt NETSTAT 1 .Os .Sh NAME @@ -94,6 +94,7 @@ .Op Fl j Ar jail .Op Fl -libxo .Op Fl 46W +.Op Fl F Ar fibnum .Op Fl f Ar address_family .It Nm Fl gs .Op Fl j Ar jail @@ -355,23 +356,14 @@ See At intervals of .Ar wait seconds, display the information regarding packet traffic on all -configured network interfaces or a single -.Ar interface . +configured network interfaces, or a single +.Ar interface +if +.Fl I +is specified. .Pp -When -.Nm -is invoked with the -.Fl w -option and a -.Ar wait -interval argument, it displays a running count of statistics related to -network interfaces. An obsolescent version of this option used a numeric parameter with no option, and is currently supported for backward compatibility. -By default, this display summarizes information for all interfaces. -Information for a specific interface may be displayed with the -.Fl I Ar interface -option. .Bl -tag -width indent .It Fl I Ar interface Only show information regarding @@ -398,6 +390,7 @@ See Exit after .Ar howmany outputs. +A value of zero indicates no limit, and is the default. .It Fl j Ar jail Run inside a jail. See @@ -746,6 +739,7 @@ See .Nm .Fl g .Op Fl 46W +.Op Fl F Ar fibnum .Op Fl f Ar address_family .Op Fl M Ar core .Op Fl N Ar system @@ -772,6 +766,15 @@ See .Sx GENERAL OPTIONS . .It Fl W Avoid truncating addresses even if this causes some fields to overflow. +.It Fl F +Display the routing table with the number +.Ar fibnum . +If the specified +.Ar fibnum +is -1 or +.Fl F +is not specified, +the default routing table is displayed. .It Fl f Ar protocol_family Filter by .Ar protocol_family . diff --git a/usr.bin/script/script.1 b/usr.bin/script/script.1 index 5f40e5af28ff..ef8eaa35174f 100644 --- a/usr.bin/script/script.1 +++ b/usr.bin/script/script.1 @@ -139,7 +139,7 @@ Forward terminal size changes on The script ends when the forked shell (or command) exits (a .Em control-D to exit -the Bourne shell +the POSIX shell .Pf ( Xr sh 1 ) , and .Em exit , @@ -184,7 +184,7 @@ exists, the shell forked by will be that shell. If .Ev SHELL -is not set, the Bourne shell +is not set, the POSIX shell is assumed. .Pq Most shells set this variable automatically . .El diff --git a/usr.bin/sockstat/sockstat.1 b/usr.bin/sockstat/sockstat.1 index b0fae81ee566..70513794ebd9 100644 --- a/usr.bin/sockstat/sockstat.1 +++ b/usr.bin/sockstat/sockstat.1 @@ -25,7 +25,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd October 29, 2025 +.Dd April 15, 2026 .Dt SOCKSTAT 1 .Os .Sh NAME @@ -261,10 +261,10 @@ $ sockstat --libxo json,pretty .Xr netstat 1 , .Xr procstat 1 , .Xr setfib 1 , +.Xr libxo 3 , .Xr inet 4 , .Xr inet6 4 , -.Xr protocols 5 -.Xr libxo 3 , +.Xr protocols 5 , .Xr xo_options 7 .Sh HISTORY The diff --git a/usr.bin/stat/tests/readlink_test.sh b/usr.bin/stat/tests/readlink_test.sh index d0107e0d655e..8eff21fa7a16 100755 --- a/usr.bin/stat/tests/readlink_test.sh +++ b/usr.bin/stat/tests/readlink_test.sh @@ -33,7 +33,7 @@ basic_head() basic_body() { atf_check ln -s foo bar - atf_check -o inline:'foo\n' readlink bar + atf_check -o inline:"foo\n" readlink bar } atf_test_case f_flag @@ -44,6 +44,7 @@ f_flag_head() } f_flag_body() { + cd "$(realpath "$PWD")" atf_check touch A.file atf_check ln -s nonexistent A.link atf_check -o inline:"nonexistent\n" \ @@ -55,13 +56,15 @@ f_flag_body() atf_test_case n_flag n_flag_head() { + atf_set "descr" "Verify that calling readlink with -n will not emit " \ + "a newline character." } n_flag_body() { atf_check ln -s nonexistent.A A atf_check ln -s nonexistent.B B - atf_check -o 'inline:nonexistent.A\nnonexistent.B\n' readlink A B - atf_check -o 'inline:nonexistent.Anonexistent.B' readlink -n A B + atf_check -o inline:"nonexistent.A\nnonexistent.B\n" readlink A B + atf_check -o inline:"nonexistent.Anonexistent.B" readlink -n A B } atf_init_test_cases() diff --git a/usr.bin/stat/tests/stat_test.sh b/usr.bin/stat/tests/stat_test.sh index afe698575034..6043686396be 100755 --- a/usr.bin/stat/tests/stat_test.sh +++ b/usr.bin/stat/tests/stat_test.sh @@ -54,6 +54,7 @@ h_flag_head() } h_flag_body() { + file=$(realpath $0) # POSIX defines a hole as “[a] contiguous region of bytes # within a file, all having the value of zero” and requires # that “all seekable files shall have a virtual hole starting @@ -82,27 +83,27 @@ h_flag_body() atf_check -o inline:"$((ps)) .\n" stat -h . atf_check -o inline:"$((ps)) ." stat -hn . - # For a file, prints a list of holes. + # For a file, prints a list of holes. Some file systems don't + # like creating small holes, so we create large ones instead. + hs=$((16*1024*1024)) atf_check truncate -s 0 foo atf_check -o inline:"0 foo" \ stat -hn foo - atf_check truncate -s "$((ps))" foo - atf_check -o inline:"0-$((ps-1)) foo" \ + atf_check truncate -s "$((hs))" foo + atf_check -o inline:"0-$((hs-1)) foo" \ stat -hn foo - atf_check dd status=none if=/COPYRIGHT of=foo \ - oseek="$((ps))" bs=1 count=1 - atf_check -o inline:"0-$((ps-1)),$((ps+1)) foo" \ + atf_check dd status=none if="${file}" of=foo \ + oseek="$((hs))" bs=1 count=1 + atf_check -o inline:"0-$((hs-1)),$((hs+1)) foo" \ stat -hn foo - atf_check truncate -s "$((ps*3))" foo - atf_check -o inline:"0-$((ps-1)),$((ps*2))-$((ps*3-1)) foo" \ + atf_check truncate -s "$((hs*3))" foo + atf_check -o inline:"0-$((hs-1)),$((hs+ps))-$((hs*3-1)) foo" \ stat -hn foo # Test multiple files. - atf_check dd status=none if=/COPYRIGHT of=bar + atf_check dd status=none if="${file}" of=bar sz=$(stat -f%z bar) - atf_check -o inline:"0-$((ps-1)),$((ps*2))-$((ps*3-1)) foo -$((sz)) bar -" \ + atf_check -o inline:"0-$((hs-1)),$((hs+ps))-$((hs*3-1)) foo\n$((sz)) bar\n" \ stat -h foo bar # For a device, fail. diff --git a/usr.bin/truss/syscalls.c b/usr.bin/truss/syscalls.c index 7b299bd2e1ff..abb9d18d6783 100644 --- a/usr.bin/truss/syscalls.c +++ b/usr.bin/truss/syscalls.c @@ -58,6 +58,7 @@ #include <sys/wait.h> #include <netinet/in.h> #include <netinet/sctp.h> +#include <netlink/netlink.h> #include <arpa/inet.h> #include <assert.h> @@ -1568,6 +1569,66 @@ user_ptr32_to_psaddr(int32_t user_pointer) return ((psaddr_t)(uintptr_t)user_pointer); } +#define NETLINK_MAX_DECODE 4096 + +/* + * Reads the first IOV and attempts to print it as Netlink using libsysdecode. + * Returns true if successful, false if fallback to standard print is needed. + */ +static bool +print_netlink(FILE *fp, struct trussinfo *trussinfo, struct msghdr *msg) +{ + struct sockaddr_storage ss; + struct iovec iov; + struct ptrace_io_desc piod; + char *buf; + pid_t pid = trussinfo->curthread->proc->pid; + bool success = false; + + /* Only decode AF_NETLINK sockets. */ + if (msg->msg_name == NULL || msg->msg_namelen < offsetof(struct sockaddr, sa_data) + || msg->msg_iovlen == 0 || msg->msg_iov == NULL) + return (false); + + if (get_struct(pid, (uintptr_t)msg->msg_name, &ss, + MIN(sizeof(ss), msg->msg_namelen)) == -1) + return (false); + + if (ss.ss_family != AF_NETLINK) + return (false); + + if (get_struct(pid, (uintptr_t)msg->msg_iov, &iov, sizeof(iov)) == -1) + return (false); + + /* Cap read size to avoid unbounded allocations. */ + size_t read_len = MIN(iov.iov_len, NETLINK_MAX_DECODE); + if (read_len == 0) + return (false); + + buf = malloc(read_len); + if (buf == NULL) + return (false); + + /* Snapshot User Memory using PTRACE. */ + piod.piod_op = PIOD_READ_D; + piod.piod_offs = iov.iov_base; + piod.piod_addr = buf; + piod.piod_len = read_len; + + if (ptrace(PT_IO, pid, (caddr_t)&piod, 0) == -1) { + free(buf); + return (false); + } + + /* Delegate Decoding to libsysdecode. */ + if (sysdecode_netlink(fp, buf, read_len)) { + success = true; + } + free(buf); + + return (success); +} + /* * Converts a syscall argument into a string. Said string is * allocated via malloc(), so needs to be free()'d. sc is @@ -2706,7 +2767,11 @@ print_arg(struct syscall_arg *sc, syscallarg_t *args, syscallarg_t *retval, fputs("{", fp); print_sockaddr(fp, trussinfo, (uintptr_t)msghdr.msg_name, msghdr.msg_namelen); fprintf(fp, ",%d,", msghdr.msg_namelen); - print_iovec(fp, trussinfo, (uintptr_t)msghdr.msg_iov, msghdr.msg_iovlen); + /* Attempt Netlink decode; fallback to standard iovec if it fails. */ + if (!print_netlink(fp, trussinfo, &msghdr)) { + print_iovec(fp, trussinfo, (uintptr_t)msghdr.msg_iov, + msghdr.msg_iovlen); + } fprintf(fp, ",%d,", msghdr.msg_iovlen); print_cmsgs(fp, pid, sc->type & OUT, &msghdr); fprintf(fp, ",%u,", msghdr.msg_controllen); diff --git a/usr.bin/unzip/Makefile b/usr.bin/unzip/Makefile index 63f49a203685..3ca95e5fa881 100644 --- a/usr.bin/unzip/Makefile +++ b/usr.bin/unzip/Makefile @@ -12,7 +12,7 @@ BSDUNZIP_VERSION_STRING!= sed -n '/define.*ARCHIVE_VERSION_ONLY_STRING/{s,[^0-9. SRCS= bsdunzip.c .PATH: ${_LIBARCHIVEDIR}/libarchive_fe -SRCS+= cmdline.c lafe_err.c passphrase.c +SRCS+= cmdline.c lafe_err.c lafe_getline.c passphrase.c CFLAGS+= -DBSDUNZIP_VERSION_STRING=\"${BSDUNZIP_VERSION_STRING}\" CFLAGS+= -DPLATFORM_CONFIG_H=\"${_LIBARCHIVECONFDIR}/config_freebsd.h\" diff --git a/usr.bin/yacc/config.h b/usr.bin/yacc/config.h index c9a9fe59139b..16ee996c427c 100644 --- a/usr.bin/yacc/config.h +++ b/usr.bin/yacc/config.h @@ -92,7 +92,7 @@ /* #undef STDC_NORETURN */ /* Define to the system name. */ -#define SYSTEM_NAME "freebsd14.0" +#define SYSTEM_NAME "freebsd16.0" /* "Define to 1 if you want to use dbmalloc for testing." */ /* #undef USE_DBMALLOC */ diff --git a/usr.bin/yes/tests/yes_test.sh b/usr.bin/yes/tests/yes_test.sh index f4c04e186536..797ac5f6ac9f 100644 --- a/usr.bin/yes/tests/yes_test.sh +++ b/usr.bin/yes/tests/yes_test.sh @@ -52,6 +52,8 @@ argv_body() { yes y >/dev/null & local pid=$! + # Wait for yes(1) to exec before checking args + sleep 0.1 atf_check -o inline:"yes y\n" ps -o args= $pid kill $pid wait diff --git a/usr.bin/zstd/Makefile b/usr.bin/zstd/Makefile index 6b8ebd8cdf3d..92dc45a45490 100644 --- a/usr.bin/zstd/Makefile +++ b/usr.bin/zstd/Makefile @@ -7,6 +7,8 @@ SRCS= \ datagen.c \ dibio.c \ fileio.c \ + fileio_asyncio.c \ + lorem.c \ timefn.c \ util.c \ zstdcli.c \ |
