not able to get controlling tty
Rajesh Ghanekar
ghanekar_rajesh at hotmail.com
Wed Apr 13 11:30:41 PDT 2005
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
More information about the freebsd-hackers
mailing list