Date: Thu, 14 Apr 2005 00:00:40 +0530 From: "Rajesh Ghanekar" <ghanekar_rajesh@hotmail.com> To: freebsd-hackers@freebsd.org Subject: not able to get controlling tty Message-ID: <BAY10-F2509CF7C63C73C1281BD28A340@phx.gbl>
index | next in thread | raw e-mail
Hi,
I have a program which prints the name of the controlling terminal. The
code snippet is as
follows:
int main(int argc, char **argv)
{
int mib[4], len;
struct kinfo_proc buf;
udev_t ttydev;
register struct dirent *dirp;
register DIR *dp;
struct stat dsb;
char namebuf[sizeof(PATH_DEV) + MAXNAMLEN];
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_PID;
mib[3] = getpid();
len = sizeof (buf);
sysctl(mib, 4, &buf, &len, NULL, 0);
ttydev = buf.kp_eproc.e_tdev;
printf("ttydev is %u, major = %d, minor = %d\n", ttydev,
major(ttydev), minor(ttydev));
if (!(dp = opendir(PATH_DEV)))
return 1;
strlcpy(namebuf, PATH_DEV, sizeof(PATH_DEV));
while ((dirp = readdir(dp))) {
memset(namebuf + sizeof(PATH_DEV) - 1, '\0',
MAXNAMLEN - sizeof(PATH_DEV) + 1);
memcpy(namebuf + sizeof(PATH_DEV) - 1, dirp->d_name,
dirp->d_namlen + 1);
if (stat(namebuf, &dsb) || (dsb.st_rdev != ttydev))
continue;
printf("OK found\n");
break;
}
}
The value returned by buf.kp_eproc.e_tdev doesn't seems to be right.
#/tmp/abc
ttydev is 30479, major = 119, minor = 15
Device name is /dev/log
# /tmp/abc
ttydev is 30577, major = 119, minor = 113
Device name is /dev/log
ttydev keeps on changing every time I run same program on same terminal.
Is there any way to get terminal device (udev_t) from struct kinfo_proc?
- Rajesh
_________________________________________________________________
Marriages at Bharatmatriony.com
http://www.bharatmatrimony.com/cgi-bin/bmclicks1.cgi?74 Relationships that
last forever
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?BAY10-F2509CF7C63C73C1281BD28A340>
