[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH] Fix openlog() ident usage



On Tue, Jan 20, 2009 at 11:14:03AM -0800, john levon sun com wrote:
> # HG changeset patch
> # User john levon sun com
> # Date 1232478815 28800
> # Node ID 37a6a671e38d7f4449d3b47bc5cf06c19362bc41
> # Parent  15bfba92a98744f8c554757ed608c3bf89fa38aa
> Fix openlog() ident usage
> 
> It cannot be freed, as it's used by reference in the syslog code, at
> least on Solaris.

  The requirement is apparently not present on Linux, sorry :-)

  I would prefer to keep the reference around and not leak it for
example on reloads

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel veillard com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/
Index: src/logging.c
===================================================================
RCS file: /data/cvs/libxen/src/logging.c,v
retrieving revision 1.6
diff -u -r1.6 logging.c
--- src/logging.c	15 Jan 2009 19:56:05 -0000	1.6
+++ src/logging.c	20 Jan 2009 19:33:28 -0000
@@ -626,14 +626,20 @@
     return(len);
 }
 
+static char *current_ident = NULL;
+
 static void virLogCloseSyslog(void *data ATTRIBUTE_UNUSED) {
+    VIR_FREE(current_ident);
     closelog();
 }
 
-static int virLogAddOutputToSyslog(int priority, const char *ident) {
+static int virLogAddOutputToSyslog(int priority, char *ident) {
+    VIR_FREE(current_ident);
     openlog(ident, 0, 0);
+    current_ident = ident; /* ident need to be kept around on Solaris */
     if (virLogDefineOutput(virLogOutputToSyslog, virLogCloseSyslog, NULL,
                            priority, 0) < 0) {
+        VIR_FREE(current_ident);
         closelog();
         return(-1);
     }
@@ -703,9 +709,12 @@
             name = strndup(str, cur - str);
             if (name == NULL)
                 return(-1);
+            /*
+             * name is consumed by virLogAddOutputToSyslog which
+             * keep the reference
+             * */
             if (virLogAddOutputToSyslog(prio, name) == 0)
                 ret++;
-            VIR_FREE(name);
 #endif /* HAVE_SYSLOG_H */
         } else if (STREQLEN(cur, "file", 4)) {
             cur += 4;

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]