bugThe GNU Hurd - Bugs: bug #48371, read(fd, NULL, 0) from /dev/klog...


bug #48371: read(fd, NULL, 0) from /dev/klog blocks until there is data

Submitter:  Kalle Olavi Niemitalo <kon>
Submitted:  Fri 01 Jul 2016 09:47:46 PM UTC
Category:  Hurd Servers Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Standard Compliance
Status:  None Privacy:  Public
Assigned to:  None Originator Name: 
Open/Closed:  Open Reproducibility:  None
Size (loc):  None Planned Release:  None
Effort:  0.00
Wiki-like text discussion box: 

For such a two-lines patch, the changes are not copyrightable, so there is no need for a copyright assignment.

* Mandatory Fields

Add a New Comment Rich Markup

Thu 07 Jul 2016 08:05:51 PM UTC, comment #3: 

I patched trans/streamio.c (trivfs_S_io_read) so that, if amount == 0, it returns success without blocking.  I didn't change dev_read because it's called only from trivfs_S_io_read and I thought it'd be better to avoid locking global_lock in this case.  After installing this change and rebooting, I then ran as root

rpctrace perl -e 'sysread STDIN, $_, 0' < /dev/klog

and it didn't hang.  I also ran "cat /dev/klog", which correctly output the "unexpected RESEND from keyboard" message from gnumach when I used a key combination to defocus the virtualbox window.  I did not retest /dev/klog support in rsyslog.

As discussed on #hurd, I don't intend to post the patch itself.

Kalle Olavi Niemitalo <kon>
Mon 04 Jul 2016 08:47:49 PM UTC, comment #2: 

I agree it should be done in dev_read. The RPC documentation doesn't
seem to say what should be done with 0-bytes requests, I'd tend to
think aligning with POSIX should be fine.

Could you test and propose a patch?

Samuel Thibault <sthibaul>
Group administrator
Fri 01 Jul 2016 10:01:35 PM UTC, comment #1: 

I wrote "storeio gets to the dev_read function" but I really meant streamio.

Kalle Olavi Niemitalo <kon>
Fri 01 Jul 2016 09:47:46 PM UTC, original submission:  

I patched rsyslog 8.16.0 to make it use /dev/klog on the Hurd.  (Set os_type="bsd" in configure.ac.)  It opened /dev/klog all right but then hung waiting for input.  rpctrace showed that it was calling read with size=0.  This call is in plugins/imklog/bsd.c (klogWillRunPostPrivDrop).  I removed the call and rsyslog then started quickly.

The translator of /dev/klog is "/hurd/streamio kmsg".  I assume storeio gets to the dev_read function, which then waits for input from the kernel, without noticing that the requested size is 0.

According to antrik, POSIX specifies that read with nbyte==0 must immediately return 0 or return an error.  This could be implemented in libc, libtrivfs, or streamio.  It seems best to implement this in streamio so that translators can still return EBADF if the file was not opened for reading.

Kalle Olavi Niemitalo <kon>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

Attached Files
file #37764:  0001-streamio-read-fd-buf-0-must-not-block.patch added by kon (1KiB - text/x-patch - Includes the prominent notice as per GPLv2 subsection 2a.)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by sthibaul (Posted a comment)
  • -email is unavailable- added by kon (Submitted the item)

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.


    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-07-07 kon Attached File- Added 0001-streamio-read-fd-buf-0-must-not-block.patch, #37764
    2016-07-07 sthibaul Wiki-like text discussion box For such a two-lines patch, the changes are not copyrightable, so there is no need for a copyright assignment.

    Back to the top

    Powered by Savane 3.12.
    Corresponding source code