static bool sge_parse_from_file_qrstat(const char *file, lList **ppcmdline, lList **alpp) { bool ret = true; DENTER(TOP_LAYER, "sge_parse_from_file_qrstat"); if (ppcmdline == NULL) { ret = false; } else { if (!sge_is_file(file)) { /* * This is no error */ DPRINTF(("file "SFQ" does not exist\n", file)); } else { char *file_as_string = NULL; int file_as_string_length; file_as_string = sge_file2string(file, &file_as_string_length); if (file_as_string == NULL) { answer_list_add_sprintf(alpp, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR, MSG_ANSWER_ERRORREADINGFROMFILEX_S, file); ret = false; } else { char **token = NULL; token = stra_from_str(file_as_string, " \n\t"); *alpp = cull_parse_cmdline(QRSTAT, token, environ, ppcmdline, FLG_USE_PSEUDOS); } } } DRETURN(ret); }
bool switch_list_qstat_parse_from_file(lList **switch_list, lList **answer_list, int mode, const char *file) { bool ret = true; DENTER(TOP_LAYER, "switch_list_qstat_parse_from_file"); if (switch_list == NULL) { ret = false; } else { if (!sge_is_file(file)) { /* * This is no error */ DPRINTF(("file "SFQ" does not exist\n", file)); ret = true; } else { char *file_as_string = NULL; int file_as_string_length; file_as_string = sge_file2string(file, &file_as_string_length); if (file_as_string == NULL) { answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR, MSG_ANSWER_ERRORREADINGFROMFILEX_S, file); ret = false; } else { char **token = NULL; token = stra_from_str(file_as_string, " \n\t"); ret = switch_list_qstat_parse_from_cmdline(switch_list, answer_list, mode, token); sge_strafree(&token); } sge_free(&file_as_string); } } DRETURN(ret); }
static void qevent_parse_command_line(int argc, char **argv, qevent_options *option_struct) { DENTER(TOP_LAYER, "qevent_parse_command_line"); option_struct->help_option = 0; option_struct->testsuite_option = 0; option_struct->subscribe_option = 0; option_struct->trigger_option_count =0; while (*(++argv)) { if (!strcmp("-h", *argv) || !strcmp("-help", *argv)) { option_struct->help_option = 1; continue; } if (!strcmp("-ts", *argv) || !strcmp("-testsuite", *argv)) { option_struct->testsuite_option = 1; continue; } if (!strcmp("-sm", *argv) || !strcmp("-subscribe", *argv)) { option_struct->subscribe_option = 1; continue; } if (!strcmp("-trigger", *argv)) { int ok = 0; if (option_struct->trigger_option_count >= MAX_TRIGGER_SCRIPTS ) { sge_dstring_sprintf(option_struct->error_message, "option \"-trigger\": only "sge_U32CFormat" trigger arguments supported\n", sge_u32c(MAX_TRIGGER_SCRIPTS) ); break; } ++argv; if (*argv) { /* get EVENT argument */ if (strcmp(qevent_get_event_name(QEVENT_JB_END),*argv) == 0) { ok = 1; (option_struct->trigger_option_events)[option_struct->trigger_option_count] = QEVENT_JB_END; } if (strcmp(qevent_get_event_name(QEVENT_JB_TASK_END),*argv) == 0) { ok = 1; (option_struct->trigger_option_events)[option_struct->trigger_option_count] = QEVENT_JB_TASK_END; } if (!ok) { sge_dstring_append(option_struct->error_message,"option \"-trigger\": undefined EVENT type\n"); break; } } else { sge_dstring_append(option_struct->error_message,"option \"-trigger\": found no EVENT argument\n"); break; } ++argv; if (*argv) { /* get SCRIPT argument */ /* check for SCRIPT file */ if (!sge_is_file(*argv)) { sge_dstring_sprintf(option_struct->error_message, "option \"-trigger\": SCRIPT file %s not found\n", (*argv)); break; } /* is file executable ? */ if (!sge_is_executable(*argv)) { sge_dstring_sprintf(option_struct->error_message, "option \"-trigger\": SCRIPT file %s not executable\n", (*argv)); break; } (option_struct->trigger_option_scripts)[option_struct->trigger_option_count] = *argv; (option_struct->trigger_option_count)++; } else { sge_dstring_append(option_struct->error_message,"option \"-trigger\": found no SCRIPT argument\n"); break; } continue; } /* unkown option */ if ( *argv[0] == '-' ) { sge_dstring_append(option_struct->error_message,"unkown option: "); sge_dstring_append(option_struct->error_message,*argv); sge_dstring_append(option_struct->error_message,"\n"); } else { sge_dstring_append(option_struct->error_message,"unkown argument: "); sge_dstring_append(option_struct->error_message,*argv); sge_dstring_append(option_struct->error_message,"\n"); } } DEXIT; }
static void qevent_start_trigger_script(int qevent_event, const char* script_file, lListElem *event ) { u_long jobid, taskid; const char* event_name; int pid; char buffer[MAX_STRING_SIZE]; char buffer2[MAX_STRING_SIZE]; DENTER(TOP_LAYER, "qevent_start_trigger_script"); jobid = lGetUlong(event, ET_intkey); taskid = lGetUlong(event, ET_intkey2); event_name = qevent_get_event_name(qevent_event); /* test if script is executable and valid file */ if (!sge_is_file(script_file)) { ERROR((SGE_EVENT, "no script file: "SFQ"\n", script_file)); DEXIT; return; } /* is file executable ? */ if (!sge_is_executable(script_file)) { ERROR((SGE_EVENT, "file not executable: "SFQ"\n", script_file)); DEXIT; return; } pid = fork(); if (pid < 0) { ERROR((SGE_EVENT, "fork() error\n")); DEXIT; return; } if (pid > 0) { int exit_status; #if !(defined(CRAY) || defined(INTERIX)) struct rusage rusage; #endif #if defined(SVR3) || defined(_BSD) union wait status; #else int status; #endif #if defined(CRAY) || defined(INTERIX) waitpid(pid, &status, 0); #else wait3(&status, 0, &rusage); #endif #if defined(SVR3) || defined(_BSD) exit_status = status.w_retcode; #else exit_status = status; #endif if ( WEXITSTATUS(exit_status) == 0 ) { INFO((SGE_EVENT,"exit status of script: "sge_U32CFormat"\n", sge_u32c(WEXITSTATUS(exit_status)))); } else { ERROR((SGE_EVENT,"exit status of script: "sge_U32CFormat"\n", sge_u32c(WEXITSTATUS(exit_status)))); } DEXIT; return; } else { const char *basename = sge_basename( script_file, '/' ); /* SETPGRP; */ /* sge_close_all_fds(NULL); */ sprintf(buffer ,sge_U32CFormat,sge_u32c(jobid)); sprintf(buffer2 ,sge_U32CFormat,sge_u32c(taskid)); execlp(script_file, basename, event_name, buffer, buffer2, (char *)0); } exit(1); }