Rust: ENOSPC should not always be described as 'no space left on device'

Created on 4 Nov 2020  路  4Comments  路  Source: rust-lang/rust

Context: https://github.com/notify-rs/notify/issues/266

man inotify_add_watch says:

       ENOSPC The  user  limit on the total number of inotify watches was reached or the kernel failed to allocate a needed
              resource.

The error the standard library gives for this is not very helpful for seeing what actually went wrong.

A-io C-bug O-linux T-libs

Most helpful comment

This is just an inherent limitation of libc and its limited number of error codes. If you wanted, you could use your own error type that has more specific messages for certain codes.

All 4 comments

Looks more like a libc bug than a rust library one? From what I see the standard library calls strerror_r:

https://github.com/rust-lang/rust/blob/95b4a4f0eee935f9e0c80b0ceef34866bcb72ca3/library/std/src/sys/unix/os.rs#L114-L132

This is just an inherent limitation of libc and its limited number of error codes. If you wanted, you could use your own error type that has more specific messages for certain codes.

A inotify_add_watch specific fix could be done around this place, inside the inotify crate: https://github.com/hannobraun/inotify/blob/f09e1bdbcbd479d3090257e47458a19be127e29f/src/inotify.rs#L200

E.g. call raw_os_error on it, check if it matches ENOSPC, if yes, return an error with a more suiting message.

But it's better to discuss that with the inotify maintainers I think.

I don't think there's anything the standard library can do about this, notify is going to fix it on their end.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nikomatsakis picture nikomatsakis  路  331Comments

thestinger picture thestinger  路  234Comments

withoutboats picture withoutboats  路  308Comments

nikomatsakis picture nikomatsakis  路  268Comments

cramertj picture cramertj  路  512Comments