1
From 11d1cec1eeece689122022758b67396f875f901b Mon Sep 17 00:00:00 2001
2
From: Ben Pfaff <blp@nicira.com>
3
Date: Thu, 26 Jul 2012 14:42:58 -0700
4
Subject: [PATCH 2/3] ovsdb: Make "ovsdb-tool create" work through a dangling symlink.
6
open() with O_CREAT|O_EXCL yields EEXIST if the name passed in is a
7
symlink, but we would like "ovsdb-tool create /etc/openvswitch/conf.db" to
8
work if /etc/openvswitch/conf.db is a symlink to elsewhere in the file
9
system. This commit fixes the problem. It introduces a theoretical race,
10
but no one should be doing "ovsdb-tool create" in parallel anyhow; O_EXCL
11
is just an idiot check here, not required to be fail-safe.
14
CC: 681880@bugs.debian.org
15
Reported-by: Bastian Blank <waldi@debian.org>
16
Signed-off-by: Ben Pfaff <blp@nicira.com>
18
ovsdb/log.c | 13 +++++++++++--
19
1 files changed, 11 insertions(+), 2 deletions(-)
21
diff --git a/ovsdb/log.c b/ovsdb/log.c
22
index ab4a150..9b882dc 100644
25
@@ -95,7 +95,16 @@ ovsdb_log_open(const char *name, enum ovsdb_log_open_mode open_mode,
26
} else if (open_mode == OVSDB_LOG_READ_WRITE) {
28
} else if (open_mode == OVSDB_LOG_CREATE) {
29
- flags = O_RDWR | O_CREAT | O_EXCL;
30
+ if (stat(name, &s) == -1 && errno == ENOENT
31
+ && lstat(name, &s) == 0 && S_ISLNK(s.st_mode)) {
32
+ /* 'name' is a dangling symlink. We want to create the file that
33
+ * the symlink points to, but POSIX says that open() with O_EXCL
34
+ * must fail with EEXIST if the named file is a symlink. So, we
35
+ * have to leave off O_EXCL and accept the race. */
36
+ flags = O_RDWR | O_CREAT;
38
+ flags = O_RDWR | O_CREAT | O_EXCL;