From owner-svn-src-head@freebsd.org Sat Jul 11 13:11:54 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id AA046361CEE; Sat, 11 Jul 2020 13:11:54 +0000 (UTC) (envelope-from trasz@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4B3r0V453mz3dpY; Sat, 11 Jul 2020 13:11:54 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 6FB851389C; Sat, 11 Jul 2020 13:11:54 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 06BDBsYJ054918; Sat, 11 Jul 2020 13:11:54 GMT (envelope-from trasz@FreeBSD.org) Received: (from trasz@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 06BDBsn5054917; Sat, 11 Jul 2020 13:11:54 GMT (envelope-from trasz@FreeBSD.org) Message-Id: <202007111311.06BDBsn5054917@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: trasz set sender to trasz@FreeBSD.org using -f From: Edward Tomasz Napierala Date: Sat, 11 Jul 2020 13:11:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r363094 - head/sys/compat/linprocfs X-SVN-Group: head X-SVN-Commit-Author: trasz X-SVN-Commit-Paths: head/sys/compat/linprocfs X-SVN-Commit-Revision: 363094 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Jul 2020 13:11:54 -0000 Author: trasz Date: Sat Jul 11 13:11:54 2020 New Revision: 363094 URL: https://svnweb.freebsd.org/changeset/base/363094 Log: Make linprocfs(5) report correct tty number in /proc//stat. Fixes sudo (sudo-1.8.21p2-3ubuntu1.2); previously would fail with "sudo: no tty present and no askpass program specified". Reviewed by: kib, emaste MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D25588 Modified: head/sys/compat/linprocfs/linprocfs.c Modified: head/sys/compat/linprocfs/linprocfs.c ============================================================================== --- head/sys/compat/linprocfs/linprocfs.c Sat Jul 11 13:08:16 2020 (r363093) +++ head/sys/compat/linprocfs/linprocfs.c Sat Jul 11 13:11:54 2020 (r363094) @@ -767,6 +767,32 @@ linprocfs_doloadavg(PFS_FILL_ARGS) return (0); } +static int +linprocfs_get_tty_nr(struct proc *p) +{ + struct session *sp; + const char *ttyname; + int error, major, minor, nr; + + PROC_LOCK_ASSERT(p, MA_OWNED); + sx_assert(&proctree_lock, SX_LOCKED); + + if ((p->p_flag & P_CONTROLT) == 0) + return (-1); + + sp = p->p_pgrp->pg_session; + if (sp == NULL) + return (-1); + + ttyname = devtoname(sp->s_ttyp->t_dev); + error = linux_driver_get_major_minor(ttyname, &major, &minor); + if (error != 0) + return (-1); + + nr = makedev(major, minor); + return (nr); +} + /* * Filler function for proc/pid/stat */ @@ -777,12 +803,14 @@ linprocfs_doprocstat(PFS_FILL_ARGS) struct timeval boottime; char state; static int ratelimit = 0; + int tty_nr; vm_offset_t startcode, startdata; getboottime(&boottime); sx_slock(&proctree_lock); PROC_LOCK(p); fill_kinfo_proc(p, &kp); + tty_nr = linprocfs_get_tty_nr(p); sx_sunlock(&proctree_lock); if (p->p_vmspace) { startcode = (vm_offset_t)p->p_vmspace->vm_taddr; @@ -809,10 +837,7 @@ linprocfs_doprocstat(PFS_FILL_ARGS) PS_ADD("pgrp", "%d", p->p_pgid); PS_ADD("session", "%d", p->p_session->s_sid); PROC_UNLOCK(p); - if (kp.ki_tdev == NODEV) - PS_ADD("tty", "%s", "-1"); - else - PS_ADD("tty", "%ju", (uintmax_t)kp.ki_tdev); + PS_ADD("tty", "%d", tty_nr); PS_ADD("tpgid", "%d", kp.ki_tpgid); PS_ADD("flags", "%u", 0); /* XXX */ PS_ADD("minflt", "%lu", kp.ki_rusage.ru_minflt);