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 p...@freebsd.org http://www.FreeBSD.org FreeBSD committer Am I Evil? Yes, I Am!
pgpwbxTvE99e9.pgp
Description: PGP signature