WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] Set close-on-exec flag on /var/log/xend.l

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] Set close-on-exec flag on /var/log/xend.log logging file.
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Tue, 15 Aug 2006 20:30:28 +0000
Delivery-date: Tue, 15 Aug 2006 13:34:18 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User kfraser@xxxxxxxxxxxxxxxxxxxxx
# Node ID 939f75570a15af51bb4173cb7fa945a86414431a
# Parent  5db6984e4503a6ddf2cb0db58c5af189d70f1f78
Set close-on-exec flag on /var/log/xend.log logging file.
Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 tools/python/xen/xend/XendLogging.py |   28 +++++++++++++++++++++++++---
 1 files changed, 25 insertions(+), 3 deletions(-)

diff -r 5db6984e4503 -r 939f75570a15 tools/python/xen/xend/XendLogging.py
--- a/tools/python/xen/xend/XendLogging.py      Tue Aug 15 16:26:39 2006 +0100
+++ b/tools/python/xen/xend/XendLogging.py      Tue Aug 15 16:27:26 2006 +0100
@@ -21,6 +21,7 @@ import types
 import types
 import logging
 import logging.handlers
+import fcntl
 
 from xen.xend.server import params
 
@@ -49,6 +50,27 @@ DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
 
 logfilename = None
 
+class XendRotatingFileHandler(logging.handlers.RotatingFileHandler):
+
+    def __init__(self, fname, mode, maxBytes, backupCount):
+        logging.handlers.RotatingFileHandler.__init__(self, fname, mode, 
maxBytes, backupCount)
+        self.setCloseOnExec()
+
+    def doRollover(self):
+        logging.handlers.RotatingFileHandler.doRollover()
+        self.setCloseOnExec()
+
+    # NB yes accessing 'self.stream' violates OO encapsulation somewhat,
+    # but python logging API gives no other way to access the file handle
+    # and the entire python logging stack is already full of OO encapsulation
+    # violations. The other alternative is copy-and-paste duplicating the
+    # entire FileHandler, StreamHandler & RotatingFileHandler classes which
+    # is even worse
+    def setCloseOnExec(self):
+        flags = fcntl.fcntl(self.stream.fileno(), fcntl.F_GETFD)
+        flags |= fcntl.FD_CLOEXEC
+        fcntl.fcntl(self.stream.fileno(), fcntl.F_SETFD, flags)
+        
 
 def init(filename, level):
     """Initialise logging.  Logs to the given filename, and logs to stderr if
@@ -58,9 +80,9 @@ def init(filename, level):
     global logfilename
 
     def openFileHandler(fname):
-        return logging.handlers.RotatingFileHandler(fname, mode = 'a',
-                                                    maxBytes = MAX_BYTES,
-                                                    backupCount = BACKUP_COUNT)
+        return XendRotatingFileHandler(fname, mode = 'a',
+                                       maxBytes = MAX_BYTES,
+                                       backupCount = BACKUP_COUNT)
 
     # Rather unintuitively, getLevelName will get the number corresponding to
     # a level name, as well as getting the name corresponding to a level

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] Set close-on-exec flag on /var/log/xend.log logging file., Xen patchbot-unstable <=