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

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

Thread Previous | Thread Next
Paul Johnson
September 13, 2011 16:34
Re: [perl #98934] set{u,g}id doesn't clear $! on success
Message ID:
On Tue, Sep 13, 2011 at 02:30:27PM +0200, Leon Timmermans wrote:
> On Mon, Sep 12, 2011 at 9:50 PM, Chris Adams <> wrote:
> > This is highly confusing, and there's really no reason to push this off
> > on the people writing perl code.  At a minimum, perl internally could do
> > something like:
> >
> >    if (setregid(gid,-1) == 0)
> >        errno = 0;
> >
> > (and that goes for all the setuid/setgid family of functions).
> That might piss off an equal number of users because $! gets
> overwritten when they didn't expect it.

The problem in perl is that $! is intimately bound to errno, and you have
no business doing anything with errno except examining it immediately
after a failed system call.  IIRC, on some systems you cannot assign to
errno anyway since it can be implemented as a macro expanding to a

However, this is not to say that $! needs to remain so intimately bound to
errno.  It's easy to make an argument that $! should reflect the return
status of the Perl function call, and not retain the C semantics as Jan
described.  It's somewhat less easy to argue against that.

If we do make such a change then it might also be worth considering the
option of throwing exceptions on failure too.

Paul Johnson -

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About