[CRIU] [PATCH 2/2] test: thread_different_uid_gid -- Fixup sync points
Cyrill Gorcunov
gorcunov at openvz.org
Sat Oct 14 00:26:32 MSK 2017
Wait for thread to finish its creation instead of
calling sleep. Same time call for test_daemon
only when we're ready.
CC: Vitaly Ostrosablin <vostrosablin at virtuozzo.com>
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
test/zdtm/static/thread_different_uid_gid.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/test/zdtm/static/thread_different_uid_gid.c b/test/zdtm/static/thread_different_uid_gid.c
index 7964b6893702..1a6cdc976045 100644
--- a/test/zdtm/static/thread_different_uid_gid.c
+++ b/test/zdtm/static/thread_different_uid_gid.c
@@ -25,6 +25,7 @@ unsigned int gid;
unsigned int uid;
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+task_waiter_t t;
int done = 0;
@@ -70,6 +71,8 @@ void *chg_uid_gid(void *arg)
test_msg("Now aux thread runs as UID: %d; GID: %d\n", uid, gid);
test_msg("Child thread is waiting for main thread's signal\n");
+ task_waiter_complete(&t, 1);
+
pthread_mutex_lock(&mutex);
while (!done) {
pthread_cond_wait(&cond, &mutex);
@@ -89,15 +92,13 @@ int main(int argc, char **argv)
int ret;
test_init(argc, argv);
+ task_waiter_init(&t);
if (getuid() != 0) {
fail("Test is expected to be run with root privileges\n");
exit(1);
}
- test_daemon();
- test_msg("Test daemonized\n");
-
test_msg("Acquiring CAP_SETGID and CAP_SETUID...\n");
newcaps = cap_from_text("cap_setgid,cap_setuid=+eip");
@@ -124,8 +125,7 @@ int main(int argc, char **argv)
test_msg("Creating thread with different UID/GID\n");
ret = pthread_create(&diff_cred_thread, NULL, &chg_uid_gid, NULL);
-
- sleep(5);
+ task_waiter_wait4(&t, 1);
test_msg("Relinquishing root privileges\n");
ret = syscall(SYS_setresgid, maingroup, maingroup, maingroup);
@@ -142,6 +142,7 @@ int main(int argc, char **argv)
}
test_msg("Main thread is waiting for signal\n");
+ test_daemon();
test_waitsig();
if (gid == getgid() || uid == getuid()) {
--
2.7.5
More information about the CRIU
mailing list