Author: llu
Date: Tue Jul 26 23:15:32 2011
New Revision: 1151287

URL: http://svn.apache.org/viewvc?rev=1151287&view=rev
Log:
MAPREDUCE-2651. Fix race condition in Linux task controller for job log 
directory creation. (Bharath Mundlapudi via llu)

Modified:
    hadoop/common/branches/branch-0.20-security/CHANGES.txt
    
hadoop/common/branches/branch-0.20-security/src/c++/task-controller/impl/task-controller.c

Modified: hadoop/common/branches/branch-0.20-security/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security/CHANGES.txt?rev=1151287&r1=1151286&r2=1151287&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security/CHANGES.txt (original)
+++ hadoop/common/branches/branch-0.20-security/CHANGES.txt Tue Jul 26 23:15:32 
2011
@@ -6,6 +6,9 @@ Release 0.20.205.0 - unreleased
 
   BUG FIXES
 
+    MAPREDUCE-2651. Fix race condition in Linux task controller for
+    job log directory creation. (Bharath Mundlapudi via llu)
+
     HADOOP-6833. IPC leaks call parameters when exceptions thrown.
     (Todd Lipcon via Eli Collins)
   

Modified: 
hadoop/common/branches/branch-0.20-security/src/c++/task-controller/impl/task-controller.c
URL: 
http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security/src/c%2B%2B/task-controller/impl/task-controller.c?rev=1151287&r1=1151286&r2=1151287&view=diff
==============================================================================
--- 
hadoop/common/branches/branch-0.20-security/src/c++/task-controller/impl/task-controller.c
 (original)
+++ 
hadoop/common/branches/branch-0.20-security/src/c++/task-controller/impl/task-controller.c
 Tue Jul 26 23:15:32 2011
@@ -620,9 +620,16 @@ int create_directory_for_user(const char
   uid_t user = geteuid();
   gid_t group = getegid();
   int ret = 0;
-  ret = change_effective_user(tt_uid, tt_gid);
+  uid_t root = 0;
+
+  //This check is particularly required for c-based unit tests since 
+  //tests run as a regular user.
+  if (getuid() == root) {
+    ret = change_effective_user(root, tt_gid);
+  }
+
   if (ret == 0) {
-    if (mkdir(path, permissions) == 0) {
+    if (mkdir(path, permissions) == 0 || errno == EEXIST) {
       // need to reassert the group sticky bit
       if (chmod(path, permissions) != 0) {
         fprintf(LOGFILE, "Can't chmod %s to add the sticky bit - %s\n",
@@ -631,21 +638,6 @@ int create_directory_for_user(const char
       } else if (change_owner(path, user, tt_gid) != 0) {
         ret = -1;
       }
-    } else if (errno == EEXIST) {
-      struct stat file_stat;
-      if (stat(path, &file_stat) != 0) {
-        fprintf(LOGFILE, "Can't stat directory %s - %s\n", path, 
-                strerror(errno));
-        ret = -1;
-      } else {
-        if (file_stat.st_uid != user ||
-            file_stat.st_gid != tt_gid) {
-          fprintf(LOGFILE, "Directory %s owned by wrong user or group. "
-                  "Expected %d:%d and found %d:%d.\n",
-                  path, user, tt_gid, file_stat.st_uid, file_stat.st_gid);
-          ret = -1;
-        }
-      }
     } else {
       fprintf(LOGFILE, "Failed to create directory %s - %s\n", path,
               strerror(errno));


Reply via email to