[Git][NTPsec/ntpsec][master] 2 commits: Adjusted log file behavior.

Ian Bruene gitlab at mg.gitlab.com
Fri Feb 16 19:52:41 UTC 2018


Ian Bruene pushed to branch master at NTPsec / ntpsec


Commits:
c3c8f24e by Ian Bruene at 2018-02-16T13:44:16-06:00
Adjusted log file behavior.

- - - - -
8d50caeb by Ian Bruene at 2018-02-16T13:51:41-06:00
Fixed commandline option error with logfile (Bug #456).

- - - - -


1 changed file:

- ntpclients/ntpsnmpd.py


Changes:

=====================================
ntpclients/ntpsnmpd.py
=====================================
--- a/ntpclients/ntpsnmpd.py
+++ b/ntpclients/ntpsnmpd.py
@@ -1462,7 +1462,10 @@ class PacketControl:
 
 def dolog(text, level):
     if debug >= level:
-        logfp.write(text)
+        try:
+            logfp.write(text)
+        except:
+            pass
 
 
 def connect(address):
@@ -1504,9 +1507,6 @@ def daemonize(runfunc, *runArgs):
 
     os.umask(0)
 
-    global logfp
-    logfp = open(logfile, "a", 1)
-
     sid = os.setsid()
 
     # chdir should be here, change to what? root?
@@ -1538,15 +1538,16 @@ if __name__ == "__main__":
     try:
         (options, arguments) = getopt.getopt(
             sys.argv[1:],
-            "nx:dD:Vhl",
-            ["no-fork", "master-address", "debug-level", "set-debug-level",
-             "version", "help", "logfile"])
+            "nx:dD:Vhl:",
+            ["no-fork", "master-address=", "debug-level", "set-debug-level=",
+             "version", "help", "logfile="])
     except getopt.GetoptError as e:
         sys.stderr.write("%s\n" % e)
         sys.stderr.write(usage)
         raise SystemExit(1)
 
     masterAddr = "/var/agentx/master"  # Default NET-SNMP configuration
+    fileLogging = False
     for (switch, val) in options:
         if switch in ("-n", "--no-fork"):
             # currently non functional, as nofork is inited to True
@@ -1570,6 +1571,10 @@ if __name__ == "__main__":
             print(usage)
             raise SystemExit(0)
         elif switch in ("-l", "--logfile"):
+            logfile = val
+            fileLogging = True
+
+        if fileLogging is True:
             if logfp != sys.stderr:
                 logfp.close()
             logfp = open(val, "a", 1)  # 1 => line buffered



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/125dab26c243028d858ae4e57a5ab5e7a0b331c1...8d50caeb41e2bbbf6d5c411a6bd47d16132908f0

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/125dab26c243028d858ae4e57a5ab5e7a0b331c1...8d50caeb41e2bbbf6d5c411a6bd47d16132908f0
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20180216/6fc4a3df/attachment.html>


More information about the vc mailing list