简体   繁体   中英

open file O_NONBLOCKING gets lost in kernel module

I am opening a file in my C program:

pcm->dfd = open(fname, O_RDONLY|O_NONBLOCK);

and later call select() and read() on it.

But my problem is, that the O_NONBLOCK gets lost somewere:

ssize_t my_read(struct file *filp, char __user *user_buffer, size_t bytes_requested, loff_t *capture_ptr) {

    if (filp->f_flags & O_NONBLOCK){
        LOGI("mode: O_NONBLOCK");
    }
    else{
        LOGI("mode: BLOCKING"); // <-- this is printed      
    }
    ..
}

I also tried

pcm->dfd=open(fname, O_RDONLY|O_NONBLOCK);

// O_NONBLOCK does not work :/
int flags = fcntl(pcm->dfd, F_GETFL, 0);
fcntl(pcm->dfd, F_SETFL, flags | O_NONBLOCK);

It's not a logging-problem, the driver also behaves as in blocking-mode.

Anyone an idea?

EDIT:

The code which reads from the opened file is absolutely simple:

size=read(pcm->dfd,inBuffer,inBufferBytes);

I also checked the program if there's a fcntl() somewere else, but no..

EDIT 2:

May it be possible, that the O_NONBLOCK has an other value in my user-program (Android NDK) than in the kernel? I searched for O_NONBLOCK in the kernel-headers and already there are 2 different definitions.

I also checked the open -implementation in my kernel module and already there filp->f_flags is not O_NONBLOCK .

According to open(2) man-page , passing O_NONBLOCK only makes the open call itself non-blocking (which you, probably, don't want). It does not imply, that the opened file descriptor will also be in non-blocking mode -- you have to set that with a fcntl() after opening.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM