Open file in kthread on behalf of a user process
I am writing a linux kernel module which would start a kthread when a user process calls to it (using ioctl).
How can i open a file using this kthread on bahalf o开发者_Go百科f user process, that is, when it returns the user process can access this file itself!?
It's not really sensible to do this. To open a file that the userspace process can read, you need to return a file descriptor to that process.
Potentially you could return a UNIX-domain socketpair connecting the kernel thread to the userspace thread, and have the kernel thread pass open file descriptors across that socket using a SCM_RIGHTS
message.
It is likely to be more appropriate, however, to simply open the file in the context of the original process in the ioctl()
call and return the file descriptor there.
精彩评论