Date: Mon, 18 Aug 2008 14:09:07 GMT From: Ed Schouten <ed@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 147721 for review Message-ID: <200808181409.m7IE97BN051597@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=147721 Change 147721 by ed@ed_dull on 2008/08/18 14:08:25 Fix a compatibility regression: I thought I had older FreeBSD versions working, but it turned out openpty() does things differently than posix_openpt()/ptsname(). We had openpty() working, but ptsname() failed, because the minor number that gets returned should get translated to the master device, not the slave device. Make the PTS_EXTERNAL interface a little more ugly by changing the fstat() and FIODGNAME stuff to return the device number for the master part. Affected files ... .. //depot/projects/mpsafetty/sys/kern/tty_pts.c#10 edit .. //depot/projects/mpsafetty/sys/kern/tty_pty.c#8 edit .. //depot/projects/mpsafetty/sys/sys/tty.h#11 edit Differences ... ==== //depot/projects/mpsafetty/sys/kern/tty_pts.c#10 (text+ko) ==== @@ -85,8 +85,7 @@ struct selinfo pts_outpoll; /* (t) Select queue for read(). */ #ifdef PTS_EXTERNAL - pts_external_free_t *pts_external_free; /* (c) Destructor callback. */ - void *pts_external_softc; /* (c) Destructor softc. */ + struct cdev *pts_cdev; /* (c) Master device node. */ #endif /* PTS_EXTERNAL */ struct uidinfo *pts_uidinfo; /* (c) Resource limit. */ @@ -243,7 +242,12 @@ /* Reverse device name lookups, for ptsname() and ttyname(). */ fgn = data; - p = tty_devname(tp); +#ifdef PTS_EXTERNAL + if (psc->pts_cdev != NULL) + p = devtoname(psc->pts_cdev); + else +#endif /* PTS_EXTERNAL */ + p = tty_devname(tp); i = strlen(p) + 1; if (i > fgn->len) return (EINVAL); @@ -393,6 +397,9 @@ struct thread *td) { struct tty *tp = fp->f_data; +#ifdef PTS_EXTERNAL + struct pts_softc *psc = tty_softc(tp); +#endif /* PTS_EXTERNAL */ /* * According to POSIX, we must implement an fstat(). This also @@ -405,7 +412,12 @@ */ bzero(sb, sizeof *sb); - sb->st_ino = sb->st_rdev = tty_udev(tp); +#ifdef PTS_EXTERNAL + if (psc->pts_cdev != NULL) + sb->st_ino = sb->st_rdev = dev2udev(psc->pts_cdev); + else +#endif /* PTS_EXTERNAL */ + 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; @@ -479,9 +491,9 @@ uifree(psc->pts_uidinfo); #ifdef PTS_EXTERNAL - /* Call shutdown hook. */ - if (psc->pts_external_free != NULL) - psc->pts_external_free(psc->pts_external_softc); + /* Destroy master device as well. */ + if (psc->pts_cdev != NULL) + destroy_dev_sched(psc->pts_cdev); #endif /* PTS_EXTERNAL */ free(psc, M_PTS); @@ -540,7 +552,7 @@ #ifdef PTS_EXTERNAL int pts_alloc_external(int fflags, struct thread *td, struct file *fp, - pts_external_free_t freefunc, void *softc, const char *name) + struct cdev *dev, const char *name) { int ok; struct tty *tp; @@ -561,8 +573,7 @@ cv_init(&psc->pts_outwait, "pts outwait"); psc->pts_unit = -1; - psc->pts_external_free = freefunc; - psc->pts_external_softc = softc; + psc->pts_cdev = dev; psc->pts_uidinfo = uid; uihold(uid); ==== //depot/projects/mpsafetty/sys/kern/tty_pty.c#8 (text+ko) ==== @@ -48,15 +48,6 @@ static int pty_warningcnt = 10; -static void -ptydev_free(void *softc) -{ - struct cdev *dev = softc; - - /* Remove the master device. */ - destroy_dev_sched(dev); -} - static int ptydev_fdopen(struct cdev *dev, int fflags, struct thread *td, struct file *fp) { @@ -71,8 +62,7 @@ name[3] = u >> 8; name[4] = u; - error = pts_alloc_external(fflags & (FREAD|FWRITE), td, fp, - ptydev_free, dev, name); + error = pts_alloc_external(fflags & (FREAD|FWRITE), td, fp, dev, name); if (error != 0) { destroy_dev_sched(dev); return (error); ==== //depot/projects/mpsafetty/sys/sys/tty.h#11 (text+ko) ==== @@ -186,9 +186,8 @@ void tty_info(struct tty *); /* Pseudo-terminal hooks. */ -typedef void pts_external_free_t(void *); int pts_alloc_external(int, struct thread *, struct file *, - pts_external_free_t, void *, const char *); + struct cdev *, const char *); /* Drivers and line disciplines also need to call these. */ #include <sys/ttydevsw.h>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200808181409.m7IE97BN051597>