Hacker News new | ask | show | jobs
by danobi 2292 days ago
What if openat() or read() fails? More generally, what if there's a chain of syscalls and you _want_ one of them to fail?
1 comments

With the "specific fd" approach, if openat fails, then read and close will harmlessly fail with EBADF ("Bad file descriptor"). Once you process the failure of openat, you'll just ignore the failure of read and close.
What will happen though, if the fd is already used by some other area of userspace? Like what if some lib you link to also happen to hardcore the use of the same fd. Sounds like unfunny problems to debug.

In the case of uring I suppose it is possible to link the calls to fail at the first failure.

> What will happen though, if the fd is already used by some other area of userspace?

That's what the min_fd patch is for, and potentially other systems for reserving blocks of fds. Much like memory, you'll ask the kernel for a block of it and then do your own allocations out of that.

Ah, it will be possible to allocate multiple blocks of file descriptors? Ok, then things start to make sense.