From owner-freebsd-hackers Tue Apr 17 2: 5:59 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from Awfulhak.org (awfulhak.demon.co.uk [194.222.196.252]) by hub.freebsd.org (Postfix) with ESMTP id 3EF1037B424 for ; Tue, 17 Apr 2001 02:05:39 -0700 (PDT) (envelope-from brian@Awfulhak.org) Received: from hak.lan.Awfulhak.org (root@hak.lan.Awfulhak.org [172.16.0.12]) by Awfulhak.org (8.11.3/8.11.3) with ESMTP id f3H96Eb49816; Tue, 17 Apr 2001 10:06:14 +0100 (BST) (envelope-from brian@lan.Awfulhak.org) Received: from hak.lan.Awfulhak.org (brian@localhost [127.0.0.1]) by hak.lan.Awfulhak.org (8.11.3/8.11.3) with ESMTP id f3H95lr61736; Tue, 17 Apr 2001 10:05:47 +0100 (BST) (envelope-from brian@hak.lan.Awfulhak.org) Message-Id: <200104170905.f3H95lr61736@hak.lan.Awfulhak.org> X-Mailer: exmh version 2.3.1 01/18/2001 with nmh-1.0.4 To: Dima Dorfman Cc: hackers@FreeBSD.ORG, brian@Awfulhak.org Subject: Re: Patch to make snp(4) devfs-friendly In-Reply-To: Message from Dima Dorfman of "Tue, 17 Apr 2001 01:33:50 PDT." <20010417083350.5989F3E2F@bazooka.unixfreak.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Tue, 17 Apr 2001 10:05:47 +0100 From: Brian Somers Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG I haven't actually tested the code, but looking at the patch, I think there's a problem with it... Specifically, on a non-devfs system - where the device nodes are created with mknod(1), snp_clone() isn't going to be called before snpopen(). I've (ab)used drv2 as a flag to say whether make_dev() has been called in net/if_tun.c, but I'm not sure if this is the right answer either :*] > Attached is a patch to make the snp(4) driver play ball with DEVFS. > For better or for worse, I used the bpf(4) driver as a guide on how to > do this. > > If someone could review this, and, if nothing is wrong with it, commit > it, I'd appreciate it. > > Thanks in advance, > > Dima Dorfman > dima@unixfreak.org > > Index: tty_snoop.c > =================================================================== > RCS file: /st/src/FreeBSD/src/sys/kern/tty_snoop.c,v > retrieving revision 1.52 > diff -u -r1.52 tty_snoop.c > --- tty_snoop.c 2001/03/26 12:41:01 1.52 > +++ tty_snoop.c 2001/04/17 08:17:23 > @@ -286,12 +286,9 @@ > if ((error = suser(p)) != 0) > return (error); > > - if (dev->si_drv1 == NULL) { > - int mynor = minor(dev); > - > + if (dev->si_drv1 == NULL) > dev->si_drv1 = snp = malloc(sizeof(*snp), M_SNP, M_WAITOK|M_ZERO); > - make_dev(&snp_cdevsw, mynor, 0, 0, 0600, "snp%d", mynor); > - } else > + else > return (EBUSY); > > /* > @@ -365,6 +362,7 @@ > free(snp->snp_buf, M_SNP); > snp->snp_flags &= ~SNOOP_OPEN; > dev->si_drv1 = NULL; > + destroy_dev(dev); > > return (snp_detach(snp)); > } > @@ -505,10 +503,25 @@ > static void snp_drvinit __P((void *unused)); > > static void > +snp_clone(void *arg, char *name, int namelen, dev_t *dev) > +{ > + int u; > + > + if (*dev != NODEV) > + return; > + if (dev_stdclone(name, NULL, "snp", &u) != 1) > + return; > + *dev = make_dev(&snp_cdevsw, unit2minor(u), UID_ROOT, GID_WHEEL, 0600, > + "snp%d", u); > + return; > +} > + > +static void > snp_drvinit(unused) > void *unused; > { > > + EVENTHANDLER_REGISTER(dev_clone, snp_clone, 0, 1000); > cdevsw_add(&snp_cdevsw); > } > -- Brian Don't _EVER_ lose your sense of humour ! To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message