void tpie_init(int subsystems) { if (subsystems & MEMORY_MANAGER) init_memory_manager(); if (subsystems & DEFAULT_LOGGING) init_default_log(); if (subsystems & PRIMEDB) init_prime(); if (subsystems & CAPTURE_FRACTIONS) { init_fraction_db(true); init_execution_time_db(); } else if (subsystems & PROGRESS) { init_fraction_db(false); init_execution_time_db(); } if (subsystems & JOB_MANAGER) init_job(); if (subsystems & STREAMS) { init_stream_buffer_pool(); init_compressor(); } if (subsystems & HASH) init_hash(); }
/** * @brief Initialize the MapReduce configuration. */ static void init_mr_config (void) { srand (12345); init_config (); init_stats (); init_job (); distribute_data (); }
/* * resiger a job to job lines * input(2) : PID of job & INFOMATION of commandline * output : JID of job if success * : 0 otherwise */ int resiger_jobs(pid_t pid, char *info) { int jid; if (job_ctr.max) { printf("error : job_list has reach maximum\n"); return 0; } jid = 1; while (job_lists[jid] != NULL) jid++; // to find a space job_lists[jid] = init_job(pid, jid, info); job_ctr.num++; if (job_ctr.num >= MAX_JOBS_NUM - 1) // since job_list[0] is unused job_ctr.max = 1; return jid; }
bool readcmdline(char *msg) { print_colored_prompt(stdout, msg); char *cmdline = (char *)calloc(MAX_LEN_CMDLINE, sizeof(char)); if(!cmdline) return invokefree(NULL, "malloc: no space"); fgets(cmdline, MAX_LEN_CMDLINE, stdin); /* sequence is true only when the command line contains ; */ bool sequence = false; /* seq_pos is used for storing the command line before ; */ int seq_pos = 0; int cmdline_pos = 0; /*iterator for command line; */ while(1) { job_t *current_job = find_last_job(); int cmd_pos = 0; /* iterator for a command */ int iofile_seek = 0; /*iofile_seek for file */ bool valid_input = true; /* check for valid input */ bool end_of_input = false; /* check for end of input */ /* cmdline is NOOP, i.e., just return with spaces*/ while (isspace(cmdline[cmdline_pos])){++cmdline_pos;} /* ignore any spaces */ if(cmdline[cmdline_pos] == '\n' || cmdline[cmdline_pos] == '\0' || feof(stdin)) return false; if (cmdline[cmdline_pos] == '#') //no commands, just a comment return false; /* Check for invalid special symbols (characters) */ if(cmdline[cmdline_pos] == ';' || cmdline[cmdline_pos] == '&' || cmdline[cmdline_pos] == '<' || cmdline[cmdline_pos] == '>' || cmdline[cmdline_pos] == '|') return false; char *cmd = (char *)calloc(MAX_LEN_CMDLINE, sizeof(char)); if(!cmd) return invokefree(NULL,"malloc: no space"); job_t *newjob = (job_t *)malloc(sizeof(job_t)); if(!newjob) return invokefree(NULL,"malloc: no space"); if(!first_job) first_job = current_job = newjob; else { current_job->next = newjob; current_job = current_job->next; } if(!init_job(current_job)) return invokefree(current_job,"init_job: malloc failed"); process_t *current_process = find_last_process(current_job); while(cmdline[cmdline_pos] != '\n' && cmdline[cmdline_pos] != '\0') { switch (cmdline[cmdline_pos]) { case '<': /* input redirection */ current_job->ifile = (char *) calloc(MAX_LEN_FILENAME, sizeof(char)); if(!current_job->ifile) return invokefree(current_job,"malloc: no space"); ++cmdline_pos; while (isspace(cmdline[cmdline_pos])){++cmdline_pos;} /* ignore any spaces */ iofile_seek = 0; while(cmdline[cmdline_pos] != '\0' && !isspace(cmdline[cmdline_pos])){ if(MAX_LEN_FILENAME == iofile_seek) return invokefree(current_job,"input redirection: file length exceeded"); current_job->ifile[iofile_seek++] = cmdline[cmdline_pos++]; } current_job->ifile[iofile_seek] = '\0'; current_job->mystdin = INPUT_FD; while(isspace(cmdline[cmdline_pos])) { if(cmdline[cmdline_pos] == '\n') break; ++cmdline_pos; } valid_input = false; break; case '>': /* output redirection */ current_job->ofile = (char *) calloc(MAX_LEN_FILENAME, sizeof(char)); if(!current_job->ofile) return invokefree(current_job,"malloc: no space"); ++cmdline_pos; while (isspace(cmdline[cmdline_pos])){++cmdline_pos;} /* ignore any spaces */ iofile_seek = 0; while(cmdline[cmdline_pos] != '\0' && !isspace(cmdline[cmdline_pos])){ if(MAX_LEN_FILENAME == iofile_seek) return invokefree(current_job,"input redirection: file length exceeded"); current_job->ofile[iofile_seek++] = cmdline[cmdline_pos++]; } current_job->ofile[iofile_seek] = '\0'; current_job->mystdout = OUTPUT_FD; while(isspace(cmdline[cmdline_pos])) { if(cmdline[cmdline_pos] == '\n') break; ++cmdline_pos; } valid_input = false; break; case '|': /* pipeline */ cmd[cmd_pos] = '\0'; process_t *newprocess = (process_t *)malloc(sizeof(process_t)); if(!newprocess) return invokefree(current_job,"malloc: no space"); if(!init_process(newprocess)) return invokefree(current_job,"init_process: failed"); if(!current_job->first_process) current_process = current_job->first_process = newprocess; else { current_process->next = newprocess; current_process = current_process->next; } if(!readprocessinfo(current_process, cmd)) return invokefree(current_job,"parse cmd: error"); ++cmdline_pos; cmd_pos = 0; /*Reinitialze for new cmd */ valid_input = true; break; case '&': /* background job */ current_job->bg = true; while (isspace(cmdline[cmdline_pos])){++cmdline_pos;} /* ignore any spaces */ if(cmdline[cmdline_pos+1] != '\n' && cmdline[cmdline_pos+1] != '\0') fprintf(stderr, "reading bg: extra input ignored"); end_of_input = true; break; case ';': /* sequence of jobs*/ sequence = true; strncpy(current_job->commandinfo,cmdline+seq_pos,cmdline_pos-seq_pos); seq_pos = cmdline_pos + 1; break; case '#': /* comment */ end_of_input = true; break; default: if(!valid_input) return invokefree(current_job,"reading cmdline: could not fathom input"); if(cmd_pos == MAX_LEN_CMDLINE-1) return invokefree(current_job,"reading cmdline: length exceeds the max limit"); cmd[cmd_pos++] = cmdline[cmdline_pos++]; break; } if(end_of_input || sequence) break; } cmd[cmd_pos] = '\0'; process_t *newprocess = (process_t *)malloc(sizeof(process_t)); if(!newprocess) return invokefree(current_job,"malloc: no space"); if(!init_process(newprocess)) return invokefree(current_job,"init_process: failed"); if(!current_job->first_process) current_process = current_job->first_process = newprocess; else { current_process->next = newprocess; current_process = current_process->next; } if(!readprocessinfo(current_process, cmd)) return invokefree(current_job,"read process info: error"); if(!sequence) { strncpy(current_job->commandinfo,cmdline+seq_pos,cmdline_pos-seq_pos); break; } sequence = false; ++cmdline_pos; } return true; }
asmlinkage static long xjob(__user void *args, int argslen) { struct xargs *xarg = NULL; struct job *job = NULL; int err = 0; /* check and copy user argument */ if (!args) return -EINVAL; /* unless modifing syscall prototype to two arguments * if (sizeof(struct xargs) != argslen) * return -EINVAL; */ argslen = sizeof(struct xargs); xarg = kmalloc(argslen, GFP_KERNEL); if (!xarg) return -ENOMEM; if (copy_from_user(xarg, args, argslen)) { INFO("invalid user address passed"); err = -EFAULT; goto out; } if (xarg->action == ACTION_SETUP) { err = new_job_id(); goto out; } else if (xarg->action == ACTION_REMOVE_ONE) { err = remove_queued_job(xarg->id); goto out; } else if (xarg->action == ACTION_REMOVE_ALL) { err = remove_queued_jobs(); goto out; } else if (xarg->action == ACTION_LIST) { err = list_queued_jobs(xarg->list_buf, xarg->list_len); goto out; } else if (xarg->action >= ACTION_LAST) { err = -EINVAL; goto out; } /* init job */ job = kmalloc(sizeof(struct job), GFP_KERNEL); if (!job) { err = -ENOMEM; goto out; } err = init_job(job, xarg); if (err) goto out_err; err = produce(job); if (err) goto out_err; err = job->id; /* submit successfully, do not free job */ goto out; out_err: destroy_job(job); out: kfree(xarg); return err; }
int main(int argc, char **argv) { Job job; int i; FILE *pjf; init_job(&job); job.core = create_core(); for (i = 1; i < argc; i++) { char *opt = argv[i]; char *arg = argv[i + 1]; if (opt[0] == '-' && strcmp(opt, "-")) { if (!strcmp(opt, "-L") || !strcmp(opt, "--letter")) { job.just_one_letter = 1; job.just_one_word = 0; } if (!strcmp(opt, "-t") || !strcmp(opt, "--truth")) { i++; if (!arg) usage(); job.just_one_letter = 1; job.just_one_word = 0; job.ground_truth = arg; } if (!strcmp(opt, "-a") || !strcmp(opt, "--append")) { job.append = 1; } else if (!strcmp(opt, "-W") || !strcmp(opt, "--word")) { job.just_one_letter = 0; job.just_one_word = 1; } else if (!strcmp(opt, "-l") || !strcmp(opt, "--lib")) { Library l; i++; if (!arg) usage(); l = library_open(arg); library_discard_prototypes(l); add_to_core(job.core, l); } else if (!strcmp(opt, "-p") || !strcmp(opt, "-j") || !strcmp(opt, "--pjf")) { i++; if (!arg) usage(); job.job_file_path = arg; } else if (!strcmp(opt, "-i") || !strcmp(opt, "--in")) { i++; if (!arg) usage(); job.input_path = arg; } else if (!strcmp(opt, "-o") || !strcmp(opt, "--out")) { i++; if (!arg) usage(); set_core_orange_policy(job.core, 1); job.out_library_path = arg; } else if (!strcmp(opt, "-c") || !strcmp(opt, "--color")) { job.colored_output = 1; } else if (!strcmp(opt, "-n") || !strcmp(opt, "--nocolor")) { job.colored_output = 0; } } } load_image(&job); if (job.just_one_letter) { process_letter(&job, 0, 0, job.width, job.height); putchar('\n'); if (job.ground_truth && job.out_library_path) { Library l = get_core_orange_library(job.core); if (library_shelves_count(l)) { Shelf *s = library_get_shelf(l, 0); if (s->count) { strncpy(s->records[0].text, job.ground_truth, MAX_TEXT_SIZE); } } } } else if (job.just_one_word) { process_word(&job, 0, 0, job.width, job.height); putchar('\n'); } else { if (!job.job_file_path) { fprintf(stderr, "You must specify a pjf file (or either -L or -W).\n"); usage(); } pjf = fopen(job.job_file_path, "r"); if (!pjf) { perror(job.job_file_path); exit(1); } go(&job, pjf); } if (job.out_library_path) library_save(get_core_orange_library(job.core), job.out_library_path, job.append); free_bitmap(job.pixels); free_core(job.core); return 0; }