[fpc-pascal] [SYSTEM]: How detecting if run as root ?

Pete Cervasio cervasio at airmail.net
Thu Oct 12 03:35:42 CEST 2006


On Wednesday 11 October 2006 19:37, Andrew Haines wrote:
> TOUZEAU DAVID wrote:
> > Dear
> >
> > I need to detect if the program is executed as root privileges on Linux
> > system.
> > Did somebody had developped a such function ??
> >
> > Best regards.
>
> Well you can try GetEnv('USER') = 'root'; or GetEnv('UID') = '0'; but
> there may be better ways to check this.

The better way would be to use the geteuid function in the libc unit, because 
the environment variables may not be set (such as if they were explictly 
unset or if the program is run from cron or the system startup scripts).  

See the getuid/geteuid man page for particulars.  And no, I am not saying 
"RTFMP" spitefully.  :) :)

Best regards,
Pete C.



More information about the fpc-pascal mailing list