Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 13 Dec 2008 21:17:47 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r186056 - in head/sys: dev/snp kern netgraph sys
Message-ID:  <200812132117.mBDLHlqw040014@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Sat Dec 13 21:17:46 2008
New Revision: 186056
URL: http://svn.freebsd.org/changeset/base/186056

Log:
  Change ttyhook_register() second argument from thread to process pointer.
  Thread was not really needed there, while previous ng_tty implementation
  that used thread pointer had locking issues (using sx while holding mutex).

Modified:
  head/sys/dev/snp/snp.c
  head/sys/kern/tty.c
  head/sys/netgraph/ng_tty.c
  head/sys/sys/ttyhook.h

Modified: head/sys/dev/snp/snp.c
==============================================================================
--- head/sys/dev/snp/snp.c	Sat Dec 13 20:53:57 2008	(r186055)
+++ head/sys/dev/snp/snp.c	Sat Dec 13 21:17:46 2008	(r186056)
@@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/malloc.h>
 #include <sys/module.h>
 #include <sys/poll.h>
+#include <sys/proc.h>
 #include <sys/snoop.h>
 #include <sys/sx.h>
 #include <sys/systm.h>
@@ -246,7 +247,7 @@ snp_ioctl(struct cdev *dev, u_long cmd, 
 			sx_xunlock(&snp_register_lock);
 			return (EBUSY);
 		}
-		error = ttyhook_register(&ss->snp_tty, td, *(int *)data,
+		error = ttyhook_register(&ss->snp_tty, td->td_proc, *(int *)data,
 		    &snp_hook, ss);
 		sx_xunlock(&snp_register_lock);
 		if (error != 0)

Modified: head/sys/kern/tty.c
==============================================================================
--- head/sys/kern/tty.c	Sat Dec 13 20:53:57 2008	(r186055)
+++ head/sys/kern/tty.c	Sat Dec 13 21:17:46 2008	(r186056)
@@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/cons.h>
 #include <sys/fcntl.h>
 #include <sys/file.h>
+#include <sys/filedesc.h>
 #include <sys/filio.h>
 #ifdef COMPAT_43TTY
 #include <sys/ioctl_compat.h>
@@ -1673,18 +1674,24 @@ ttyhook_defrint(struct tty *tp, char c, 
 }
 
 int
-ttyhook_register(struct tty **rtp, struct thread *td, int fd,
+ttyhook_register(struct tty **rtp, struct proc *p, int fd,
     struct ttyhook *th, void *softc)
 {
 	struct tty *tp;
 	struct file *fp;
 	struct cdev *dev;
 	struct cdevsw *cdp;
+	struct filedesc *fdp;
 	int error;
 
 	/* Validate the file descriptor. */
-	if (fget(td, fd, &fp) != 0)
-		return (EINVAL);
+	if ((fdp = p->p_fd) == NULL)
+		return (EBADF);
+	FILEDESC_SLOCK(fdp);
+	if ((fp = fget_locked(fdp, fd)) == NULL || fp->f_ops == &badfileops) {
+		FILEDESC_SUNLOCK(fdp);
+		return (EBADF);
+	}
 	
 	/* Make sure the vnode is bound to a character device. */
 	error = EINVAL;
@@ -1723,7 +1730,7 @@ ttyhook_register(struct tty **rtp, struc
 
 done3:	tty_unlock(tp);
 done2:	dev_relthread(dev);
-done1:	fdrop(fp, td);
+done1:	FILEDESC_SUNLOCK(fdp);
 	return (error);
 }
 

Modified: head/sys/netgraph/ng_tty.c
==============================================================================
--- head/sys/netgraph/ng_tty.c	Sat Dec 13 20:53:57 2008	(r186055)
+++ head/sys/netgraph/ng_tty.c	Sat Dec 13 21:17:46 2008	(r186056)
@@ -252,7 +252,6 @@ static int
 ngt_rcvmsg(node_p node, item_p item, hook_p lasthook)
 {
 	struct proc *p;
-	struct thread *td;
 	const sc_p sc = NG_NODE_PRIVATE(node);
 	struct ng_mesg *msg, *resp = NULL;
 	int error = 0;
@@ -266,12 +265,13 @@ ngt_rcvmsg(node_p node, item_p item, hoo
 				return (EBUSY);
 			
 			p = pfind(((int *)msg->data)[0]);
-			if (p == NULL)
+			if (p == NULL || (p->p_flag & P_WEXIT))
 				return (ESRCH);
-			td = FIRST_THREAD_IN_PROC(p);
-			error = ttyhook_register(&sc->tp, td, ((int *)msg->data)[1],
-			    &ngt_hook, sc);
+			_PHOLD(p);
 			PROC_UNLOCK(p);
+			error = ttyhook_register(&sc->tp, p, ((int *)msg->data)[1],
+			    &ngt_hook, sc);
+			PRELE(p);
 			if (error != 0)
 				return (error);
 			break;

Modified: head/sys/sys/ttyhook.h
==============================================================================
--- head/sys/sys/ttyhook.h	Sat Dec 13 20:53:57 2008	(r186055)
+++ head/sys/sys/ttyhook.h	Sat Dec 13 21:17:46 2008	(r186056)
@@ -66,7 +66,7 @@ struct ttyhook {
 	th_close_t		*th_close;
 };
 
-int	ttyhook_register(struct tty **, struct thread *, int,
+int	ttyhook_register(struct tty **, struct proc *, int,
     struct ttyhook *, void *);
 void	ttyhook_unregister(struct tty *);
 #define	ttyhook_softc(tp)		((tp)->t_hooksoftc)



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