예제 #1
0
/*
 * Function used to launch a task as the provided user. It does the following :
 * 1) Creates attempt work dir and log dir to be accessible by the child
 * 2) Copies the script file from the TT to the work directory
 * 3) Sets up the environment
 * 4) Does an execlp on the same in order to replace the current image with
 *    task image.
 */
int run_task_as_user(const char *user, const char * good_local_dirs,
                     const char *job_id, const char *task_id,
                     const char *work_dir, const char *script_name) {
  int exit_code = -1;
  char *task_script_path = NULL;
  if (create_attempt_directories(user, good_local_dirs, job_id, task_id) != 0) {
    goto cleanup;
  }
  int task_file_source = open_file_as_task_tracker(script_name);
  if (task_file_source == -1) {
    goto cleanup;
  }
  task_script_path = get_task_launcher_file(work_dir);
  if (task_script_path == NULL) {
    exit_code = OUT_OF_MEMORY;
    goto cleanup;
  }
  if (copy_file(task_file_source, script_name,task_script_path,S_IRWXU) != 0) {
    goto cleanup;
  }

  //change the user
  // dlai blocked 12/29/2012 fcloseall();
  // dlai added ditto
  fflush(stdin);
  fflush(stdout);
  fflush(stderr);
  fclose(stdin);
  fclose(stdout);
  fclose(stderr);

  umask(0027);
  if (chdir(work_dir) != 0) {
    fprintf(LOGFILE, "Can't change directory to %s -%s\n", work_dir,
	    strerror(errno));
    goto cleanup;
  }
  if (change_user(user_detail->pw_uid, user_detail->pw_gid) != 0) {
    exit_code = SETUID_OPER_FAILED;
    goto cleanup;
  }

  // dlai blocked `1/19/10`1 if (execlp(task_script_path, task_script_path, NULL) != 0) {
  if (execlp(task_script_path, task_script_path, (char*) 0) != 0) {
    fprintf(LOGFILE, "Couldn't execute the task jvm file %s - %s", 
            task_script_path, strerror(errno));
    exit_code = UNABLE_TO_EXECUTE_TASK_SCRIPT;
    goto cleanup;
  }
  exit_code = 0;

 cleanup:
  free(task_script_path);
  return exit_code;
}
예제 #2
0
void test_get_task_launcher_file() {
  char *expected_file = ("/tmp/usercache/user/appcache/job_200906101234_0001"
			 "/task.sh");
  char *job_dir = get_job_directory("/tmp", "user",
                                    "job_200906101234_0001");
  char *task_file =  get_task_launcher_file(job_dir);
  if (strcmp(task_file, expected_file) != 0) {
    printf("failure to match expected task file %s vs %s\n", task_file,
           expected_file);
    exit(1);
  }
  free(job_dir);
  free(task_file);
}