Commit eff4c2ac authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Andrei Vagin

test: thread_different_uid_gid -- Fixup sync points

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@virtuozzo.com>
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent bd561153
...@@ -25,6 +25,7 @@ unsigned int gid; ...@@ -25,6 +25,7 @@ unsigned int gid;
unsigned int uid; unsigned int uid;
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond = PTHREAD_COND_INITIALIZER; pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
task_waiter_t t;
int done = 0; int done = 0;
...@@ -70,6 +71,8 @@ void *chg_uid_gid(void *arg) ...@@ -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("Now aux thread runs as UID: %d; GID: %d\n", uid, gid);
test_msg("Child thread is waiting for main thread's signal\n"); test_msg("Child thread is waiting for main thread's signal\n");
task_waiter_complete(&t, 1);
pthread_mutex_lock(&mutex); pthread_mutex_lock(&mutex);
while (!done) { while (!done) {
pthread_cond_wait(&cond, &mutex); pthread_cond_wait(&cond, &mutex);
...@@ -89,15 +92,13 @@ int main(int argc, char **argv) ...@@ -89,15 +92,13 @@ int main(int argc, char **argv)
int ret; int ret;
test_init(argc, argv); test_init(argc, argv);
task_waiter_init(&t);
if (getuid() != 0) { if (getuid() != 0) {
fail("Test is expected to be run with root privileges\n"); fail("Test is expected to be run with root privileges\n");
exit(1); exit(1);
} }
test_daemon();
test_msg("Test daemonized\n");
test_msg("Acquiring CAP_SETGID and CAP_SETUID...\n"); test_msg("Acquiring CAP_SETGID and CAP_SETUID...\n");
newcaps = cap_from_text("cap_setgid,cap_setuid=+eip"); newcaps = cap_from_text("cap_setgid,cap_setuid=+eip");
...@@ -124,8 +125,7 @@ int main(int argc, char **argv) ...@@ -124,8 +125,7 @@ int main(int argc, char **argv)
test_msg("Creating thread with different UID/GID\n"); test_msg("Creating thread with different UID/GID\n");
ret = pthread_create(&diff_cred_thread, NULL, &chg_uid_gid, NULL); ret = pthread_create(&diff_cred_thread, NULL, &chg_uid_gid, NULL);
task_waiter_wait4(&t, 1);
sleep(5);
test_msg("Relinquishing root privileges\n"); test_msg("Relinquishing root privileges\n");
ret = syscall(SYS_setresgid, maingroup, maingroup, maingroup); ret = syscall(SYS_setresgid, maingroup, maingroup, maingroup);
...@@ -142,6 +142,7 @@ int main(int argc, char **argv) ...@@ -142,6 +142,7 @@ int main(int argc, char **argv)
} }
test_msg("Main thread is waiting for signal\n"); test_msg("Main thread is waiting for signal\n");
test_daemon();
test_waitsig(); test_waitsig();
if (gid == getgid() || uid == getuid()) { if (gid == getgid() || uid == getuid()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment