Skip to content

Commit

Permalink
Merge pull request #56 from eribertomota/025-update_fhs
Browse files Browse the repository at this point in the history
Update to FHS version 3
  • Loading branch information
oetiker committed Oct 19, 2021
2 parents f2690c8 + defda22 commit 84dee09
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
26 changes: 18 additions & 8 deletions src/bin/mrtg
Original file line number Diff line number Diff line change
Expand Up @@ -189,26 +189,29 @@ sub main {
die "$NOW: ERROR: Unknown User: $opts{user})\n" if not defined $uid;
}

# If we've specified using FHS (http://www.pathname.com/fhs/) on the command line,
# use the relevant path definitions (can be overridden later):
# If we've specified using FHS
# (https://refspecs.linuxfoundation.org/FHS_3.0/index.html) on the command
# line, use the relevant path definitions (can be overridden later):

my $confcachefile;
my $pidpath;
my $pidfile;
my $lockfile;
my $templock;
my $logfile;

if (defined $opts{"fhs"}) {
$confcachefile = "/var/cache/mrtg/mrtg.ok";
$pidfile = "/var/run/mrtg.pid";
$lockfile = "/var/cache/mrtg/mrtg.lck";
$templock = "/var/cache/mrtg/mrtg.lck.$$";
$logfile = "/var/log/mrtg.log";
$confcachefile = "/var/lib/mrtg/mrtg.ok";
$pidpath = "/run/mrtg";
$pidfile = "$pidpath/mrtg.pid";
$lockfile = "/var/lock/mrtg/mrtg.lck";
$templock = "/var/lock/mrtg/mrtg.lck.$$";
$logfile = "/var/log/mrtg/mrtg.log";
}

my $cfgfile = shift @ARGV;

if ( !defined $cfgfile and -r "/etc/mrtg.cfg" ) { $cfgfile = "/etc/mrtg.cfg"; }
if ( !defined $cfgfile and -r "/etc/mrtg/mrtg.cfg" ) { $cfgfile = "/etc/mrtg/mrtg.cfg"; }

printusage() unless defined $cfgfile;

Expand All @@ -220,6 +223,13 @@ sub main {
}
$pidfile = $opts{"pid-file"} || $pidfile;

if (defined $opts{"fhs"}) {
unless(-e $pidpath or mkdir ($pidpath, 0755)) {
die "Unable to create $pidpath\n";
}
chown $uid, $gid, $pidpath;
}

# Run as a daemon, specified on command line (required for FHS compliant daemon)
if (defined $opts{"daemon"}) {
# Create a pidfile, then chown it so we can use it once we change user
Expand Down
8 changes: 4 additions & 4 deletions src/doc/mrtg.pod
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ the config file option, but the switch is required for proper FHS operation
Configure all mrtg paths to conform to the FHS specification
L<http://www.pathname.com/fhs/>. The following default values are assumed:

confcachefile - /var/cache/mrtg/mrtg.ok
pid-file - /var/run/mrtg.pid
lock-file - /var/cache/mrtg/mrtg.lck
log-file - /var/log/mrtg.log
confcachefile - /var/lib/mrtg/mrtg.ok
pid-file - /run/mrtg/mrtg.pid
lock-file - /var/lock/mrtg/mrtg.lck
log-file - /var/log/mrtg/mrtg.log



Expand Down

0 comments on commit 84dee09

Please sign in to comment.