]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fix a couple of issues with the tools file logger.
authorVMware, Inc <>
Wed, 24 Feb 2010 22:17:55 +0000 (14:17 -0800)
committerMarcelo Vanzin <mvanzin@vmware.com>
Wed, 24 Feb 2010 22:17:55 +0000 (14:17 -0800)
. if the log level is "none", the code optimizes things a little bit
and never sets the file path in the logger data. This was causing
an assert later on.
. while logging the assert, the log function was asserting that the
log file path was set, which caused a second assert because of the
same situation.

Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/libvmtools/fileLogger.c
open-vm-tools/libvmtools/vmtoolsLog.c

index cfa17ec4961abf401983b57fdb1ab247c3b71af6..f9d72194c7aea1ee1126bdd09fa80e7be39ee3b2 100644 (file)
@@ -115,30 +115,39 @@ VMFileLoggerLog(const gchar *domain,
                 LogHandlerData *_data,
                 LogErrorFn errfn)
 {
+   gboolean ret = FALSE;
    FileLoggerData *data = (FileLoggerData *) _data;
 
    if (data->error) {
-      return FALSE;
+      goto exit;
    }
 
    if (data->file == NULL) {
-      ASSERT(data->path != NULL);
-      data->file = VMFileLoggerOpen(data->path, data->append);
-      if (data->file == NULL) {
-         data->error = TRUE;
-         errfn(domain, G_LOG_LEVEL_WARNING | G_LOG_FLAG_RECURSION,
-               "Unable to open log file %s for domain %s.\n",
-               data->path, data->handler.domain);
-         return FALSE;
+      if (data->path == NULL) {
+         /* We should only get in this situation if the domain's log level is "none". */
+         ASSERT(data->handler.mask == 0);
+         errfn(domain, level, message);
+         ret = TRUE;
+         goto exit;
+      } else {
+         data->file = VMFileLoggerOpen(data->path, data->append);
+         if (data->file == NULL) {
+            data->error = TRUE;
+            errfn(domain, G_LOG_LEVEL_WARNING | G_LOG_FLAG_RECURSION,
+                  "Unable to open log file %s for domain %s.\n",
+                  data->path, data->handler.domain);
+            goto exit;
+         }
       }
    }
 
    if (fputs(message, data->file) >= 0) {
       fflush(data->file);
-      return TRUE;
+      ret = TRUE;
    }
 
-   return FALSE;
+exit:
+   return ret;
 }
 
 
@@ -162,11 +171,11 @@ VMFileLoggerCopy(LogHandlerData *_current,
    FileLoggerData *current = (FileLoggerData *) _current;
    FileLoggerData *old = (FileLoggerData *) _old;
 
-   ASSERT(old->path != NULL);
-   ASSERT(current->path != NULL);
    ASSERT(current->file == NULL);
-
-   if (old->file != NULL && strcmp(current->path, old->path) == 0) {
+   if (current->path != NULL &&
+       old->path != NULL &&
+       old->file != NULL &&
+       strcmp(current->path, old->path) == 0) {
       g_free(current->path);
       current->file = old->file;
       current->path = old->path;
@@ -281,6 +290,6 @@ VMFileLoggerConfig(const gchar *domain,
    data->append = (name != NULL && strcmp(name, "file+") == 0);
 
 exit:
-   return &data->handler;
+   return (data != NULL) ? &data->handler : NULL;
 }
 
index 12a964b86e600cb788228135975075180ef59713..b2a0b583ce1c5825bdbc6f53eb3a70837a5b785f 100644 (file)
@@ -608,7 +608,10 @@ VMToolsRestoreLogging(LogHandlerData *oldDefault,
       }
    }
 
-   if (gDefaultData != NULL && oldDefault != NULL && gDefaultData->copyfn != NULL) {
+   if (gDefaultData != NULL &&
+       oldDefault != NULL &&
+       gDefaultData->copyfn != NULL &&
+       gDefaultData->type == oldDefault->type) {
       gDefaultData->copyfn(gDefaultData, oldDefault);
    }