Author: yhemanth
Date: Wed Apr 8 13:57:06 2009
New Revision: 763247
URL: http://svn.apache.org/viewvc?rev=763247&view=rev
Log:
HADOOP-5462. Fixed a double free bug in the task-controller executable.
Contributed by Sreekanth Ramakrishnan.
Modified:
hadoop/core/trunk/CHANGES.txt
hadoop/core/trunk/src/c++/task-controller/configuration.c
hadoop/core/trunk/src/c++/task-controller/configuration.h.in
hadoop/core/trunk/src/c++/task-controller/task-controller.c
hadoop/core/trunk/src/c++/task-controller/task-controller.h
Modified: hadoop/core/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=763247&r1=763246&r2=763247&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Wed Apr 8 13:57:06 2009
@@ -373,6 +373,9 @@
HADOOP-4045. Fix processing of IO errors in EditsLog.
(Boris Shkolnik via shv)
+ HADOOP-5462. Fixed a double free bug in the task-controller
+ executable. (Sreekanth Ramakrishnan via yhemanth)
+
Release 0.20.0 - Unreleased
INCOMPATIBLE CHANGES
Modified: hadoop/core/trunk/src/c++/task-controller/configuration.c
URL:
http://svn.apache.org/viewvc/hadoop/core/trunk/src/c%2B%2B/task-controller/configuration.c?rev=763247&r1=763246&r2=763247&view=diff
==============================================================================
--- hadoop/core/trunk/src/c++/task-controller/configuration.c (original)
+++ hadoop/core/trunk/src/c++/task-controller/configuration.c Wed Apr 8
13:57:06 2009
@@ -18,8 +18,11 @@
#include "configuration.h"
+
char * hadoop_conf_dir;
+struct configuration config={.size=0, .confdetails=NULL};
+
//clean up method for freeing configuration
void free_configurations() {
int i = 0;
Modified: hadoop/core/trunk/src/c++/task-controller/configuration.h.in
URL:
http://svn.apache.org/viewvc/hadoop/core/trunk/src/c%2B%2B/task-controller/configuration.h.in?rev=763247&r1=763246&r2=763247&view=diff
==============================================================================
--- hadoop/core/trunk/src/c++/task-controller/configuration.h.in (original)
+++ hadoop/core/trunk/src/c++/task-controller/configuration.h.in Wed Apr 8
13:57:06 2009
@@ -47,7 +47,7 @@
#define CONF_FILE_PATTERN "%s/conf/taskcontroller.cfg"
#endif
-struct configuration config;
+extern struct configuration config;
//configuration file contents
#ifndef HADOOP_CONF_DIR
extern char *hadoop_conf_dir;
Modified: hadoop/core/trunk/src/c++/task-controller/task-controller.c
URL:
http://svn.apache.org/viewvc/hadoop/core/trunk/src/c%2B%2B/task-controller/task-controller.c?rev=763247&r1=763246&r2=763247&view=diff
==============================================================================
--- hadoop/core/trunk/src/c++/task-controller/task-controller.c (original)
+++ hadoop/core/trunk/src/c++/task-controller/task-controller.c Wed Apr 8
13:57:06 2009
@@ -98,16 +98,12 @@
if (mapred_local_dir == NULL) {
if (get_mapred_local_dir() < 0) {
- fprintf(LOGFILE, "invalid hadoop config\n");
return -1;
}
}
token = strtok((char *) mapred_local_dir, ",");
if (token == NULL && mapred_local_dir != NULL) {
-#ifdef DEBUG
- fprintf(LOGFILE,"Single hadoop.tmp.dir configured");
-#endif
token = (char *)mapred_local_dir;
}
@@ -235,7 +231,6 @@
const char *tt_root) {
char *task_script_path = NULL;
char *pid_path = NULL;
- char *task_script = NULL;
FILE *file_handle = NULL;
int exit_code = 0;
int i = 0;
@@ -253,10 +248,18 @@
return INVALID_TT_ROOT;
}
+ //change the user
+ fclose(LOGFILE);
+ fcloseall();
+ umask(0);
+ if (change_user(user) != 0) {
+ cleanup();
+ return SETUID_OPER_FAILED;
+ }
+
get_pid_path(jobid, taskid, tt_root, &pid_path);
if (pid_path == NULL) {
- fprintf(LOGFILE, "Invalid task-pid path provided");
cleanup();
return INVALID_PID_PATH;
}
@@ -265,75 +268,30 @@
file_handle = fopen(pid_path, "w");
if (file_handle == NULL) {
- fprintf(LOGFILE, "Error opening task-pid file %s :%s\n", pid_path,
- strerror(errno));
exit_code = UNABLE_TO_OPEN_PID_FILE_WRITE_MODE;
goto cleanup;
}
errno = 0;
if (fprintf(file_handle, "%d\n", getpid()) < 0) {
- fprintf(LOGFILE, "Error writing to task-pid file :%s\n", strerror(errno));
exit_code = UNABLE_TO_WRITE_TO_PID_FILE;
goto cleanup;
}
fflush(file_handle);
fclose(file_handle);
+ //set file handle to null after closing so it would not be double closed
+ //in cleanup label
+ file_handle = NULL;
//change the permissions of the file
errno = 0;
- //setting permission to 777
-
- if (chmod(pid_path, S_IREAD | S_IEXEC | S_IWRITE | S_IROTH | S_IWOTH
- | S_IXOTH | S_IRGRP | S_IWGRP | S_IXGRP) < 0) {
- fprintf(LOGFILE, "Error changing permission of %s task-pid file : %s",
- pid_path, strerror(errno));
- errno = 0;
- if (remove(pid_path) < 0) {
- fprintf(LOGFILE, "Error deleting %s task-pid file : %s", pid_path,
- strerror(errno));
- exit_code = UNABLE_TO_CHANGE_PERMISSION_AND_DELETE_PID_FILE;
- } else {
- exit_code = UNABLE_TO_CHANGE_PERMISSION_OF_PID_FILE;
- }
- goto cleanup;
- }
-#ifdef DEBUG
- fprintf(LOGFILE,"changing file ownership\n");
- fprintf(LOGFILE, "run_task_as_user : uid id %d \n", getuid());
- fprintf(LOGFILE, "run_task_as_user : gid id %d \n", getgid());
-#endif
- //change the owner ship of the file to the launching user.
- if(chown(pid_path, getuid(), getgid()) <0 ) {
- fprintf(LOGFILE, "Error changing ownership of %s task-pid file : %s",
- pid_path, strerror(errno));
- if(remove(pid_path) < 0) {
- fprintf(LOGFILE, "Error deleting %s task-pid file : %s", pid_path,
- strerror(errno));
- exit_code = UNABLE_TO_CHANGE_OWNERSHIP_OF_PID_FILE_AND_DELETE_PID_FILE;
- } else {
- exit_code = UNABLE_TO_CHANGE_OWNERSHIP_OF_PID_FILE;
- }
- goto cleanup;
- }
-
-
//free pid_t path which is allocated
free(pid_path);
-
- //change the user
- fcloseall();
- fclose(LOGFILE);
- umask(0);
- if (change_user(user) != 0) {
- cleanup();
- return SETUID_OPER_FAILED;
- }
+ pid_path = NULL;
get_task_file_path(jobid, taskid, tt_root, &task_script_path);
if (task_script_path == NULL) {
- fprintf(LOGFILE, "Unable to locate task script");
cleanup();
return INVALID_TASK_SCRIPT_PATH;
}
@@ -341,7 +299,6 @@
cleanup();
execlp(task_script_path, task_script_path, NULL);
if (errno != 0) {
- fprintf(LOGFILE, "Error execing script %s", strerror(errno));
free(task_script_path);
exit_code = UNABLE_TO_EXECUTE_TASK_SCRIPT;
}
@@ -388,23 +345,28 @@
fprintf(LOGFILE,"kill_user_task : tt_root : %s \n", tt_root);
fflush(LOGFILE);
#endif
+
if (check_tt_root(tt_root) < 0) {
- fprintf(LOGFILE, "invalid tt root specified");
+ fprintf(LOGFILE, "invalid tt root passed %s\n", tt_root);
cleanup();
return INVALID_TT_ROOT;
}
+
+ fclose(LOGFILE);
+ fcloseall();
+
+ if (change_user(user) != 0) {
+ cleanup();
+ return SETUID_OPER_FAILED;
+ }
+
get_pid_path(jobid, taskid, tt_root, &pid_path);
if (pid_path == NULL) {
cleanup();
return INVALID_PID_PATH;
}
-#ifdef DEBUG
- fprintf(LOGFILE,"kill_user_task : task-pid path :%s \n",pid_path);
- fflush(LOGFILE);
-#endif
file_handle = fopen(pid_path, "r");
if (file_handle == NULL) {
- fprintf(LOGFILE, "unable to open task-pid file :%s \n", pid_path);
free(pid_path);
cleanup();
return UNABLE_TO_OPEN_PID_FILE_READ_MODE;
@@ -413,14 +375,9 @@
fclose(file_handle);
free(pid_path);
if (pid == 0) {
- fprintf(LOGFILE, "Unable to read task-pid from path: %s \n", pid_path);
cleanup();
return UNABLE_TO_READ_PID;
}
- if (change_user(user) != 0) {
- cleanup();
- return SETUID_OPER_FAILED;
- }
if (kill(pid, SIGTERM) < 0) {
fprintf(LOGFILE, "%s\n", strerror(errno));
cleanup();
Modified: hadoop/core/trunk/src/c++/task-controller/task-controller.h
URL:
http://svn.apache.org/viewvc/hadoop/core/trunk/src/c%2B%2B/task-controller/task-controller.h?rev=763247&r1=763246&r2=763247&view=diff
==============================================================================
--- hadoop/core/trunk/src/c++/task-controller/task-controller.h (original)
+++ hadoop/core/trunk/src/c++/task-controller/task-controller.h Wed Apr 8
13:57:06 2009
@@ -47,10 +47,6 @@
UNABLE_TO_OPEN_PID_FILE_WRITE_MODE,
UNABLE_TO_OPEN_PID_FILE_READ_MODE,
UNABLE_TO_WRITE_TO_PID_FILE,
- UNABLE_TO_CHANGE_PERMISSION_OF_PID_FILE,
- UNABLE_TO_CHANGE_PERMISSION_AND_DELETE_PID_FILE,
- UNABLE_TO_CHANGE_OWNERSHIP_OF_PID_FILE,
- UNABLE_TO_CHANGE_OWNERSHIP_OF_PID_FILE_AND_DELETE_PID_FILE,
SETUID_OPER_FAILED,
INVALID_TASK_SCRIPT_PATH,
UNABLE_TO_EXECUTE_TASK_SCRIPT,