diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index 2220c2a23e..51ed31f4a8 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -504,6 +504,9 @@ Release 2.7.0 - UNRELEASED YARN-2694. Ensure only single node label specified in ResourceRequest. (Wangda Tan via jianhe) + YARN-3089. LinuxContainerExecutor does not handle file arguments to + deleteAsUser (Eric Payne via jlowe) + Release 2.6.0 - 2014-11-18 INCOMPATIBLE CHANGES diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.c b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.c index f73776e422..04d02326fe 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.c +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.c @@ -1354,21 +1354,37 @@ int delete_as_user(const char *user, const char *subdir, char* const* baseDirs) { int ret = 0; - + int subDirEmptyStr = (subdir == NULL || subdir[0] == 0); + int needs_tt_user = subDirEmptyStr; char** ptr; // TODO: No switching user? !!!! if (baseDirs == NULL || *baseDirs == NULL) { - return delete_path(subdir, strlen(subdir) == 0); + return delete_path(subdir, needs_tt_user); } // do the delete for(ptr = (char**)baseDirs; *ptr != NULL; ++ptr) { - char* full_path = concatenate("%s/%s", "user subdir", 2, - *ptr, subdir); + char* full_path = NULL; + struct stat sb; + if (stat(*ptr, &sb) != 0) { + fprintf(LOGFILE, "Could not stat %s\n", *ptr); + return -1; + } + if (!S_ISDIR(sb.st_mode)) { + if (!subDirEmptyStr) { + fprintf(LOGFILE, "baseDir \"%s\" is a file and cannot contain subdir \"%s\".\n", *ptr, subdir); + return -1; + } + full_path = strdup(*ptr); + needs_tt_user = 0; + } else { + full_path = concatenate("%s/%s", "user subdir", 2, *ptr, subdir); + } + if (full_path == NULL) { return -1; } - int this_ret = delete_path(full_path, strlen(subdir) == 0); + int this_ret = delete_path(full_path, needs_tt_user); free(full_path); // delete as much as we can, but remember the error if (this_ret != 0) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c index e9ac2342d1..7f08e069ab 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c @@ -382,7 +382,28 @@ void test_delete_user() { if (mkdirs(app_dir, 0700) != 0) { exit(1); } + char buffer[100000]; + sprintf(buffer, "%s/test.cfg", app_dir); + if (write_config_file(buffer) != 0) { + exit(1); + } + + char * dirs[] = {buffer, 0}; + int ret = delete_as_user(yarn_username, "file1" , dirs); + if (ret == 0) { + printf("FAIL: if baseDir is a file, delete_as_user should fail if a subdir is also passed\n"); + exit(1); + } + + // Pass a file to delete_as_user in the baseDirs parameter. The file should + // be deleted. + ret = delete_as_user(yarn_username, "" , dirs); + if (ret != 0) { + printf("FAIL: delete_as_user could not delete baseDir when baseDir is a file: return code is %d\n", ret); + exit(1); + } + sprintf(buffer, "%s/local-1/usercache/%s", TEST_ROOT, yarn_username); if (access(buffer, R_OK) != 0) { printf("FAIL: directory missing before test\n");