mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
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:
parent
65a983eca1
commit
3e581d150a
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user