]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests: Do not ignore mode parameter in mocked open()
authorLuyao Huang <lhuang@redhat.com>
Mon, 25 Sep 2017 18:27:07 +0000 (20:27 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Wed, 4 Oct 2017 09:57:42 +0000 (11:57 +0200)
This is normally not an issue since the tests which use mocked open() do
not create files. But once coverage build is enabled, gcov_open will use
O_CREATE and real_open will read random data rather than the actual mode
argument.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
tests/virfilewrapper.c
tests/virusbmock.c

index fede7b2e89a8f63acfa71b4f3880985608d3abb0..1d1d1827086de3e6e5b8e30d0f6302cf1f5d2aa7 100644 (file)
@@ -257,10 +257,21 @@ int open(const char *path, int flags, ...)
 {
     int ret = -1;
     char *newpath = NULL;
+    va_list ap;
+    mode_t mode = 0;
 
     PATH_OVERRIDE(newpath, path);
 
-    ret = real_open(newpath, flags);
+    /* The mode argument is mandatory when O_CREAT is set in flags,
+     * otherwise the argument is ignored.
+     */
+    if (flags & O_CREAT) {
+        va_start(ap, flags);
+        mode = va_arg(ap, mode_t);
+        va_end(ap);
+    }
+
+    ret = real_open(newpath, flags, mode);
 
     VIR_FREE(newpath);
 
index 8d606649445d305db36e80810d0464a3fc4de104..f430a2edad6aab7b8c2e70fc4c22311d67529e76 100644 (file)
@@ -87,13 +87,26 @@ int open(const char *pathname, int flags, ...)
 {
     char *path;
     int ret;
+    va_list ap;
+    mode_t mode = 0;
 
     init_syms();
 
     path = get_fake_path(pathname);
     if (!path)
         return -1;
-    ret = realopen(path, flags);
+
+    /* The mode argument is mandatory when O_CREAT is set in flags,
+     * otherwise the argument is ignored.
+     */
+    if (flags & O_CREAT) {
+        va_start(ap, flags);
+        mode = va_arg(ap, mode_t);
+        va_end(ap);
+    }
+
+    ret = realopen(path, flags, mode);
+
     VIR_FREE(path);
     return ret;
 }