Date: Tue, 4 Aug 2009 23:04:57 +0200 From: Pawel Jakub Dawidek <pjd@FreeBSD.org> To: Maslan <maslanbsd@gmail.com> Cc: Dag-Erling =?iso-8859-1?Q?Sm=F8rgrav?= <des@des.no>, FreeBSD Hackers <freebsd-hackers@freebsd.org> Subject: Re: sosend() and mbuf Message-ID: <20090804210457.GF2181@garage.freebsd.pl> In-Reply-To: <319cceca0908031425r3516de29q34807cdf2c7489ed@mail.gmail.com> References: <319cceca0908030119i3432a495ya60aa431dab0e1b1@mail.gmail.com> <864ospvvkv.fsf@ds4.des.no> <319cceca0908031043x6bfe5771wa73553dce922756a@mail.gmail.com> <86eirs65gb.fsf@ds4.des.no> <319cceca0908031425r3516de29q34807cdf2c7489ed@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
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.
>
> kthread_create((void *)thread_main, NULL, NULL, RFNOWAIT, 0, "thread");
>
> void thread_main(){
> struct thread *td = curthread;
> int ret;
> int fd;
> ret = f_open("/path/to/file.txt", &fd);
> printf("%d\n", ret);
> tsleep(td, PDROP, "test tsleep", 10*hz);
> f_close(fd);
> kthread_exit(0);
> }
>
> int f_open(char *filename, int *fd){
> struct thread *td = curthread;
> int ret = kern_open(td, filename, UIO_SYSSPACE, O_RDONLY, FREAD);
> if(!ret){
> *fd = td->td_retval[0];
> return 1;
> }
> return 0;
> }
>
> 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?:)
--
Pawel Jakub Dawidek http://www.wheel.pl
pjd@FreeBSD.org http://www.FreeBSD.org
FreeBSD committer Am I Evil? Yes, I Am!
[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4 (FreeBSD)
iD8DBQFKeKJ5ForvXbEpPzQRAoEoAJsEUEFVHoo7LUjhPz1m04KB5LDuPgCg+J38
aVvIaYP47XokZiqx7Ry2iqA=
=8DQI
-----END PGP SIGNATURE-----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090804210457.GF2181>
