Package: mrtg
Severity: important
Tags: patch upstream
Control: forwarded -1 https://github.com/oetiker/mrtg/pull/56

MRTG needs an upgrade to FHS 3.0 in some points:

  - When using the option --fhs.
  - Creating directory /run/mrtg/ when running, if this directory is missing.
  - Moving the config file to /etc/mrtg/ to allow one to maintain several
    config files. (see #245357)

The attached patch solves these issues.

Regards,

Eriberto
Description: Update to FHS version 3 and create /run/mrtg/ if needed
    Rationale:
    .
    mrtg.ok is a library (a set of information) or, if you prefer, a
    "database". The best for it place is /var/lib/mrtg.
    .
    PID files must be moved from /var/run to /run.
    .
    lock files should be put in /var/lock.
    .
    The log file was moved to /var/log/mrtg/ to allow non-root users
    to create logs and to organize better the rotated logs.
    .
    The main config file was moved to /etc/mrtg/ to make ease the use
    of separate configuration files and to provide a central location
    for configuration.
Author: Joao Eriberto Mota Filho <eribe...@debian.org>
Forwarded: https://github.com/oetiker/mrtg/pull/56
Last-Update: 2021-10-18
Index: mrtg/bin/mrtg
===================================================================
--- mrtg.orig/bin/mrtg
+++ mrtg/bin/mrtg
@@ -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;
 
@@ -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
Index: mrtg/doc/mrtg.pod
===================================================================
--- mrtg.orig/doc/mrtg.pod
+++ mrtg/doc/mrtg.pod
@@ -169,10 +169,10 @@ the config file option, but the switch i
 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
  
 
 

Reply via email to