Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 13 Aug 2008 14:25:45 GMT
From:      Ed Schouten <ed@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 147301 for review
Message-ID:  <200808131425.m7DEPjcE051410@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=147301

Change 147301 by ed@ed_mekker on 2008/08/13 14:24:46

	According to POSIX, we must implement fstat(), even for our new
	pseudo-terminals. Make the implementation a little more complete
	by implementing the st_uid and st_gid fields. We fill it up with
	cr_ruid and GID_TTY, which matches the user/group pair used to
	create the device node.

Affected files ...

.. //depot/projects/mpsafetty/sys/kern/tty_pts.c#8 edit

Differences ...

==== //depot/projects/mpsafetty/sys/kern/tty_pts.c#8 (text+ko) ====

@@ -388,7 +388,6 @@
 	return (revents);
 }
 
-#if defined(PTS_COMPAT) || defined(PTS_LINUX)
 static int
 ptsdev_stat(struct file *fp, struct stat *sb, struct ucred *active_cred,
     struct thread *td)
@@ -396,18 +395,23 @@
 	struct tty *tp = fp->f_data;
 
 	/*
-	 * To make older FreeBSD and Linux binaries work, implement a
-	 * basic fstat(), which should contain enough data to make
-	 * reverse device name lookups work.
+	 * According to POSIX, we must implement an fstat(). This also
+	 * makes this implementation compatible with Linux binaries,
+	 * because Linux calls fstat() on the pseudo-terminal master to
+	 * obtain st_rdev.
+	 *
+	 * XXX: POSIX also mentions we must fill in st_dev, st_atime,
+	 * st_ctime and st_mtime, but how?
 	 */
 
 	bzero(sb, sizeof *sb);
 	sb->st_ino = sb->st_rdev = tty_udev(tp);
 	sb->st_mode = S_IFCHR;
+	sb->st_uid = tp->t_dev->si_cred->cr_ruid;
+	sb->st_gid = GID_TTY;
 	
 	return (0);
 }
-#endif /* PTS_COMPAT || PTS_LINUX */
 
 static int
 ptsdev_close(struct file *fp, struct thread *td)
@@ -426,9 +430,7 @@
 	.fo_write	= ptsdev_write,
 	.fo_ioctl	= ptsdev_ioctl,
 	.fo_poll	= ptsdev_poll,
-#if defined(PTS_COMPAT) || defined(PTS_LINUX)
 	.fo_stat	= ptsdev_stat,
-#endif /* PTS_COMPAT || PTS_LINUX */
 	.fo_close	= ptsdev_close,
 	.fo_flags	= DFLAG_PASSABLE,
 };



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200808131425.m7DEPjcE051410>