fixed to check if setgid() and setuid() functions were successful

This commit is contained in:
Jordi Sanfeliu 2018-03-05 16:19:19 +01:00
parent 8b18d23e60
commit 7b1cc6c8e9
1 changed files with 9 additions and 1 deletions

View File

@ -23,7 +23,7 @@ package Monitorix;
use strict;
use warnings;
use Exporter 'import';
use POSIX qw(setuid setgid setsid);
use POSIX qw(setuid setgid setsid getgid getuid);
use Socket;
our @EXPORT = qw(logger trim min max celsius_to uptime2str setup_riglim httpd_setup get_nvidia_data get_ati_data flush_accounting_rules);
@ -135,7 +135,15 @@ sub httpd_setup {
chown($uid, $gid, $config->{httpd_builtin}->{log_file});
setgid($gid);
if(getgid() != $gid) {
logger("WARNING: $myself: unable to setgid($gid).");
exit(1);
}
setuid($uid);
if(getuid() != $uid) {
logger("WARNING: $myself: unable to setuid($uid).");
exit(1);
}
setsid();
$SIG{$_} = 'DEFAULT' for keys %SIG; # reset all sighandlers
$0 = "monitorix-httpd listening on $port"; # change process' name