You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by jl...@apache.org on 2015/02/06 21:41:05 UTC

hadoop git commit: YARN-3089. LinuxContainerExecutor does not handle file arguments to deleteAsUser. Contributed by Eric Payne (cherry picked from commit 4c484320b430950ce195cfad433a97099e117bad)

Repository: hadoop
Updated Branches:
  refs/heads/branch-2 3ddafaa7c -> 83449a4e4


YARN-3089. LinuxContainerExecutor does not handle file arguments to deleteAsUser. Contributed by Eric Payne
(cherry picked from commit 4c484320b430950ce195cfad433a97099e117bad)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/83449a4e
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/83449a4e
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/83449a4e

Branch: refs/heads/branch-2
Commit: 83449a4e4d1e3d03ac782d36af8bee596f64fabe
Parents: 3ddafaa
Author: Jason Lowe <jl...@apache.org>
Authored: Fri Feb 6 20:39:01 2015 +0000
Committer: Jason Lowe <jl...@apache.org>
Committed: Fri Feb 6 20:40:33 2015 +0000

----------------------------------------------------------------------
 hadoop-yarn-project/CHANGES.txt                 |  3 +++
 .../impl/container-executor.c                   | 26 ++++++++++++++++----
 .../test/test-container-executor.c              | 21 ++++++++++++++++
 3 files changed, 45 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/83449a4e/hadoop-yarn-project/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt
index d3d4a91..3457c38 100644
--- a/hadoop-yarn-project/CHANGES.txt
+++ b/hadoop-yarn-project/CHANGES.txt
@@ -470,6 +470,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

http://git-wip-us.apache.org/repos/asf/hadoop/blob/83449a4e/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.c
----------------------------------------------------------------------
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 4fc78b6..314a05e 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) {

http://git-wip-us.apache.org/repos/asf/hadoop/blob/83449a4e/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c
----------------------------------------------------------------------
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 e9ac234..7f08e06 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");