Bug 289812 - Make frsig field optional in VT_SETMODE.
Summary: Make frsig field optional in VT_SETMODE.
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 16.0-CURRENT
Hardware: Any Any
: --- Affects Many People
Assignee: Ed Maste
URL:
Keywords: vt
Depends on:
Blocks:
 
Reported: 2025-09-24 13:05 UTC by Dušan Gvozdenović
Modified: 2025-12-12 18:14 UTC (History)
6 users (show)

See Also:


Attachments
Proposed change. (410 bytes, patch)
2025-09-24 13:05 UTC, Dušan Gvozdenović
no flags Details | Diff
Proposed change (412 bytes, patch)
2025-10-06 03:35 UTC, Mark Linimon
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dušan Gvozdenović 2025-09-24 13:05:41 UTC
Created attachment 264053 [details]
Proposed change.

The vt_mode::frsig signal is described to be unimplemented [1] in the vt driver
and it does not seem to be used anywhere but we fail the VT_SETMODE call with
EINVAL if it is not a valid signal number [2].

My understanding is that frsig is a historical artifact and that most modern
*NIXes do not implement it (e.g. Linux [3] and Illumos [4]). If that is the
case and there is no outlook for it to be ever implemented, we should probably
not demand it.


[1]
https://github.com/freebsd/freebsd-src/blob/7cd7b849b0629a259f4034514cf0e47e82efc44a/sys/sys/consio.h
[2]
https://github.com/freebsd/freebsd-src/blob/7cd7b849b0629a259f4034514cf0e47e82efc44a/sys/dev/vt/vt_core.c
[3]
https://github.com/torvalds/linux/blob/cec1e6e5d1ab33403b809f79cd20d6aff124ccfe/drivers/tty/vt/vt_ioctl.c#L776
[4]
https://github.com/illumos/illumos-gate/blob/92ae099e204069d2fec11f099863387b5317d849/usr/src/uts/common/io/vcons.c#L633
Comment 1 Ed Maste freebsd_committer freebsd_triage 2025-09-25 09:01:44 UTC
Seems reasonable. I'm curious how you came across this - did some code try (and fail) setting frsig?
Comment 2 Dušan Gvozdenović 2025-09-25 21:35:13 UTC
(In reply to Ed Maste from comment #1)
I am trying to get SDDM to start a Plasma Wayland session. I was stepping through the source and found that a call to VT_SETMODE fails, due to rtsig not being set and acqsig/relsig not being in range of NSIG.

The latter is to be addressed in SDDM but omitting the frsig check here would help compatibility as there would be more programs coming from Linux that did not assume this quirk. 

[1]
https://github.com/sddm/sddm/blob/fbffb577796c471e4fabf64f6422aa7bab4ea990/src/common/VirtualTerminal.cpp#L90
Comment 3 Jan Beich freebsd_committer freebsd_triage 2025-09-30 13:11:25 UTC
+1. I've bumped into this a few times while debugging standalone apps wanting to render without X11/Wayland e.g., https://github.com/mpv-player/mpv/pull/7647 https://github.com/vkmark/vkmark/pull/29
Comment 4 Ed Maste freebsd_committer freebsd_triage 2025-09-30 18:59:00 UTC
Interestingly, in lib/libvgl/main.c:  smode.frsig  = SIGINT;      

In any case I concur that frsig is currently unused and is unlikely to ever be used, so requiring userland to set it doesn't make much sense.

I don't like having possibly-uninitialized values passed in though; what about
frsig == 0 as a special case, e.g.:

                        if (!(ISSIGVALID(mode->relsig) &&
                            ISSIGVALID(mode->acqsig) &&
                            (mode->frsig == 0 || ISSIGVALID(mode->frsig)))) {
                                DPRINTF(5, "error EINVAL\n");
                                return (EINVAL);
                        }
Comment 5 Jan Beich freebsd_committer freebsd_triage 2025-10-01 14:07:57 UTC
frsig == 0 wouldn't help portability e.g., mpv didn't set frsig at all, vkmark wanted acqsig == 0 and relsig == 0 as well. According to sys/compat/linux/linux_ioctl.c invalid signals are reset to 0 instead of returning EINVAL.
Comment 6 Ed Maste freebsd_committer freebsd_triage 2025-10-01 16:55:46 UTC
It looks like Linux doesn't care, it just passes whatever was provided in acqsig or relsig to kill_pid(). For us the Linuxulator behaviour makes sense because it has to translate the requested Linux signal to FreeBSD and there is no mapping for an invalid signal.

mpv currently has `struct vt_mode vt_mode = { 0 };` and I'd expect that sort of idiom to be pretty common.

sddm has

            vt_mode setModeRequest { };
            bool ok = true;

            setModeRequest.mode = VT_PROCESS;
            setModeRequest.relsig = RELEASE_DISPLAY_SIGNAL;
            setModeRequest.acqsig = ACQUIRE_DISPLAY_SIGNAL;

            if (ioctl(fd, VT_SETMODE, &setModeRequest) < 0) {
                qDebug() << "Failed to manage VT manually:" << strerror(errno);
                ok = false;
            }
Comment 7 Mark Linimon freebsd_committer freebsd_triage 2025-10-06 03:35:55 UTC
Created attachment 264332 [details]
Proposed change

^Triage: rebase patch.
Comment 8 commit-hook freebsd_committer freebsd_triage 2025-11-27 00:20:17 UTC
A commit in branch main references this bug:

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

commit 5198c32210039d8dc92554647384eee75688848c
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2025-09-30 19:39:34 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2025-11-27 00:19:04 +0000

    vt: Allow VT_SETMODE with frsig=0

    Linux does not check that any of the signals in vt_mode VT_SETMODE ioctl
    (relsig, acqsig, frsig) are valid, but FreeBSD required that all three
    are valid.  frsig is unusued in both Linux and FreeBSD, and software
    typically leaves it unset.  To improve portability, allow frsig to be
    set to zero.

    PR:             289812
    Reported by:    Dušan Gvozdenović
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D52835

 sys/dev/vt/vt_core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Comment 9 commit-hook freebsd_committer freebsd_triage 2025-12-09 16:33:24 UTC
A commit in branch stable/15 references this bug:

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

commit 224d65015465d085f2e07edccef1f23a8c217b88
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2025-09-30 19:39:34 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2025-12-09 16:32:10 +0000

    vt: Allow VT_SETMODE with frsig=0

    Linux does not check that any of the signals in vt_mode VT_SETMODE ioctl
    (relsig, acqsig, frsig) are valid, but FreeBSD required that all three
    are valid.  frsig is unusued in both Linux and FreeBSD, and software
    typically leaves it unset.  To improve portability, allow frsig to be
    set to zero.

    PR:             289812
    Reported by:    Dušan Gvozdenović
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D52835

    (cherry picked from commit 5198c32210039d8dc92554647384eee75688848c)

 sys/dev/vt/vt_core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Comment 10 Mark Linimon freebsd_committer freebsd_triage 2025-12-12 17:42:48 UTC
^Triage: committed via D52835.
Comment 11 commit-hook freebsd_committer freebsd_triage 2025-12-12 18:14:10 UTC
A commit in branch stable/14 references this bug:

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

commit e1c985ccc335beb37bb34b368c5c019cc5f80f9c
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2025-09-30 19:39:34 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2025-12-12 18:13:13 +0000

    vt: Allow VT_SETMODE with frsig=0

    Linux does not check that any of the signals in vt_mode VT_SETMODE ioctl
    (relsig, acqsig, frsig) are valid, but FreeBSD required that all three
    are valid.  frsig is unusued in both Linux and FreeBSD, and software
    typically leaves it unset.  To improve portability, allow frsig to be
    set to zero.

    PR:             289812
    Reported by:    Dušan Gvozdenović
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D52835

    (cherry picked from commit 5198c32210039d8dc92554647384eee75688848c)
    (cherry picked from commit 224d65015465d085f2e07edccef1f23a8c217b88)

 sys/dev/vt/vt_core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)