-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
std.posix: Added 'error.ProcessNotFound' where necessary #23268
base: master
Are you sure you want to change the base?
Conversation
I'm not really clear on the conditions under which we get |
(Let me preface this comment by saying, do whatever Alex says, and feel free to ignore me.) I think this PR correctly maps the errno code on read/write when operating on a Also since POSIX defines From what I can tell (in the Doing this mapping at I think Zig's posix layer can get away with specializing some errno from some syscalls. But I think it'll be hard to do that correctly from syscalls like My suggestion on this PR is that the |
I generally agree with that. As suggested, "process not found" could of course return "file not found." I'm completely unenthusiastic about this and just want to avoid further confusion, because at that point, you're working with "processes" and not with files. Not from a technical point of view (everything is a file), but from a logical point of view. Personally, I'd stick with "process," because when you're working with it, you think of PID as a process and not a file. |
(Again, I'm not a Zig team member, so my opinions may be ignored and I may be off-base.) The problem I'm trying to convince you about is that the Zig's My comments here are all about the pre-existing mappings of (**) The |
I was under the impression that |
Yes, and that hasn't changed. The error message returned by the Linux kernel varies depending on the combination of how a PID is accessed or can no longer be accessed because it no longer exists. We can now catch both possible error types and return them as 'process not found' in Zig, which logically is always the case. Or we can ignore the fact that it's accessing a process and simply write "file not found." I'm still in favor of option 1 and find option 2 clumsy because it's extremely confusing (as Linux often is, unfortunately). We have the option of outputting explanatory error messages, so why not use them? Addendum: The Linux manual pages also say, "The proc filesystem is a pseudo-filesystem...", so I find the error message "procress not found" much more meaningful than "file not found". |
I actually have a question: What a specific situation/example where |
…tencies. After extensive testing, the error messages for processes that are already open but no longer available for reading/writing have been adjusted to 'ProcessNotFound' if the error code ESRCH is thrown by the Linux kernel. Incorrect ENOENT error codes that also returned 'ProcessNotFound' have been removed.
To be honest, I don't remember. I had a test setup consisting of a C program and a Zig program, and I was getting corresponding error codes. Now I tried to recreate it, but to no avail. So I tested everything again from the beginning and only got ESRCH. I've now adjusted this PR accordingly. |
@@ -1565,6 +1566,7 @@ fn openDirFlagsZ(self: Dir, sub_path_c: [*:0]const u8, flags: posix.O) OpenError | |||
error.FileLocksNotSupported => unreachable, // locking folders is not supported | |||
error.WouldBlock => unreachable, // can't happen for directories | |||
error.FileBusy => unreachable, // can't happen for directories | |||
error.ProcessNotFound => unreachable, // can't happen for directories |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if I try to open /proc/12345
(as opposed to a file under it)? Or a subdirectory somewhere under /proc/12345/...
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you try const proc = try std.posix.open("/proc/29103", .{}, 0);
and the PID is unavailable, you get .NOENT => return error.FileNotFound,
.
However, if the PID was open correctly and the PID disapears, and you try const fd = try std.posix.openat(proc, "cpuset", .{}, 0);
, then you get .SRCH => return error.ProcessNotFound,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But then it sounds like this shouldn't be unreachable
unless I'm misunderstanding?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think unreachable
is the right choice here, because if the error is caught there, something else fundamentally wrong. Omitting it won't work; the compiler will complain about the dependencies. And the same goes for the other errors caught there with unreachable
. The idea wasn't mine; I just added it because it makes sense to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't follow; ProcessNotFound
is in OpenError
, which this function returns. Your example of const fd = try std.posix.openat(proc, "cpuset", .{}, 0);
where the process behind proc
disappeared in the meantime also seems like a completely reasonable scenario where the programmer couldn't have done anything to prevent it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that can be prevented. So the only option is to catch the error using catch
. I just don't quite understand what you're getting at.
LGTM! |
If you attempt to
read
(or other operations) from a process previously opened viaopenat
, but it has since terminated, the Linux kernel throws the errorESRCH - No such process
. This is now represented byerror.ProcessNotFound
.fixes #19875