Skip to contentSkip to conversation

/proc/kmsg blocks with O_NONBLOCK, read() should return 0 with EAGAIN

DISCUSSION Graham Swallow 2 participants 2 messages Feb 23, 2004 – Feb 24, 2004 Proc filesystem

lore
Share & tools
lore
#0 lore raw

/proc/kmsg blocks with O_NONBLOCK, read() should return 0 with EAGAIN

	fd = open( "/proc/kmsg", O_RDONLY|O_NONBLOCK );
	...
	poll() -- says read it

	len = read(fd,buff,len); // first read is fine
	...
	len = read(fd,buff,len); // second read blocks

I call read() a second time, because I'm feeling lucky, (this is library code, which also reads from sockets).

I expected it to return 0 with errno==EAGAIN.
Instead it waits: do_syslog(2,buf,count);

I'm not on this list, so please raise a ticket, linux-2.4.23,

thanks
--
Graham
Information-Cascade (at) ntlworld.com

#1 lore raw
Quoted 11 lines · Graham Swallow

/proc/kmsg blocks with O_NONBLOCK, read() should return 0 with EAGAIN

	fd = open( "/proc/kmsg", O_RDONLY|O_NONBLOCK );
	...
	poll() -- says read it

	len = read(fd,buff,len); // first read is fine
	...
	len = read(fd,buff,len); // second read blocks
Quoted 6 lines

I call read() a second time, because I'm feeling lucky, (this is library code, which also reads from sockets).

I expected it to return 0 with errno==EAGAIN.
Instead it waits: do_syslog(2,buf,count);

Does this work?

fs/proc/kmsg.c renamed from fs/proc/kmsg.c~kmsg-nonblock +2 -0
diff -puN fs/proc/kmsg.c~kmsg-nonblock fs/proc/kmsg.c
@@ -32,6 +32,8 @@ static int kmsg_release(struct inode * i
 static ssize_t kmsg_read(struct file * file, char * buf,
 			 size_t count, loff_t *ppos)
 {
+	if ((file->f_flags & O_NONBLOCK) && !do_syslog(9, 0, 0))
+		return -EAGAIN;
 	return do_syslog(2,buf,count);
 }
 

_