skx has asked for the wisdom of the Perl Monks concerning the following question:
I've deployed a forking server which appears to be having problems on FreeBSD versions 3.2 and below.
This is my code:
use English; # Avoid $<, etc. my $username = "nobody"; my ($n,$p, $u,$g, $q,$c,$gc,$dir,$sh); ($n,$p, $u,$g, $q,$c,$gc,$dir,$sh)=getpwnam( $username ); # If we have a uid + gid switch to it. if ( defined( $u ) and defined( $g ) ) { # NOTE: Switch GID first - because once switching UID. # switching GID fails. # $GID = $g; $EGID= $g; $UID = $u; $EUID= $u; }
This setting of GID, EGID, UID, and EUID fails due to broken implementations of setruid() on this platform.
So my question? Is there a sane way to switch UID+GID that will work on FreeBSD in perl? Or a simple way to test for FreeBSD systems to avoid this breakage?
I know I could test $^O - but I'm not sure what a FreeBSD machine would produce.
I guess to detect the failure I can try reading back the values after the switch - but if it fails there's not a lot I can do.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem switching UID + GID under FreeBSD
by Abigail-II (Bishop) on Oct 29, 2003 at 16:12 UTC | |
|
Re: Problem switching UID + GID under FreeBSD
by sgifford (Prior) on Oct 29, 2003 at 19:36 UTC |