[libvirt] [PATCH 2/2] vircgroupmock: Mock access() to some more files
Eric Blake
eblake at redhat.com
Tue Oct 22 14:09:11 UTC 2013
On 10/22/2013 01:21 PM, Michal Privoznik wrote:
> Currently, if access(path, mode) is invoked, we check if @path has this
> special prefix SYSFS_PREFIX. If it does, we modify the path a bit and
> call realaccess. If it doesn't we act just like a wrapper and call
> realaccess directly. However, we are mocking fopen() as well. And as one
> can clearly see there, fopen("/proc/cgroups") will succeed. Hence, we
> have an error in our mocked access(): We need to check whether @path is
> not equal to /proc/cgroups as it may not exists on real system we're
> running however we definitely know how to fopen() it.
>
> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
> ---
> tests/vircgroupmock.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
Close.
>
> diff --git a/tests/vircgroupmock.c b/tests/vircgroupmock.c
> index adc1718..6d7083d 100644
> --- a/tests/vircgroupmock.c
> +++ b/tests/vircgroupmock.c
> @@ -498,6 +498,14 @@ int access(const char *path, int mode)
> }
> ret = realaccess(newpath, mode);
> free(newpath);
> + } else if (STREQ(path, "/proc/cgroups") ||
> + STREQ(path, "/proc/self/cgroup")) {
> + /* These files are readable for all. */
> + ret = (mode == F_OK || mode & R_OK) ? 0 : -1;
Our mock means the files are readable for all, but not writable for all.
I'd feel safer with:
ret = (mode == F_OK || mode == R_OK) ? 0 : -1;
so that we explicitly reject attempts to probe for other combinations
like 'mode == (R_OK|X_OK)'.
> + } else if (STREQ(path, "/proc/mounts")) {
> + /* This one is accessible anytime for anybody. In fact, it's just
> + * a symlink to /proc/self/mounts. */
> + ret = 0;
> } else {
> ret = realaccess(path, mode);
> }
>
ACK if that change still passes testing (but there may be fallout from
mocking non-writable, which in turn would require a v2).
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 621 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20131022/3c9badd2/attachment-0001.sig>
More information about the libvir-list
mailing list