diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c index a4515ce29c8..3a5a3d5d16b 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c @@ -1440,10 +1440,26 @@ int main(int argc, char **argv) { exit(1); } - if (mkdirs(TEST_ROOT, 0777) != 0) { + // See the description above of various ways this test + // can be executed in order to understand the following logic + char* current_username = strdup(getpwuid(getuid())->pw_name); + if (getuid() == 0 && (argc == 2 || argc == 3)) { + username = argv[1]; + yarn_username = (argc == 3) ? argv[2] : argv[1]; + } else { + username = current_username; + yarn_username = (argc == 2) ? argv[1] : current_username; + } + struct passwd *username_info = check_user(username); + set_nm_uid(username_info->pw_uid, username_info->pw_gid); + if (set_user(username)) { exit(1); } - if (chmod(TEST_ROOT, 0777) != 0) { // in case of umask + + if (mkdirs(TEST_ROOT, 0755) != 0) { + exit(1); + } + if (chmod(TEST_ROOT, 0755) != 0) { // in case of umask exit(1); } @@ -1464,22 +1480,6 @@ int main(int argc, char **argv) { create_nm_roots(local_dirs); - // See the description above of various ways this test - // can be executed in order to understand the following logic - char* current_username = strdup(getpwuid(getuid())->pw_name); - if (getuid() == 0 && (argc == 2 || argc == 3)) { - username = argv[1]; - yarn_username = (argc == 3) ? argv[2] : argv[1]; - } else { - username = current_username; - yarn_username = (argc == 2) ? argv[1] : current_username; - } - set_nm_uid(geteuid(), getegid()); - - if (set_user(username)) { - exit(1); - } - printf("\nStarting tests\n"); printf("\ntest_is_empty()\n");