void test_create_log_directory() {
    printf("\nTesting test_create_log_directory\n");
    create_userlogs_dir();
    char *job_log_dir = get_job_log_directory("job_7");
    if (job_log_dir == NULL) {
        exit(1);
    }
    if (create_directory_for_user(job_log_dir) != 0) {
        exit(1);
    }
    free(job_log_dir);
    char* good_local_dirs = get_value("mapred.local.dir");
    if (good_local_dirs == NULL) {
        fprintf(LOGFILE, "Mapred local directories could not be obtained.\n");
        exit(1);
    }
    create_attempt_directories(username, good_local_dirs, "job_7", "task_1");

    //check if symlink got created
    struct stat file;
    int status;
    char actualpath [PATH_MAX+1];
    char *res;
    char *filepath = TEST_ROOT "/logs/userlogs/job_7/task_1";

    status = lstat(filepath, &file);
    if (!S_ISLNK(file.st_mode)) {
        fprintf(LOGFILE, "Symlink creation failed\n");
        exit(1);
    }

    //Check if symlink path exists
    res = realpath(filepath, actualpath);
    if(!res) {
        fprintf(LOGFILE, "Failed to get target for the symlink\n");
        exit(1);
    }

    char local_job_dir[PATH_MAX+1];
    int i;
    bool found = false;
    for(i=1; i<5; i++) {
        sprintf(local_job_dir, TEST_ROOT "/local-%d/userlogs/job_7/task_1", i);
        if (strcmp(local_job_dir, actualpath) == 0) {
            found = true;
            break;
        }
    }

    if(!found) {
        printf("FAIL: symlink path and target path mismatch\n");
        exit(1);
    }

    free(good_local_dirs);
}
Exemplo n.º 2
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;
}