git: 70174ef7d2c8 - main - proccontrol: make -s require a target

From: Brooks Davis <brooks_at_FreeBSD.org>
Date: Fri, 23 Aug 2024 17:58:42 UTC
The branch main has been updated by brooks:

URL: https://cgit.FreeBSD.org/src/commit/?id=70174ef7d2c80abdfca0e3ad9d0bb1af61318542

commit 70174ef7d2c80abdfca0e3ad9d0bb1af61318542
Author:     Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2024-08-23 17:57:59 +0000
Commit:     Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2024-08-23 17:57:59 +0000

    proccontrol: make -s require a target
    
    Require a command to exec or a pid to target and update usage and the
    manpage to make this more clear.
    
    It makes no sense to invoke a procctl(2) command on the current process
    only to exit.  Users are sometimes confused about how proccontrol works
    and think it effects their shell environment when invoked without a
    target.  Disallowing this nonsensical behavior and clarifiying usage
    will hopefully reduce confusion.
    
    Reviewed by:    kib
    Differential Revision:  https://reviews.freebsd.org/D46422
---
 usr.bin/proccontrol/proccontrol.1 |  7 +++++--
 usr.bin/proccontrol/proccontrol.c | 14 ++++++++++----
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/usr.bin/proccontrol/proccontrol.1 b/usr.bin/proccontrol/proccontrol.1
index 7ab917e4a61f..ee71c3200b1a 100644
--- a/usr.bin/proccontrol/proccontrol.1
+++ b/usr.bin/proccontrol/proccontrol.1
@@ -34,9 +34,12 @@
 .Sh SYNOPSIS
 .Nm
 .Fl m Ar mode
-.Op Fl s Ar control
-.Op Fl q
+.Fl s Ar control
 .Fl p Ar pid | command
+.Nm
+.Fl m Ar mode
+.Fl q
+.Op Fl p Ar pid | command
 .Sh DESCRIPTION
 The
 .Nm
diff --git a/usr.bin/proccontrol/proccontrol.c b/usr.bin/proccontrol/proccontrol.c
index 4b7543d63793..be78e14fd75e 100644
--- a/usr.bin/proccontrol/proccontrol.c
+++ b/usr.bin/proccontrol/proccontrol.c
@@ -81,10 +81,14 @@ str2pid(const char *str)
 static void __dead2
 usage(void)
 {
-
-	fprintf(stderr, "Usage: proccontrol -m (aslr|protmax|trace|trapcap|"
-	    "stackgap|nonewprivs|wxmap"KPTI_USAGE LA_USAGE") [-q] "
-	    "[-s (enable|disable)] [-p pid | command]\n");
+	fprintf(stderr, "Usage:\n");
+	fprintf(stderr, "    proccontrol -m mode -s (enable|disable) "
+	    "(-p pid | command)\n");
+	fprintf(stderr, "    proccontrol -m mode -q [-p pid]\n");
+	fprintf(stderr, "Modes: "
+	    "aslr|protmax|trace|trapcap|stackgap|nonewprivs|wxmap"
+	    KPTI_USAGE LA_USAGE
+	    "\n");
 	exit(1);
 }
 
@@ -157,6 +161,8 @@ main(int argc, char *argv[])
 			usage();
 		pid = getpid();
 	} else if (pid == -1) {
+		if (!query)
+			usage();
 		pid = getpid();
 	}