EAGAIN from Run is an os.PathError?

75 views
Skip to first unread message

W. Michael Petullo

unread,
Mar 28, 2020, 11:07:29 AM3/28/20
to golang-nuts
I am playing with Go and setrlimit(). Here is some code from a test that executes after setting RLIMIT_NPROC to 0:

err = exec.Command("true").Run()
if e, ok := err.(*os.PathError); !ok || e.Err.(unix.Errno) != unix.EAGAIN {
t.Error(err.Error())
}

/* Test succeeded: Run failed with EAGAIN as the process (thread) limit is exceeded. */

This seems to work, but I am surprised that Run() returns an os.PathError rather than an os.SyscallError. I would expect EAGAIN to be the latter.

Is this intentional? I guess I am looking for the reason for this so tha t my min d can more easily remember it.

Thank you!

--
Mike

:wq

Ian Lance Taylor

unread,
Mar 28, 2020, 3:25:27 PM3/28/20
to W. Michael Petullo, golang-nuts
Yes, it's intentional. For this case exec.Command.Run just returns
the error from os.StartProcess, which is documented to consistently
return an error of type *os.PathError. StartProcess returns
PathError so that it can return the name of the executable that was
not started.

It's true that in some cases it would be better to return
SyscallError, although that would require some work to keep track of
exactly which system call failed: it might easily be a system call
executed by the child process. But I'm not sure we can change it now,
given that it has worked this way for a long time and it is
documented.

Ian
Reply all
Reply to author
Forward
0 new messages