From owner-freebsd-hackers@FreeBSD.ORG Tue Aug 4 21:37:30 2009 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 28F4E106570A for ; Tue, 4 Aug 2009 21:37:29 +0000 (UTC) (envelope-from pjd@garage.freebsd.pl) Received: from mail.garage.freebsd.pl (chello087206049004.chello.pl [87.206.49.4]) by mx1.freebsd.org (Postfix) with ESMTP id 2835E8FC12 for ; Tue, 4 Aug 2009 21:37:28 +0000 (UTC) (envelope-from pjd@garage.freebsd.pl) Received: by mail.garage.freebsd.pl (Postfix, from userid 65534) id 114B945B36; Tue, 4 Aug 2009 23:04:49 +0200 (CEST) Received: from localhost (chello087206049004.chello.pl [87.206.49.4]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.garage.freebsd.pl (Postfix) with ESMTP id 05C3945684; Tue, 4 Aug 2009 23:04:39 +0200 (CEST) Date: Tue, 4 Aug 2009 23:04:57 +0200 From: Pawel Jakub Dawidek To: Maslan Message-ID: <20090804210457.GF2181@garage.freebsd.pl> References: <319cceca0908030119i3432a495ya60aa431dab0e1b1@mail.gmail.com> <864ospvvkv.fsf@ds4.des.no> <319cceca0908031043x6bfe5771wa73553dce922756a@mail.gmail.com> <86eirs65gb.fsf@ds4.des.no> <319cceca0908031425r3516de29q34807cdf2c7489ed@mail.gmail.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="Zi0sgQQBxRFxMTsj" Content-Disposition: inline In-Reply-To: <319cceca0908031425r3516de29q34807cdf2c7489ed@mail.gmail.com> User-Agent: Mutt/1.4.2.3i X-PGP-Key-URL: http://people.freebsd.org/~pjd/pjd.asc X-OS: FreeBSD 8.0-CURRENT i386 X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on mail.garage.freebsd.pl X-Spam-Level: X-Spam-Status: No, score=-0.6 required=4.5 tests=BAYES_00,RCVD_IN_SORBS_DUL autolearn=no version=3.0.4 Cc: Dag-Erling =?iso-8859-1?Q?Sm=F8rgrav?= , FreeBSD Hackers Subject: Re: sosend() and mbuf X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Aug 2009 21:37:30 -0000 --Zi0sgQQBxRFxMTsj Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Aug 03, 2009 at 09:25:27PM +0000, Maslan wrote: > No my code doesn't work, I thought it may be because that soaccept() > -which is not found in man 9- is non-blocking, so i've to put my code > in a thread. > Now i got another problem, when I open a text file from this thread, > the kernel crashes, I'm sure that its the thread. >=20 > kthread_create((void *)thread_main, NULL, NULL, RFNOWAIT, 0, "thread"); >=20 > void thread_main(){ > struct thread *td =3D curthread; > int ret; > int fd; > ret =3D f_open("/path/to/file.txt", &fd); > printf("%d\n", ret); > tsleep(td, PDROP, "test tsleep", 10*hz); > f_close(fd); > kthread_exit(0); > } >=20 > int f_open(char *filename, int *fd){ > struct thread *td =3D curthread; > int ret =3D kern_open(td, filename, UIO_SYSSPACE, O_RDONLY, FREAD); > if(!ret){ > *fd =3D td->td_retval[0]; > return 1; > } > return 0; > } >=20 > I've to finish up this problem to go back for the first one. > Can you figure out what's wrong with this code, it works when I call > thread_main() rather than kthread_create((void *)thread_main, ..... When you did kern_open() without creating kernel thread, it worked, because kern_open() used file descriptor table from your current (userland) process. In FreeBSD 7.x kthread_create() creates a process without file descriptor table, so you can't use kern_open() and actually you shouldn't do this either. Take a look at sys/cddl/compat/opensolaris/kern/opensolaris_kobj.c, where you can find functions to do what you want. I guess you already considered doing all this in userland?:) --=20 Pawel Jakub Dawidek http://www.wheel.pl pjd@FreeBSD.org http://www.FreeBSD.org FreeBSD committer Am I Evil? Yes, I Am! --Zi0sgQQBxRFxMTsj Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.4 (FreeBSD) iD8DBQFKeKJ5ForvXbEpPzQRAoEoAJsEUEFVHoo7LUjhPz1m04KB5LDuPgCg+J38 aVvIaYP47XokZiqx7Ry2iqA= =8DQI -----END PGP SIGNATURE----- --Zi0sgQQBxRFxMTsj--