develooper Front page | perl.perl5.porters | Postings from September 2011

Re: [perl #98934] set{u,g}id doesn't clear $! on success

Thread Previous
From:
Zefram
Date:
September 13, 2011 04:02
Subject:
Re: [perl #98934] set{u,g}id doesn't clear $! on success
Message ID:
20110913110200.GF18211@lake.fysh.org
Chris Adams wrote:
>Setting a user/group ID by assigning to the perl special variables does
>not clear $!,

Yes, generally $! is not cleared by successful operations.  It is an exact
mirror for the C level errno.  You need an independent way to see whether
the operation succeeded, such as getting -1 from a syscall, and only
check $! on failure.  Unfortunately, assignment to magic variables doesn't
provide a way to report failure.  You've run into the edge of the model
here: this is where the magic variables stop behaving like variables.

I suggest that you use setgid() from the POSIX module.  Unfortunately it
seems not to have setegid() and friends; patches welcome.

-zefram

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About