Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENOSPC should not always be described as 'no space left on device' #78723

Closed
jyn514 opened this issue Nov 4, 2020 · 4 comments
Closed

ENOSPC should not always be described as 'no space left on device' #78723

jyn514 opened this issue Nov 4, 2020 · 4 comments
Labels
A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` C-bug Category: This is a bug. O-linux Operating system: Linux T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@jyn514
Copy link
Member

jyn514 commented Nov 4, 2020

Context: notify-rs/notify#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.

@jyn514 jyn514 added O-linux Operating system: Linux T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. C-bug Category: This is a bug. A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` labels Nov 4, 2020
@est31
Copy link
Member

est31 commented Nov 4, 2020

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

/// Gets a detailed string description for the given error number.
pub fn error_string(errno: i32) -> String {
extern "C" {
#[cfg_attr(any(target_os = "linux", target_env = "newlib"), link_name = "__xpg_strerror_r")]
fn strerror_r(errnum: c_int, buf: *mut c_char, buflen: libc::size_t) -> c_int;
}
let mut buf = [0 as c_char; TMPBUF_SZ];
let p = buf.as_mut_ptr();
unsafe {
if strerror_r(errno as c_int, p, buf.len()) < 0 {
panic!("strerror_r failure");
}
let p = p as *const _;
str::from_utf8(CStr::from_ptr(p).to_bytes()).unwrap().to_owned()
}
}

@sfackler
Copy link
Member

sfackler commented Nov 4, 2020

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.

@est31
Copy link
Member

est31 commented Nov 4, 2020

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.

@jyn514
Copy link
Member Author

jyn514 commented Nov 5, 2020

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

@jyn514 jyn514 closed this as completed Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` C-bug Category: This is a bug. O-linux Operating system: Linux T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants