nx-match: Add functions for raw decoding and encoding of OXM.
[cascardo/ovs.git] / lib / vlog.c
index 18d0e33..28cea5d 100644 (file)
@@ -105,7 +105,7 @@ DEFINE_STATIC_PER_THREAD_DATA(unsigned int, msg_num, 0);
  * All of the following is protected by 'log_file_mutex', which nests inside
  * pattern_rwlock. */
 static struct ovs_mutex log_file_mutex = OVS_MUTEX_INITIALIZER;
-static char *log_file_name = NULL OVS_GUARDED_BY(log_file_mutex);
+static char *log_file_name OVS_GUARDED_BY(log_file_mutex) = NULL;
 static int log_fd OVS_GUARDED_BY(log_file_mutex) = -1;
 static struct async_append *log_writer OVS_GUARDED_BY(log_file_mutex);
 static bool log_async OVS_GUARDED_BY(log_file_mutex);
@@ -438,17 +438,23 @@ vlog_reopen_log_file(void)
 void
 vlog_change_owner_unix(uid_t user, gid_t group)
 {
-    if (!log_file_name) {
-        return;
-    }
+    struct ds err = DS_EMPTY_INITIALIZER;
+    int error;
 
     ovs_mutex_lock(&log_file_mutex);
-    int error = chown(log_file_name, user, group);
+    error = log_file_name ? chown(log_file_name, user, group) : 0;
+    if (error) {
+        /* Build the error message. We can not call VLOG_FATAL directly
+         * here because VLOG_FATAL() will try again to to acquire
+         * 'log_file_mutex' lock, causing deadlock.
+         */
+        ds_put_format(&err, "Failed to change %s ownership: %s.",
+                      log_file_name, ovs_strerror(errno));
+    }
     ovs_mutex_unlock(&log_file_mutex);
 
     if (error) {
-        VLOG_FATAL("Failed to change %s ownership: %s.",
-                   log_file_name, ovs_strerror(errno));
+        VLOG_FATAL("%s", ds_steal_cstr(&err));
     }
 }
 #endif