Make linprocfs(5) report correct tty number in /proc/<PID>/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
This commit is contained in:
parent
17f701a3fb
commit
ce28fd95e0
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=363094
@ -767,6 +767,32 @@ linprocfs_doloadavg(PFS_FILL_ARGS)
|
|||||||
return (0);
|
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
|
* Filler function for proc/pid/stat
|
||||||
*/
|
*/
|
||||||
@ -777,12 +803,14 @@ linprocfs_doprocstat(PFS_FILL_ARGS)
|
|||||||
struct timeval boottime;
|
struct timeval boottime;
|
||||||
char state;
|
char state;
|
||||||
static int ratelimit = 0;
|
static int ratelimit = 0;
|
||||||
|
int tty_nr;
|
||||||
vm_offset_t startcode, startdata;
|
vm_offset_t startcode, startdata;
|
||||||
|
|
||||||
getboottime(&boottime);
|
getboottime(&boottime);
|
||||||
sx_slock(&proctree_lock);
|
sx_slock(&proctree_lock);
|
||||||
PROC_LOCK(p);
|
PROC_LOCK(p);
|
||||||
fill_kinfo_proc(p, &kp);
|
fill_kinfo_proc(p, &kp);
|
||||||
|
tty_nr = linprocfs_get_tty_nr(p);
|
||||||
sx_sunlock(&proctree_lock);
|
sx_sunlock(&proctree_lock);
|
||||||
if (p->p_vmspace) {
|
if (p->p_vmspace) {
|
||||||
startcode = (vm_offset_t)p->p_vmspace->vm_taddr;
|
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("pgrp", "%d", p->p_pgid);
|
||||||
PS_ADD("session", "%d", p->p_session->s_sid);
|
PS_ADD("session", "%d", p->p_session->s_sid);
|
||||||
PROC_UNLOCK(p);
|
PROC_UNLOCK(p);
|
||||||
if (kp.ki_tdev == NODEV)
|
PS_ADD("tty", "%d", tty_nr);
|
||||||
PS_ADD("tty", "%s", "-1");
|
|
||||||
else
|
|
||||||
PS_ADD("tty", "%ju", (uintmax_t)kp.ki_tdev);
|
|
||||||
PS_ADD("tpgid", "%d", kp.ki_tpgid);
|
PS_ADD("tpgid", "%d", kp.ki_tpgid);
|
||||||
PS_ADD("flags", "%u", 0); /* XXX */
|
PS_ADD("flags", "%u", 0); /* XXX */
|
||||||
PS_ADD("minflt", "%lu", kp.ki_rusage.ru_minflt);
|
PS_ADD("minflt", "%lu", kp.ki_rusage.ru_minflt);
|
||||||
|
Loading…
Reference in New Issue
Block a user