Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to FHS version 3 #56

Merged
merged 2 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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