From: Michal Privoznik Date: Mon, 15 Apr 2019 11:45:38 +0000 (+0200) Subject: qemusecuritymock: Mock virProcessRunInFork X-Git-Tag: v5.6.0-rc1~371 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0a9dcfabf89d711d5e01f606f02d87b2ff9ceb95;p=thirdparty%2Flibvirt.git qemusecuritymock: Mock virProcessRunInFork This test is beautiful. It checks if we haven't messed up refcounting on security labels (well, XATTRs where the original owner is stored). It does this by setting up tracking of XATTR setting/removing into a hash table, then calling qemuSecuritySetAllLabel() followed by immediate qemuSecurityRestoreAllLabel() at which point, the hash table must be empty. The test so beautifully written that no matter what you do it won't fail. The reason is that all seclabel work is done in a child process. Therefore, the hash table in the parent is never changed and thus always empty. There are two reasons for forking (only one of them makes sense here though): 1) namespaces - when chown()-ing a file we have to fork() and make the child enter desired namespace, 2) locking - because of exclusive access to XATTRs we lock the files we chown() and this is done in a fork (see 207860927ad for more info). While we want to fork in real world, we don't want that in a test suite. Override virProcessRunInFork() then. Signed-off-by: Michal Privoznik Reviewed-by: Daniel P. Berrangé --- diff --git a/src/util/virprocess.h b/src/util/virprocess.h index d7d191ec75..003ba1edf4 100644 --- a/src/util/virprocess.h +++ b/src/util/virprocess.h @@ -107,7 +107,8 @@ typedef int (*virProcessForkCallback)(pid_t ppid, void *opaque); int virProcessRunInFork(virProcessForkCallback cb, - void *opaque); + void *opaque) + ATTRIBUTE_NOINLINE; int virProcessSetupPrivateMountNS(void); diff --git a/tests/qemusecuritymock.c b/tests/qemusecuritymock.c index 4edc5c44ad..d170e5da8f 100644 --- a/tests/qemusecuritymock.c +++ b/tests/qemusecuritymock.c @@ -416,3 +416,11 @@ int checkPaths(void) virMutexUnlock(&m); return ret; } + + +int +virProcessRunInFork(virProcessForkCallback cb, + void *opaque) +{ + return cb(-1, opaque); +}