Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 20 Jul 2008 19:41:06 GMT
From:      Ed Schouten <ed@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 145509 for review
Message-ID:  <200807201941.m6KJf61Y055585@repoman.freebsd.org>

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

Change 145509 by ed@ed_dull on 2008/07/20 19:40:38

	Don't use the symlink-approach for the ptycompat(4) driver. I'm
	not sure, but I can imagine older binaries break here.

Affected files ...

.. //depot/projects/mpsafetty/share/man/man4/ptycompat.4#2 edit
.. //depot/projects/mpsafetty/sys/dev/pts/pts.c#3 edit
.. //depot/projects/mpsafetty/sys/dev/pts/pts.h#2 edit
.. //depot/projects/mpsafetty/sys/dev/ptycompat/ptycompat.c#3 edit

Differences ...

==== //depot/projects/mpsafetty/share/man/man4/ptycompat.4#2 (text+ko) ====

@@ -56,7 +56,7 @@
 is being opened, a new terminal shall be created with the
 .Xr pts 4
 driver.
-A symlink to this terminal shall be created, which has the name
+A device node for this terminal shall be created, which has the name
 .Pa /dev/ttyXX .
 .Pp
 New code should not try to allocate pseudo-terminals using this
@@ -73,7 +73,7 @@
 .It Pa /dev/pty[l-sL-S][0-9a-v]
 Pseudo-terminal master devices.
 .It Pa /dev/tty[l-sL-S][0-9a-v]
-Pseudo-terminal slave device symlinks.
+Pseudo-terminal slave devices.
 .El
 .Sh DIAGNOSTICS
 None.

==== //depot/projects/mpsafetty/sys/dev/pts/pts.c#3 (text+ko) ====

@@ -90,7 +90,7 @@
  * (c)	const until freeing
  */
 struct pts_softc {
-	unsigned int	pts_unit;	/* (c) Device unit number */
+	int		pts_unit;	/* (c) Device unit number */
 
 	struct cv	pts_inwait;	/* (t) Blocking write() on master */
 	struct selinfo	pts_inpoll;	/* (t) Select queue for write() */
@@ -296,6 +296,8 @@
 		/*
 		 * Get the device unit number.
 		 */
+		if (psc->pts_unit < 0)
+			return (ENOTTY);
 		*(unsigned int *)data = psc->pts_unit;
 		return (0);
 #endif /* PTS_COMPAT || PTS_LINUX */
@@ -482,10 +484,12 @@
 	struct pts_softc *psc = softc;
 
 	/* Make device number available again */
-	free_unr(pts_pool, psc->pts_unit);
-	mtx_lock(&pts_lock);
-	pts_ndevs--;
-	mtx_unlock(&pts_lock);
+	if (psc->pts_unit >= 0) {
+		free_unr(pts_pool, psc->pts_unit);
+		mtx_lock(&pts_lock);
+		pts_ndevs--;
+		mtx_unlock(&pts_lock);
+	}
 
 #ifdef PTS_EXTERNAL
 	/* Call shutdown hook */
@@ -504,7 +508,7 @@
 	.tsw_free	= ptsdrv_free,
 };
 
-static struct tty *
+static int
 pts_alloc(int fflags, struct thread *td, struct file *fp)
 {
 	int unit;
@@ -516,16 +520,18 @@
 	unit = alloc_unrl(pts_pool);
 	if (unit < 0) {
 		mtx_unlock(&pts_lock);
-		return (NULL);
+		return (EAGAIN);
 	}
 	pts_ndevs++;
 	mtx_unlock(&pts_lock);
 
 	/* Allocate TTY and softc */
 	psc = malloc(sizeof(struct pts_softc), M_PTS, M_WAITOK|M_ZERO);
-	psc->pts_unit = unit;
 	cv_init(&psc->pts_inwait, "pts inwait");
 	cv_init(&psc->pts_outwait, "pts outwait");
+
+	psc->pts_unit = unit;
+
 	tp = tty_alloc(&pts_class, psc, NULL);
 
 	finit(fp, fflags, DTYPE_PTS, tp, &ptsdev_ops);
@@ -533,30 +539,32 @@
 	/* Expose the slave device as well */
 	tty_makedev(tp, td->td_ucred, "pts/%u", psc->pts_unit);
 
-	return (tp);
+	return (0);
 }
 
 #ifdef PTS_EXTERNAL
-int
+void
 pts_alloc_external(int fflags, struct thread *td, struct file *fp,
     pts_external_free_t freefunc, void *softc, const char *name)
 {
 	struct tty *tp;
 	struct pts_softc *psc;
 
-	tp = pts_alloc(fflags, td, fp);
-	if (tp == NULL)
-		return (EAGAIN);
-	psc = tty_softc(tp);
+	/* Allocate TTY and softc */
+	psc = malloc(sizeof(struct pts_softc), M_PTS, M_WAITOK|M_ZERO);
+	cv_init(&psc->pts_inwait, "pts inwait");
+	cv_init(&psc->pts_outwait, "pts outwait");
 
-	/* Add destructor routine */
+	psc->pts_unit = -1;
 	psc->pts_external_free = freefunc;
 	psc->pts_external_softc = softc;
 
-	/* Create device alias */
-	tty_makealias(tp, name);
+	tp = tty_alloc(&pts_class, psc, NULL);
+
+	finit(fp, fflags, DTYPE_PTS, tp, &ptsdev_ops);
 
-	return (0);
+	/* Expose the slave device as well */
+	tty_makedev(tp, td->td_ucred, "%s", name);
 }
 #endif /* PTS_EXTERNAL */
 
@@ -578,7 +586,8 @@
 		return (error);
 
 	/* Allocate the actual pseudo-TTY */
-	if (pts_alloc(FFLAGS(uap->flags & O_ACCMODE), td, fp) == NULL) {
+	error = pts_alloc(FFLAGS(uap->flags & O_ACCMODE), td, fp);
+	if (error != 0) {
 		fdclose(td->td_proc->p_fd, fp, fd, td);
 		return (EAGAIN);
 	}
@@ -596,8 +605,11 @@
 static int
 ptmx_fdopen(struct cdev *dev, int fflags, struct thread *td, struct file *fp)
 {
-	if (pts_alloc(fflags & (FREAD|FWRITE), td, fp) == NULL)
-		return (EAGAIN);
+	int error;
+
+	error = pts_alloc(fflags & (FREAD|FWRITE), td, fp);
+	if (error != 0)
+		return (error);
 
 	/* Raise a warning when a legacy PTY has been allocated */
 	if (pts_warningcnt > 0) {

==== //depot/projects/mpsafetty/sys/dev/pts/pts.h#2 (text+ko) ====

@@ -41,7 +41,7 @@
 
 typedef void pts_external_free_t(void *softc);
 
-int pts_alloc_external(int, struct thread *, struct file *,
+void pts_alloc_external(int, struct thread *, struct file *,
     pts_external_free_t, void *, const char *);
 
 #endif /* _PTS_H_ */

==== //depot/projects/mpsafetty/sys/dev/ptycompat/ptycompat.c#3 (text+ko) ====

@@ -64,7 +64,7 @@
 static int
 ptydev_fdopen(struct cdev *dev, int fflags, struct thread *td, struct file *fp)
 {
-	int u, error;
+	int u;
 	char name[] = "ttyXX";
 
 	if (!atomic_cmpset_ptr((uintptr_t *)&dev->si_drv1, 0, 1))
@@ -74,15 +74,9 @@
 	u = minor2unit(minor(dev));
 	name[3] = u >> 8;
 	name[4] = u;
-	error = pts_alloc_external(fflags & (FREAD|FWRITE), td, fp,
+	pts_alloc_external(fflags & (FREAD|FWRITE), td, fp,
 	    ptydev_free, dev, name);
 
-	if (error) {
-		/* There is no need for the master device anymore */
-		destroy_dev_sched(dev);
-		return (error);
-	}
-
 	/* Raise a warning when a legacy PTY has been allocated */
 	if (pty_warningcnt > 0) {
 		pty_warningcnt--;



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