~ubuntu-branches/ubuntu/quantal/openvswitch/quantal

« back to all changes in this revision

Viewing changes to debian/patches/bug-681880-2-ovsdb-Make-ovsdb-tool-create-work-through-a-dangling.patch

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-08-07 16:00:53 UTC
  • mfrom: (5.1.25 sid)
  • Revision ID: package-import@ubuntu.com-20120807160053-nj4pgmkn6bp8t4md
Tags: 1.4.2+git20120612-9ubuntu1
* Merge from Debian unstable; remaining changes:
  - d/control: Disable openvswitch-datapath-dkms package.
* Dropped changes:
  - d/patches/kernel_3.5_support.patch: Superceded by 
    bug-684057-ovs-ctl-Add-support-for-newer-module-name.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
5
 
 
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.
 
12
 
 
13
Debian bug #681880.
 
14
CC: 681880@bugs.debian.org
 
15
Reported-by: Bastian Blank <waldi@debian.org>
 
16
Signed-off-by: Ben Pfaff <blp@nicira.com>
 
17
---
 
18
 ovsdb/log.c |   13 +++++++++++--
 
19
 1 files changed, 11 insertions(+), 2 deletions(-)
 
20
 
 
21
diff --git a/ovsdb/log.c b/ovsdb/log.c
 
22
index ab4a150..9b882dc 100644
 
23
--- a/ovsdb/log.c
 
24
+++ b/ovsdb/log.c
 
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) {
 
27
         flags = O_RDWR;
 
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;
 
37
+        } else {
 
38
+            flags = O_RDWR | O_CREAT | O_EXCL;
 
39
+        }
 
40
     } else {
 
41
         NOT_REACHED();
 
42
     }
 
43
-- 
 
44
1.7.2.5
 
45