Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 2 Oct 2025 08:20:40 GMT
From:      Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= <des@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 76fd9309e55e - stable/15 - pwait: Fix timeout unit parser
Message-ID:  <202510020820.5928Ketv023022@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/15 has been updated by des:

URL: https://cgit.FreeBSD.org/src/commit/?id=76fd9309e55e93c0c998db16c26ab480e49887a2

commit 76fd9309e55e93c0c998db16c26ab480e49887a2
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2025-09-23 12:56:04 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2025-10-02 08:19:23 +0000

    pwait: Fix timeout unit parser
    
    The timeout parser would check the first character after the number and
    ignore any subsequent ones.
    
    While here, switch to bool for booleans and fix some style nits.
    
    MFC after:      1 week
    Reviewed by:    0mp, markj
    Differential Revision:  https://reviews.freebsd.org/D52612
    
    (cherry picked from commit 3aac05f56620712744cb57d71a0ef42f8d8e3b52)
---
 bin/pwait/pwait.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/bin/pwait/pwait.c b/bin/pwait/pwait.c
index 0fae22562607..a78c0bb84ca8 100644
--- a/bin/pwait/pwait.c
+++ b/bin/pwait/pwait.c
@@ -39,6 +39,7 @@
 #include <err.h>
 #include <errno.h>
 #include <signal.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -48,7 +49,6 @@
 static void
 usage(void)
 {
-
 	fprintf(stderr, "usage: pwait [-t timeout] [-ov] pid ...\n");
 	exit(EX_USAGE);
 }
@@ -61,15 +61,15 @@ main(int argc, char *argv[])
 {
 	struct itimerval itv;
 	struct kevent *e;
-	int oflag, tflag, verbose;
-	int i, kq, n, nleft, opt, status;
-	long pid;
 	char *end, *s;
 	double timeout;
+	long pid;
+	int i, kq, n, nleft, opt, status;
+	bool oflag, tflag, verbose;
 
-	oflag = 0;
-	tflag = 0;
-	verbose = 0;
+	oflag = false;
+	tflag = false;
+	verbose = false;
 	memset(&itv, 0, sizeof(itv));
 
 	while ((opt = getopt(argc, argv, "ot:v")) != -1) {
@@ -78,25 +78,31 @@ main(int argc, char *argv[])
 			oflag = 1;
 			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 +112,7 @@ main(int argc, char *argv[])
 			    (suseconds_t)(timeout * 1000000UL);
 			break;
 		case 'v':
-			verbose = 1;
+			verbose = true;
 			break;
 		default:
 			usage();
@@ -134,7 +140,7 @@ main(int argc, char *argv[])
 	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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202510020820.5928Ketv023022>