Bug 268093 - killall(1) allow sending signals to pts(4)
Summary: killall(1) allow sending signals to pts(4)
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: Unspecified
Hardware: Any Any
: --- Affects Some People
Assignee: Konstantin Belousov
URL: https://cgit.freebsd.org/src/commit/?...
Keywords:
Depends on:
Blocks:
 
Reported: 2022-12-01 02:18 UTC by Daniel Dowse
Modified: 2024-01-20 22:10 UTC (History)
2 users (show)

See Also:
grahamperrin: mfc-stable13+


Attachments
Patchfile (432 bytes, text/plain)
2022-12-01 02:18 UTC, Daniel Dowse
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Dowse 2022-12-01 02:18:12 UTC
Created attachment 238465 [details]
Patchfile

Hello,

the current version of killall(1) does not allow sending signals to processes attached to a pts(4) e.g /dev/pts/4 and to do so results in an error messages like the one below. 

#killall -t pts/4
killall: stat(/dev/ttypts/4): No such file or directory


The provided patch would enable the ability to do that.

Best regards

Daniel Dowse


--- killall.c.orig      2022-12-01 02:47:39.299477000 +0100
+++ killall.c   2022-12-01 02:47:21.503069000 +0100
@@ -257,6 +257,8 @@
                        snprintf(buf, sizeof(buf), "%s", tty);
                else if (strncmp(tty, "tty", 3) == 0)
                        snprintf(buf, sizeof(buf), "/dev/%s", tty);
+               else if (strncmp(tty, "pts", 3) == 0)
+                       snprintf(buf, sizeof(buf), "/dev/%s", tty);
                else
                        snprintf(buf, sizeof(buf), "/dev/tty%s", tty);
                if (stat(buf, &sb) < 0)
Comment 1 Konstantin Belousov freebsd_committer freebsd_triage 2022-12-01 02:46:05 UTC
It is better to match on pts/, not just pts. For tty, the short match allows
to specify e.g. ttyuX, i.e. USB-serial ports.

Also, there is no need to have two identical snprintfs.

Below is what I intent to commit after your confirmation.

commit e442917ee41986c416afea1d152ad03c5daeeac4
Author: Daniel Dowse <freebsd-bugs@daemonbytes.net>
Date:   Thu Dec 1 04:42:35 2022 +0200

    killall(1): allow sending signals to processes with control terminal on pts(4)
    
    PR:     268093
    Reviewed by:    kib
    MFC after:      1 week

diff --git a/usr.bin/killall/killall.c b/usr.bin/killall/killall.c
index aca0830c158b..494a527d190b 100644
--- a/usr.bin/killall/killall.c
+++ b/usr.bin/killall/killall.c
@@ -255,7 +255,8 @@ main(int ac, char **av)
 	if (tty) {
 		if (strncmp(tty, "/dev/", 5) == 0)
 			snprintf(buf, sizeof(buf), "%s", tty);
-		else if (strncmp(tty, "tty", 3) == 0)
+		else if (strncmp(tty, "tty", 3) == 0 ||
+		    strncmp(tty, "pts/", 4) == 0)
 			snprintf(buf, sizeof(buf), "/dev/%s", tty);
 		else
 			snprintf(buf, sizeof(buf), "/dev/tty%s", tty);
Comment 2 Daniel Dowse 2022-12-01 02:56:16 UTC
Hello Konstantin,

thanks you are right. I confirm.

Best regards

Daniel
Comment 3 commit-hook freebsd_committer freebsd_triage 2022-12-01 03:42:35 UTC
A commit in branch main references this bug:

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

commit e442917ee41986c416afea1d152ad03c5daeeac4
Author:     Daniel Dowse <freebsd-bugs@daemonbytes.net>
AuthorDate: 2022-12-01 02:42:35 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-12-01 02:42:35 +0000

    killall(1): allow sending signals to processes with control terminal on pts(4)

    PR:     268093
    Reviewed by:    kib
    MFC after:      1 week

 usr.bin/killall/killall.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Comment 4 Graham Perrin freebsd_committer freebsd_triage 2022-12-04 17:00:40 UTC
Thanks. 

Triage: [patch] is amongst the summary line tags that are deprecated. 

MFC to both stable/13 and stable/12, or just 13?
Comment 5 commit-hook freebsd_committer freebsd_triage 2022-12-08 01:19:16 UTC
A commit in branch stable/13 references this bug:

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

commit a76fa7bb6cb721bcccc257ddbc4398d25dc8def8
Author:     Daniel Dowse <freebsd-bugs@daemonbytes.net>
AuthorDate: 2022-12-01 02:42:35 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-12-08 01:18:32 +0000

    killall(1): allow sending signals to processes with control terminal on pts(4)

    PR:     268093

    (cherry picked from commit e442917ee41986c416afea1d152ad03c5daeeac4)

 usr.bin/killall/killall.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)