]> git.ipfire.org Git - thirdparty/libvirt.git/commit
vircgroupmock: Be wiser about detecting fakerootdir change
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 3 Mar 2022 14:42:17 +0000 (15:42 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 4 Mar 2022 14:08:59 +0000 (15:08 +0100)
commit61a12ffe0823444de9eb821c9618aaa8d1bff394
tree7e2f9f96126f0e597582c3b348b6651542adaaee
parent20f1db2467d45a286b9166ce2098cd89120f0dcd
vircgroupmock: Be wiser about detecting fakerootdir change

The way that vircgroupmock works is that the vircgrouptest
creates a temporary directory and sets LIBVIRT_FAKE_ROOT_DIR env
variable which is then checked by the mock at the beginning of
basically every function it overrides (access(), stat in all its
flavours, mkdir(), etc.). The mock then creates a CGroup dir
structure. But the test is allowed to change the directory, to
accommodate environment for the particular test case. This is
done by changing the environment variable which is then detected
by the mock and the whole process repeats.

However, the way the mock detect changes is buggy. After it got
the environment variable it compares it to the last known value
(global variable @fakerootdir) and if they don't match the last
known value is set to point to the new value. Problem is that the
result of getenv() is assigned to the @fakerootdir directly.
Therefore, @fakerootdir points somewhere into the buffer of
environment variables. In turn, when the test sets new value (via
g_setenv()) it may be placed at the very same position in the env
var buffer and thus the mock fails to detect the change.

The solution is to keep our private copy of the value (by
g_strdup()) which makes the variable not rely on
getenv()/setenv() placing values at random positions.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tests/vircgroupmock.c