tests: Do not ignore mode parameter in mocked open()

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>
This commit is contained in:
Luyao Huang 2017-09-25 20:27:07 +02:00 committed by Jiri Denemark
parent 65a983eca1
commit 3e581d150a
2 changed files with 26 additions and 2 deletions

View 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);

View 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;
}