diff options
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/cp/tests/Makefile | 2 | ||||
| -rwxr-xr-x | bin/cp/tests/cp_test.sh | 10 | ||||
| -rw-r--r-- | bin/cp/tests/sparse.c | 73 | ||||
| -rw-r--r-- | bin/date/date.1 | 41 | ||||
| -rw-r--r-- | bin/freebsd-version/freebsd-version.1 | 4 | ||||
| -rw-r--r-- | bin/ln/tests/ln_test.sh | 2 | ||||
| -rw-r--r-- | bin/pwait/pwait.1 | 6 | ||||
| -rw-r--r-- | bin/pwait/pwait.c | 128 | ||||
| -rw-r--r-- | bin/pwait/tests/pwait_test.sh | 38 | ||||
| -rw-r--r-- | bin/sh/Makefile | 7 | ||||
| -rw-r--r-- | bin/sh/dot.profile | 2 | ||||
| -rw-r--r-- | bin/timeout/tests/timeout_test.sh | 2 | ||||
| -rw-r--r-- | bin/uuidgen/uuidgen.1 | 17 |
13 files changed, 166 insertions, 166 deletions
diff --git a/bin/cp/tests/Makefile b/bin/cp/tests/Makefile index 3fa9ae8f0685..a1917ada8fbf 100644 --- a/bin/cp/tests/Makefile +++ b/bin/cp/tests/Makefile @@ -1,7 +1,5 @@ PACKAGE= tests ATF_TESTS_SH= cp_test -PROGS+= sparse -BINDIR= ${TESTSDIR} .include <bsd.test.mk> diff --git a/bin/cp/tests/cp_test.sh b/bin/cp/tests/cp_test.sh index 999993bfad67..b637f862b7d3 100755 --- a/bin/cp/tests/cp_test.sh +++ b/bin/cp/tests/cp_test.sh @@ -90,7 +90,7 @@ hardlink_body() echo "foo" >foo atf_check cp -l foo bar atf_check -o inline:"foo\n" cat bar - atf_check_equal "$(stat -f%d,%i foo)" "$(stat -f%d,%i bar)" + atf_check test foo -ef bar } atf_test_case hardlink_exists @@ -105,7 +105,7 @@ hardlink_exists_body() echo "bar" >bar atf_check -s not-exit:0 -e match:exists cp -l foo bar atf_check -o inline:"bar\n" cat bar - atf_check_not_equal "$(stat -f%d,%i foo)" "$(stat -f%d,%i bar)" + atf_check test ! foo -ef bar } atf_test_case hardlink_exists_force @@ -120,7 +120,7 @@ hardlink_exists_force_body() echo "bar" >bar atf_check cp -fl foo bar atf_check -o inline:"foo\n" cat bar - atf_check_equal "$(stat -f%d,%i foo)" "$(stat -f%d,%i bar)" + atf_check test foo -ef bar } atf_test_case matching_srctgt @@ -384,12 +384,12 @@ samefile_body() file_is_sparse() { - atf_check ${0%/*}/sparse "$1" + atf_check -o match:"^[0-9]+-[0-9]" stat -h "$1" } files_are_equal() { - atf_check_not_equal "$(stat -f%d,%i "$1")" "$(stat -f%d,%i "$2")" + atf_check test ! "$1" -ef "$2" atf_check cmp "$1" "$2" } diff --git a/bin/cp/tests/sparse.c b/bin/cp/tests/sparse.c deleted file mode 100644 index 78957581a56c..000000000000 --- a/bin/cp/tests/sparse.c +++ /dev/null @@ -1,73 +0,0 @@ -/*- - * Copyright (c) 2023 Klara, Inc. - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include <err.h> -#include <fcntl.h> -#include <stdbool.h> -#include <stdio.h> -#include <stdlib.h> -#include <sysexits.h> -#include <unistd.h> - -static bool verbose; - -/* - * Returns true if the file named by its argument is sparse, i.e. if - * seeking to SEEK_HOLE returns a different value than seeking to - * SEEK_END. - */ -static bool -sparse(const char *filename) -{ - off_t hole, end; - int fd; - - if ((fd = open(filename, O_RDONLY)) < 0 || - (hole = lseek(fd, 0, SEEK_HOLE)) < 0 || - (end = lseek(fd, 0, SEEK_END)) < 0) - err(1, "%s", filename); - close(fd); - if (end > hole) { - if (verbose) - printf("%s: hole at %zu\n", filename, (size_t)hole); - return (true); - } - return (false); -} - -static void -usage(void) -{ - - fprintf(stderr, "usage: sparse [-v] file [...]\n"); - exit(EX_USAGE); -} - -int -main(int argc, char *argv[]) -{ - int opt, rv; - - while ((opt = getopt(argc, argv, "v")) != -1) { - switch (opt) { - case 'v': - verbose = true; - break; - default: - usage(); - break; - } - } - argc -= optind; - argv += optind; - if (argc == 0) - usage(); - rv = EXIT_SUCCESS; - while (argc-- > 0) - if (!sparse(*argv++)) - rv = EXIT_FAILURE; - exit(rv); -} diff --git a/bin/date/date.1 b/bin/date/date.1 index 62d28a7df0a0..f68892bd408d 100644 --- a/bin/date/date.1 +++ b/bin/date/date.1 @@ -29,7 +29,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd September 10, 2024 +.Dd November 5, 2025 .Dt DATE 1 .Os .Sh NAME @@ -129,7 +129,7 @@ format. Parsing is done using .Xr strptime 3 . .It Fl I Ns Op Ar FMT -Use +Use extended .St -iso8601 output format. .Ar FMT @@ -143,7 +143,8 @@ values are .Cm minutes , .Cm seconds , and -.Cm ns No Pq for nanoseconds . +.Cm ns +.Pq for nanoseconds . The date and time is formatted to the specified precision. When .Ar FMT @@ -154,9 +155,9 @@ is .Cm seconds , or .Cm ns Pc , -the +the extended .St -iso8601 -format includes the timezone. +format includes the timezone offset. .It Fl j Do not try to set the date. This allows you to use the @@ -172,7 +173,7 @@ Obsolete flag, accepted and ignored for compatibility. .It Fl R Use RFC 2822 date and time output format. This is equivalent to using -.Dq Li %a, %d %b %Y \&%T %z +.Ql %a, %d %b %Y \&%T %z as .Ar output_fmt while @@ -194,9 +195,7 @@ and can be specified in decimal, octal, or hex. Print the date and time of the last modification of .Ar filename . .It Fl u -Display or set the date in -.Tn UTC -(Coordinated Universal) time. +Display or set the date in UTC (Coordinated Universal) time. By default .Nm displays the time in the time zone described by @@ -328,7 +327,7 @@ The format string may contain any of the conversion specifications described in the .Xr strftime 3 manual page and -.Ql %N +.Ql \&%N for nanoseconds, as well as any arbitrary text. A newline .Pq Ql \en @@ -468,7 +467,7 @@ will display: .Dl "Sun Jan 4 04:15:24 GMT 1998" .Pp where it is currently -.Li "Mon Aug 4 04:15:24 BST 1997" . +.Ql "Mon Aug 4 04:15:24 BST 1997" . .Pp The command: .Pp @@ -493,29 +492,31 @@ will display the last Friday of the month: .Dl "Fri Aug 29 04:31:11 BST 1997" .Pp where it is currently -.Li "Mon Aug 4 04:31:11 BST 1997" . +.Ql "Mon Aug 4 04:31:11 BST 1997" . .Pp The command: .Pp .Dl "date 8506131627" .Pp sets the date to -.Dq Li "June 13, 1985, 4:27 PM" . +.Ql "June 13, 1985, 4:27 PM" . .Pp .Dl "date ""+%Y%m%d%H%M.%S""" .Pp may be used on one machine to print out the date suitable for setting on another. -.Qq ( Li "+%m%d%H%M%Y.%S" -for use on -.Tn Linux . ) +.Po Use +.Ql "+%m%d%H%M%Y.%S" +with GNU date on +Linux . +.Pc .Pp The command: .Pp .Dl "date 1432" .Pp sets the time to -.Li "2:32 PM" , +.Ql "2:32 PM" , without modifying the date. .Pp The command @@ -591,10 +592,10 @@ flag is compatible with .St -iso8601 . .Pp The -.Ql %N +.Ql \&%N conversion specification for nanoseconds is a non-standard extension. It is compatible with GNU date's -.Ql %N . +.Ql \&%N . .Sh HISTORY A .Nm @@ -615,6 +616,6 @@ flag was added in .Fx 12.0 . .Pp The -.Ql %N +.Ql \&%N conversion specification was added in .Fx 14.1 . diff --git a/bin/freebsd-version/freebsd-version.1 b/bin/freebsd-version/freebsd-version.1 index 82ea9c707d69..c2b3241d0434 100644 --- a/bin/freebsd-version/freebsd-version.1 +++ b/bin/freebsd-version/freebsd-version.1 @@ -23,7 +23,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd October 1, 2021 +.Dd August 27, 2025 .Dt FREEBSD-VERSION 1 .Os .Sh NAME @@ -73,7 +73,7 @@ If several of the above options are specified, will print the installed kernel version first, then the running kernel version, next the userland version, and finally the userland version of the specified jails, on separate lines. -If neither is specified, it will print the userland version only. +If no option is specified, it will print the userland version only. .Sh IMPLEMENTATION NOTES The .Nm diff --git a/bin/ln/tests/ln_test.sh b/bin/ln/tests/ln_test.sh index 78b4074aea18..ac9d785ba1fc 100644 --- a/bin/ln/tests/ln_test.sh +++ b/bin/ln/tests/ln_test.sh @@ -28,7 +28,7 @@ atf_check_same_file() { - atf_check_equal "$(stat -f %d,%i "$1")" "$(stat -f %d,%i "$2")" + atf_check test "$1" -ef "$2" } atf_check_symlink_to() diff --git a/bin/pwait/pwait.1 b/bin/pwait/pwait.1 index 83ac8bcef317..d92b829b1d6a 100644 --- a/bin/pwait/pwait.1 +++ b/bin/pwait/pwait.1 @@ -30,7 +30,7 @@ .\" USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY .\" OF SUCH DAMAGE. .\" -.Dd January 21, 2021 +.Dd October 22, 2025 .Dt PWAIT 1 .Os .Sh NAME @@ -39,7 +39,7 @@ .Sh SYNOPSIS .Nm .Op Fl t Ar duration -.Op Fl ov +.Op Fl opv .Ar pid \&... .Sh DESCRIPTION @@ -51,6 +51,8 @@ The following option is available: .Bl -tag -width indent .It Fl o Exit when any of the given processes has terminated. +.It Fl p +On exit, print a list of processes that have not terminated. .It Fl t Ar duration If any process is still running after .Ar duration , diff --git a/bin/pwait/pwait.c b/bin/pwait/pwait.c index 0fae22562607..59bf0eb93ced 100644 --- a/bin/pwait/pwait.c +++ b/bin/pwait/pwait.c @@ -33,23 +33,40 @@ #include <sys/types.h> #include <sys/event.h> +#include <sys/sysctl.h> #include <sys/time.h> +#include <sys/tree.h> #include <sys/wait.h> #include <err.h> #include <errno.h> #include <signal.h> +#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sysexits.h> #include <unistd.h> +struct pid { + RB_ENTRY(pid) entry; + pid_t pid; +}; + +static int +pidcmp(const struct pid *a, const struct pid *b) +{ + return (a->pid > b->pid ? 1 : a->pid < b->pid ? -1 : 0); +} + +RB_HEAD(pidtree, pid); +static struct pidtree pids = RB_INITIALIZER(&pids); +RB_GENERATE_STATIC(pidtree, pid, entry, pidcmp); + static void usage(void) { - - fprintf(stderr, "usage: pwait [-t timeout] [-ov] pid ...\n"); + fprintf(stderr, "usage: pwait [-t timeout] [-opv] pid ...\n"); exit(EX_USAGE); } @@ -61,42 +78,55 @@ main(int argc, char *argv[]) { struct itimerval itv; struct kevent *e; - int oflag, tflag, verbose; - int i, kq, n, nleft, opt, status; - long pid; + struct pid k, *p; char *end, *s; double timeout; + size_t sz; + long pid; + pid_t mypid; + int i, kq, n, ndone, nleft, opt, pid_max, ret, status; + bool oflag, pflag, tflag, verbose; - oflag = 0; - tflag = 0; - verbose = 0; + oflag = false; + pflag = false; + tflag = false; + verbose = false; memset(&itv, 0, sizeof(itv)); - while ((opt = getopt(argc, argv, "ot:v")) != -1) { + while ((opt = getopt(argc, argv, "opt:v")) != -1) { switch (opt) { case 'o': - oflag = 1; + oflag = true; + break; + case 'p': + pflag = true; break; case 't': - tflag = 1; + tflag = true; errno = 0; timeout = strtod(optarg, &end); if (end == optarg || errno == ERANGE || timeout < 0) { errx(EX_DATAERR, "timeout value"); } - switch(*end) { - case 0: + switch (*end) { + case '\0': + break; case 's': + end++; break; case 'h': timeout *= 60; /* FALLTHROUGH */ case 'm': timeout *= 60; + end++; break; default: errx(EX_DATAERR, "timeout unit"); } + if (*end != '\0') { + errx(EX_DATAERR, "timeout unit"); + } if (timeout > 100000000L) { errx(EX_DATAERR, "timeout value"); } @@ -106,7 +136,7 @@ main(int argc, char *argv[]) (suseconds_t)(timeout * 1000000UL); break; case 'v': - verbose = 1; + verbose = true; break; default: usage(); @@ -121,53 +151,57 @@ main(int argc, char *argv[]) usage(); } - kq = kqueue(); - if (kq == -1) { + if ((kq = kqueue()) < 0) err(EX_OSERR, "kqueue"); - } - e = malloc((argc + tflag) * sizeof(struct kevent)); - if (e == NULL) { + sz = sizeof(pid_max); + if (sysctlbyname("kern.pid_max", &pid_max, &sz, NULL, 0) != 0) { + pid_max = 99999; + } + if ((e = malloc((argc + tflag) * sizeof(*e))) == NULL) { err(EX_OSERR, "malloc"); } - nleft = 0; + ndone = nleft = 0; + mypid = getpid(); for (n = 0; n < argc; n++) { s = argv[n]; /* Undocumented Solaris compat */ - if (!strncmp(s, "/proc/", 6)) { + if (strncmp(s, "/proc/", 6) == 0) { s += 6; } errno = 0; pid = strtol(s, &end, 10); - if (pid < 0 || *end != '\0' || errno != 0) { + if (pid < 0 || pid > pid_max || *end != '\0' || errno != 0) { warnx("%s: bad process id", s); continue; } - if (pid == getpid()) { + if (pid == mypid) { warnx("%s: skipping my own pid", s); continue; } - for (i = 0; i < nleft; i++) { - if (e[i].ident == (uintptr_t)pid) { - break; - } + if ((p = malloc(sizeof(*p))) == NULL) { + err(EX_OSERR, NULL); } - if (i < nleft) { + p->pid = pid; + if (RB_INSERT(pidtree, &pids, p) != NULL) { /* Duplicate. */ + free(p); continue; } EV_SET(e + nleft, pid, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, NULL); if (kevent(kq, e + nleft, 1, NULL, 0, NULL) == -1) { + if (errno != ESRCH) + err(EX_OSERR, "kevent()"); warn("%ld", pid); - if (oflag) { - exit(EX_OK); - } + RB_REMOVE(pidtree, &pids, p); + free(p); + ndone++; } else { nleft++; } } - if (nleft > 0 && tflag) { + if ((ndone == 0 || !oflag) && nleft > 0 && tflag) { /* * Explicitly detect SIGALRM so that an exit status of 124 * can be returned rather than 142. @@ -182,7 +216,8 @@ main(int argc, char *argv[]) err(EX_OSERR, "setitimer"); } } - while (nleft > 0) { + ret = EX_OK; + while ((ndone == 0 || !oflag) && ret == EX_OK && nleft > 0) { n = kevent(kq, NULL, 0, e, nleft + tflag, NULL); if (n == -1) { err(EX_OSERR, "kevent"); @@ -192,29 +227,34 @@ main(int argc, char *argv[]) if (verbose) { printf("timeout\n"); } - exit(124); + ret = 124; } + pid = e[i].ident; if (verbose) { status = e[i].data; if (WIFEXITED(status)) { printf("%ld: exited with status %d.\n", - (long)e[i].ident, - WEXITSTATUS(status)); + pid, WEXITSTATUS(status)); } else if (WIFSIGNALED(status)) { printf("%ld: killed by signal %d.\n", - (long)e[i].ident, - WTERMSIG(status)); + pid, WTERMSIG(status)); } else { - printf("%ld: terminated.\n", - (long)e[i].ident); + printf("%ld: terminated.\n", pid); } } - if (oflag) { - exit(EX_OK); + k.pid = pid; + if ((p = RB_FIND(pidtree, &pids, &k)) != NULL) { + RB_REMOVE(pidtree, &pids, p); + free(p); + ndone++; } --nleft; } } - - exit(EX_OK); + if (pflag) { + RB_FOREACH(p, pidtree, &pids) { + printf("%d\n", p->pid); + } + } + exit(ret); } diff --git a/bin/pwait/tests/pwait_test.sh b/bin/pwait/tests/pwait_test.sh index 66bdd6981704..d31ca21cff93 100644 --- a/bin/pwait/tests/pwait_test.sh +++ b/bin/pwait/tests/pwait_test.sh @@ -310,6 +310,43 @@ or_flag_cleanup() wait $p2 $p4 $p6 >/dev/null 2>&1 } +atf_test_case print +print_head() +{ + atf_set "descr" "Test the -p flag" +} + +print_body() +{ + sleep 1 & + p1=$! + + sleep 5 & + p5=$! + + sleep 10 & + p10=$! + + atf_check \ + -o inline:"$p5\n$p10\n" \ + -s exit:124 \ + pwait -t 2 -p $p10 $p5 $p1 $p5 $p10 + + atf_check \ + -e inline:"kill: $p1: No such process\n" \ + -s exit:1 \ + kill -0 $p1 + + atf_check kill -0 $p5 + atf_check kill -0 $p10 +} + +print_cleanup() +{ + kill $p1 $p5 $p10 >/dev/null 2>&1 + wait $p1 $p5 $p10 >/dev/null 2>&1 +} + atf_init_test_cases() { atf_add_test_case basic @@ -318,4 +355,5 @@ atf_init_test_cases() atf_add_test_case timeout_no_timeout atf_add_test_case timeout_many atf_add_test_case or_flag + atf_add_test_case print } diff --git a/bin/sh/Makefile b/bin/sh/Makefile index 087dbf40c3bd..2b1eca8e4b31 100644 --- a/bin/sh/Makefile +++ b/bin/sh/Makefile @@ -69,11 +69,4 @@ token.h: mktokens HAS_TESTS= SUBDIR.${MK_TESTS}+= tests -beforeinstallconfig: - rm -f ${DESTDIR}/.profile - -LINKMODE=${CONFMODE} -afterinstallconfig: - ${INSTALL_LINK} ${TAG_ARGS} ${DESTDIR}/root/.profile ${DESTDIR}/.profile - .include <bsd.prog.mk> diff --git a/bin/sh/dot.profile b/bin/sh/dot.profile index d27a2ae2fdbe..cba9bcf18ad9 100644 --- a/bin/sh/dot.profile +++ b/bin/sh/dot.profile @@ -1,6 +1,4 @@ # -HOME=/root -export HOME PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:~/bin export PATH TERM=${TERM:-xterm} diff --git a/bin/timeout/tests/timeout_test.sh b/bin/timeout/tests/timeout_test.sh index b1bf69968e84..88dbaa808043 100644 --- a/bin/timeout/tests/timeout_test.sh +++ b/bin/timeout/tests/timeout_test.sh @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: BSD-2-Clause +# Copyright (c) 2014 Baptiste Daroussin <bapt@FreeBSD.org> atf_test_case nominal nominal_head() diff --git a/bin/uuidgen/uuidgen.1 b/bin/uuidgen/uuidgen.1 index 1c2e7cce91d3..f7911b408f36 100644 --- a/bin/uuidgen/uuidgen.1 +++ b/bin/uuidgen/uuidgen.1 @@ -1,3 +1,6 @@ +.\" +.\" SPDX-License-Identifier: BSD-2-Clause +.\" .\" Copyright (c) 2002 Marcel Moolenaar .\" All rights reserved. .\" @@ -22,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 March 1, 2023 +.Dd August 27, 2025 .Dt UUIDGEN 1 .Os .Sh NAME @@ -30,9 +33,7 @@ .Nd generate universally unique identifiers .Sh SYNOPSIS .Nm -.Op Fl 1 -.Op Fl r -.Op Fl c +.Op Fl 1cr .Op Fl n Ar count .Op Fl o Ar filename .Sh DESCRIPTION @@ -50,8 +51,6 @@ This option only has effect if multiple identifiers are to be generated and instructs .Nm to not generate them in batch, but one at a time. -.It Fl r -This option controls creation of random UUID (version 4). .It Fl c This option controls creation of compact UUID (without hyphen). .It Fl n @@ -65,6 +64,8 @@ The upper hard limit is 2048 Redirect output to .Ar filename instead of stdout. +.It Fl r +This option controls creation of random UUID (version 4). .El .Pp Batched generation yields a dense set of identifiers in such a way that there @@ -80,11 +81,11 @@ reflected in the distance between two successive identifiers. .Sh EXAMPLES Generate a batch of three UUIDs. Notice the similarity of the string before the first hyphen of the UUID -(known as +.Po known as .Em time_low in .Em rfc4122 -): +.Pc : .Bd -literal -offset indent $ uuidgen -n3 8bc44345-4d90-11ee-88c7-b42e991fc52e |
