+ struct stat old_stat;
+ struct stat new_stat;
+ int new_log_fd;
+ bool same_file;
+ bool log_close;
+
+ /* Open new log file. */
+ new_log_file_name = (file_name
+ ? xstrdup(file_name)
+ : xasprintf("%s/%s.log", ovs_logdir(), program_name));
+ new_log_fd = open(new_log_file_name, O_WRONLY | O_CREAT | O_APPEND, 0666);
+ if (new_log_fd < 0) {
+ VLOG_WARN("failed to open %s for logging: %s",
+ new_log_file_name, ovs_strerror(errno));
+ free(new_log_file_name);
+ return errno;
+ }
+
+ /* If the new log file is the same one we already have open, bail out. */
+ ovs_mutex_lock(&log_file_mutex);
+ same_file = (log_fd >= 0
+ && new_log_fd >= 0
+ && !fstat(log_fd, &old_stat)
+ && !fstat(new_log_fd, &new_stat)
+ && old_stat.st_dev == new_stat.st_dev
+ && old_stat.st_ino == new_stat.st_ino);
+ ovs_mutex_unlock(&log_file_mutex);
+ if (same_file) {
+ close(new_log_fd);
+ free(new_log_file_name);
+ return 0;
+ }