The old EPERM
is still in errno
from the previous call. Successful system calls do not set errno
to 0; you have to do that yourself.
Usually, you don't need to set errno
to 0. You check the return value of the system call, and then if that indicates failure, you check errno
for more details. errno doesn't tell you that something failed - it tells you how something failed.
There's an exception to this general rule for functions with no distinct error indicator in their return value, like strtoul
, but seteuid
isn't one of those. It has a clean return value. If it returns 0, you shouldn't print an error message at all.
And relying on strerror(0)
to produce a "success message" isn't clean either - in current glibc it says "Success"
but I can still remember when strerror(0)
was "Unknown error 0"
. Maybe somewhere it still is.