提交 3e581d15 编写于 作者: L Luyao Huang 提交者: Jiri Denemark

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: NJiri Denemark <jdenemar@redhat.com>
上级 65a983ec
......@@ -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);
......
......@@ -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;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册