From nobody Wed Aug 5 14:47:24 2026 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hFYCx1Y0Hz6nNH5 for ; Wed, 05 Aug 2026 14:47:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hFYCx0vl2z3q8J for ; Wed, 05 Aug 2026 14:47:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1785941245; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ACLSeCMow6rk64/aZ6TWIZg9Zo+DaclOyYp3f189v/E=; b=Xxx5Xg/O7HQT6a9Qsbn3nITimCm3WVXMV1VPvaX/FKaRUlaJ7Tl8MR4fRThmBQZ/pAr1jD vS5tAA2ttTM2n71O7l76nOIzMOVVtyHx5TfmKQzAYTgVNQijK1P5fKs5owKZATLMtJxwBi f2/mlgA4+A4JGWAKth+fUEq/q47OGsIyBUQDQic/tfNtes0uA+TrohoPWM7Y9zuMdWD4tK owATawomVm8KKBJjVCzZWolcmDuHmxR7Cia5QM5379RI3M2wkkfb1e1moDePejF2USNdm/ IS4QuJakvH8BXNE72hMLKt/8CazuAL7mDxGFraNjSu8F6UTt+dT8O8UvYglt/w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785941245; a=rsa-sha256; cv=none; b=MWXEi7C8mTuv5G82xw8lWROyacNr36KADKH7fyX9LKOa1sX9duFeHYvGrddRrg3TCICF92 NkSEjBKMeAosX9PRVBM6d9C6mQ09fns5uCbpEpa8KtJhyiC4vIXi5JUhuFIOAr3Ggm4Qfx YgUf475qYxXDn++I4MEUGp+bLtJ71Qgfbahwi74yi43V/BD+3/dtNhwSY/1SVlMVs7vJpH R5/810lB71yjYZ+EflYKuNm7LGijR4bGCeweVJJwUy9voYGIxRa4HeEFdwsSKyK9c13iBG Wat8L8WXLKBPsLgw24+9LQDVu3Qwpjm6ecS0pUrm1chwGRd0JLWJCvCCBNIO0w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1785941245; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ACLSeCMow6rk64/aZ6TWIZg9Zo+DaclOyYp3f189v/E=; b=i1n2PGxawM3J/XCsehj/HVomUky6GRf34HR32oYpKJFcYvQl/nB/VQ0I8YM1zY6hBlIOlt llxlAuCDfKD4uOVcoapQ3ZmAx8Zrdk6Ii6Syz6kw00I1q4wZ2UyIvx6G14mP6RnfMlAQBo KlEAxiYkbGHkRRJtHCv6nFo2f433SbioV+k0FEnR3P4lNf32itY1t7v/rh50OxjrSBMBP/ Nsjachs8UlRYIfuFwTfGmioRjz4sy+Vf8zJdPTCaZdJp4Yvqu/0wzxi8/HEeP+tcr33R1r KaJEDeLF9WuG/uS7NZugjWc8DobvmxxnnLmiK1S7iC/nQNbqhZdoB4rHRHXHWg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hFYCw6bNKzf2F for ; Wed, 05 Aug 2026 14:47:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 411d6 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 05 Aug 2026 14:47:24 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Popov Subject: git: 62ccaec3dba6 - main - kern/tty.c: Exterrorize returns List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: arrowd X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 62ccaec3dba6272590d97cc0aa0df28fd3d08d1c Auto-Submitted: auto-generated Date: Wed, 05 Aug 2026 14:47:24 +0000 Message-Id: <6a734cfc.411d6.46b3ab6e@gitrepo.freebsd.org> The branch main has been updated by arrowd: URL: https://cgit.FreeBSD.org/src/commit/?id=62ccaec3dba6272590d97cc0aa0df28fd3d08d1c commit 62ccaec3dba6272590d97cc0aa0df28fd3d08d1c Author: Gleb Popov AuthorDate: 2026-08-03 19:23:11 +0000 Commit: Gleb Popov CommitDate: 2026-08-05 14:46:45 +0000 kern/tty.c: Exterrorize returns Approved by: kib Pull Request: https://github.com/freebsd/freebsd-src/pull/2349 --- lib/libc/gen/exterr_cat_filenames.h | 1 + sys/kern/tty.c | 49 ++++++++++++++++++++----------------- sys/sys/exterr_cat.h | 1 + 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/lib/libc/gen/exterr_cat_filenames.h b/lib/libc/gen/exterr_cat_filenames.h index c93f84131ecf..690d5d33fbf8 100644 --- a/lib/libc/gen/exterr_cat_filenames.h +++ b/lib/libc/gen/exterr_cat_filenames.h @@ -16,6 +16,7 @@ [EXTERR_CAT_FORK] = "kern/kern_fork.c", [EXTERR_CAT_LINKER] = "kern/kern_linker.c", [EXTERR_CAT_GENIO] = "kern/sys_generic.c", + [EXTERR_CAT_TTY] = "kern/tty.c", [EXTERR_CAT_VFSBIO] = "kern/vfs_bio.c", [EXTERR_CAT_INOTIFY] = "kern/vfs_inotify.c", [EXTERR_CAT_VFSSYSCALL] = "kern/vfs_syscalls.c", diff --git a/sys/kern/tty.c b/sys/kern/tty.c index ef0137dee80a..3de1aabae36b 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -66,6 +66,8 @@ #undef TTYDEFCHARS #include #include +#define EXTERR_CATEGORY EXTERR_CAT_TTY +#include #include @@ -222,7 +224,7 @@ ttydev_enter(struct tty *tp) if (tty_gone(tp) || !tty_opened(tp)) { /* Device is already gone. */ tty_unlock(tp); - return (ENXIO); + return (EXTERROR(ENXIO, "ttydev_enter: device is gone")); } return (0); @@ -281,7 +283,7 @@ ttydev_open(struct cdev *dev, int oflags, int devtype __unused, if (tty_gone(tp)) { /* Device is already gone. */ tty_unlock(tp); - return (ENXIO); + return (EXTERROR(ENXIO, "ttydev_open: device is gone")); } /* @@ -477,7 +479,7 @@ tty_wait_background(struct tty *tp, struct thread *td, int sig) /* Don't allow the action to happen. */ PROC_UNLOCK(p); PGRP_UNLOCK(pg); - return (EIO); + return (EXTERROR(EIO, "cannot wait in background")); } PROC_UNLOCK(p); @@ -858,7 +860,7 @@ ttyil_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, tty_lock(tp); if (tty_gone(tp)) { - error = ENODEV; + error = (EXTERROR(ENODEV, "ttyil_ioctl: device is gone")); goto done; } @@ -1240,23 +1242,23 @@ tty_drop_ctty(struct tty *tp, struct proc *p) tty_lock(tp); if (tty_gone(tp)) { sx_xunlock(&proctree_lock); - return (ENODEV); + return (EXTERROR(ENODEV, "tty_drop_ctty: device is gone")); } /* * If the session doesn't have a controlling TTY, or if we weren't - * invoked on the controlling TTY, we'll return ENOIOCTL as we've + * invoked on the controlling TTY, we'll return ENOTTY as we've * historically done. */ session = p->p_session; if (session->s_ttyp == NULL || session->s_ttyp != tp) { sx_xunlock(&proctree_lock); - return (ENOTTY); + return (EXTERROR(ENOTTY, "no controlling tty")); } if (!SESS_LEADER(p)) { sx_xunlock(&proctree_lock); - return (EPERM); + return (EXTERROR(EPERM, "not a session leader")); } PROC_LOCK(p); @@ -1587,7 +1589,7 @@ tty_wait(struct tty *tp, struct cv *cv) /* Bail out when the device slipped away. */ if (tty_gone(tp)) - return (ENXIO); + return (EXTERROR(ENXIO, "tty_wait: device is gone")); /* Restart the system call when we may have been revoked. */ if (tp->t_revokecnt != revokecnt) @@ -1609,7 +1611,7 @@ tty_timedwait(struct tty *tp, struct cv *cv, int hz) /* Bail out when the device slipped away. */ if (tty_gone(tp)) - return (ENXIO); + return (EXTERROR(ENXIO, "tty_timedwait: device is gone")); /* Restart the system call when we may have been revoked. */ if (tp->t_revokecnt != revokecnt) @@ -1657,7 +1659,7 @@ tty_sti_check(struct tty *tp, int fflag, struct thread *td) { /* Check for global disable. */ if (!tty_tiocsti) - return (EPERM); + return (EXTERROR(EPERM, "security.bsd.allow_tiocsti")); /* Root can bypass all of our constraints. */ if (priv_check(td, PRIV_TTY_STI) == 0) @@ -1665,11 +1667,11 @@ tty_sti_check(struct tty *tp, int fflag, struct thread *td) /* Unprivileged users must have it opened for read. */ if ((fflag & FREAD) == 0) - return (EPERM); + return (EXTERROR(EPERM, "opened read-only")); /* It must also be their controlling tty. */ if (!tty_is_ctty(tp, td->td_proc)) - return (EACCES); + return (EXTERROR(EACCES, "not a controlling tty")); return (0); } @@ -1856,7 +1858,7 @@ tty_generic_ioctl(struct tty *tp, u_long cmd, void *data, int fflag, return (0); case TIOCGPGRP: if (!tty_is_ctty(tp, td->td_proc)) - return (ENOTTY); + return (EXTERROR(ENOTTY, "not a controlling tty")); if (tp->t_pgrp != NULL) *(int *)data = tp->t_pgrp->pg_id; @@ -1865,7 +1867,7 @@ tty_generic_ioctl(struct tty *tp, u_long cmd, void *data, int fflag, return (0); case TIOCGSID: if (!tty_is_ctty(tp, td->td_proc)) - return (ENOTTY); + return (EXTERROR(ENOTTY, "not a controlling tty")); MPASS(tp->t_session); *(int *)data = tp->t_session->s_sid; @@ -1883,7 +1885,7 @@ tty_generic_ioctl(struct tty *tp, u_long cmd, void *data, int fflag, if (!SESS_LEADER(p)) { /* Only the session leader may do this. */ sx_xunlock(&proctree_lock); - return (EPERM); + return (EXTERROR(EPERM, "not a session leader")); } if (tp->t_session != NULL && tp->t_session == p->p_session) { @@ -1907,7 +1909,7 @@ tty_generic_ioctl(struct tty *tp, u_long cmd, void *data, int fflag, * killed or the TTY revoked. */ sx_xunlock(&proctree_lock); - return (EPERM); + return (EXTERROR(EPERM, "session already has CTTY")); } /* Connect the session to the TTY. */ @@ -1940,7 +1942,10 @@ tty_generic_ioctl(struct tty *tp, u_long cmd, void *data, int fflag, if (pg == NULL || pg->pg_session != td->td_proc->p_session) { sx_sunlock(&proctree_lock); tty_lock(tp); - return (EPERM); + return (EXTERROR(EPERM, + "pgrp %jd belongs to other session %jd", + pg != NULL ? pg->pg_id : -1, + td->td_proc->p_session->s_sid)); } tty_lock(tp); @@ -1950,7 +1955,7 @@ tty_generic_ioctl(struct tty *tp, u_long cmd, void *data, int fflag, */ if (!tty_is_ctty(tp, td->td_proc)) { sx_sunlock(&proctree_lock); - return (ENOTTY); + return (EXTERROR(ENOTTY, "not a controlling tty")); } tp->t_pgrp = pg; sx_sunlock(&proctree_lock); @@ -2042,7 +2047,7 @@ tty_ioctl(struct tty *tp, u_long cmd, void *data, int fflag, struct thread *td) tty_assert_locked(tp); if (tty_gone(tp)) - return (ENXIO); + return (EXTERROR(ENXIO, "tty_ioctl: device is gone")); error = ttydevsw_ioctl(tp, cmd, data, td); if (error == ENOIOCTL) @@ -2240,7 +2245,7 @@ ttyconsdev_open(struct cdev *dev, int oflags, int devtype, struct thread *td) /* System has no console device. */ if (dev_console_filename == NULL) - return (ENXIO); + return (EXTERROR(ENXIO, "system has no console device")); /* Look up corresponding TTY by device name. */ sx_slock(&tty_list_sx); @@ -2254,7 +2259,7 @@ ttyconsdev_open(struct cdev *dev, int oflags, int devtype, struct thread *td) /* System console has no TTY associated. */ if (dev_console->si_drv1 == NULL) - return (ENXIO); + return (EXTERROR(ENXIO, "system console has no TTY attached")); return (ttydev_open(dev, oflags, devtype, td)); } diff --git a/sys/sys/exterr_cat.h b/sys/sys/exterr_cat.h index 1b56e241023b..21655e16faa7 100644 --- a/sys/sys/exterr_cat.h +++ b/sys/sys/exterr_cat.h @@ -56,5 +56,6 @@ #define EXTERR_CAT_LINKER 19 #define EXTERR_CAT_HWPMC_AMD 20 #define EXTERR_CAT_HWPMC_MOD 21 +#define EXTERR_CAT_TTY 22 #endif