X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/c2773e80729fa9563fda174461a822f49fe39a25..21988c314858eeaf92a8b81be8e6ce6ee2243607:/tools/tesh2/src/command.c diff --git a/tools/tesh2/src/command.c b/tools/tesh2/src/command.c index a820c74aca..3f911f6aea 100644 --- a/tools/tesh2/src/command.c +++ b/tools/tesh2/src/command.c @@ -1,9 +1,9 @@ /* * src/command.c - type representing a command. * - * Copyright 2008,2009 Martin Quinson, Malek Cherier All right reserved. + * Copyright 2008,2009 Martin Quinson, Malek Cherier All right reserved. * - * This program is free software; you can redistribute it and/or modify it + * This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. * * Purpose: @@ -30,41 +30,41 @@ tow32cmd(const char* cmd) static char w32cmd[PATH_MAX + 1] = {0}; char cmd_buf[PATH_MAX + 1] = {0}; size_t i,j, len; - + if(!cmd) { errno = EINVAL; return NULL; } - + /* TODO : if ~*/ if(cmd[0] != '.') { strcpy(w32cmd, cmd); return w32cmd; } - + i = j = 0; len = strlen(cmd); - + while(i < len) { if(cmd[i] != ' ' && cmd[i] != '\t' && cmd[i] != '>') cmd_buf[j++] = cmd[i]; else break; - + i++; } _fullpath(w32cmd, cmd_buf, sizeof(w32cmd)); - + if(!strstr(w32cmd, ".exe")) strcat(w32cmd, ".exe "); - + strcat(w32cmd, cmd + i); - - + + /*printf("w32cmd : %s", w32cmd);*/ return w32cmd; @@ -87,43 +87,43 @@ command_t command_new(unit_t unit, context_t context, xbt_os_mutex_t mutex) { command_t command; - + command = xbt_new0(s_command_t, 1); - + /* get the context of the execution of the command */ if(!(command->context = context_dup(context))) { free(command); return NULL; } - + /* the exit code of the command is indefinite */ command->exit_code = INDEFINITE; - + /* the signal of the command is indefinite */ command->signal = INDEFINITE_SIGNAL; - + command->failed = 0; command->interrupted = 0; - + /* the mutex used to safetly access to the command unit properties */ command->mutex = mutex; command->output = xbt_strbuff_new(); command->pid = INDEFINITE_PID; - + command->stat_val = -1; - + /* set the unit of the command */ - command->root = unit->root ? unit->root : unit; + command->root = unit->root ? unit->root : unit; command->unit = unit; - + /* all the commands are runned in a thread */ command->thread = NULL; - + command->successeded = 0; - + command->reader = reader_new(command); if(context->input->used) @@ -138,23 +138,23 @@ command_new(unit_t unit, context_t context, xbt_os_mutex_t mutex) command->status = cs_initialized; command->reason = csr_unknown; - + command->stdin_fd = INDEFINITE_FD; command->stdout_fd = INDEFINITE_FD; - - + + /* register the command */ xbt_os_mutex_acquire(mutex); - + xbt_dynar_push(unit->commands, &command); command->root->cmd_nb++; xbt_os_mutex_release(mutex); - + #ifndef WIN32 command->killed = 0; command->execlp_errno = 0; #endif - + return command; } @@ -164,16 +164,16 @@ command_run(command_t command) { if(!silent_flag && !interrupted) INFO2("[%s] %s",command->context->pos, command->context->command_line); - + if(!just_print_flag) - { + { if(!interrupted) { /* start the command in a thread*/ if(command->context->async) { command->thread = xbt_os_thread_create("", command_start, command); - + } else { @@ -183,12 +183,12 @@ command_run(command_t command) } else { - command_interrupt(command); + command_interrupt(command); } - + } - + return 0; } @@ -198,15 +198,15 @@ command_start(void* p) { command_t command = (command_t)p; unit_t root = command->root; - + /* the command is started */ command->status = cs_started; - + /* increment the number of started commands of the unit */ xbt_os_mutex_acquire(command->mutex); (root->started_cmd_nb)++; xbt_os_mutex_release(command->mutex); - + /* execute the command of the test */ #ifndef WIN32 @@ -215,18 +215,18 @@ command_start(void* p) /* play the translated command line on Windows */ command_exec(command, command->context->t_command_line); #endif - + if(cs_in_progress == command->status) { /* wait the process if it is in progress */ command_wait(command); - + if(cs_failed != command->status && cs_interrupted != command->status) command_check(command); } - + xbt_os_mutex_acquire(command->mutex); - + /* if it's the last command of the root unit */ if(!root->interrupted && root->parsed && (root->started_cmd_nb == (root->failed_cmd_nb + root->interrupted_cmd_nb + root->successeded_cmd_nb))) { @@ -238,22 +238,22 @@ command_start(void* p) } else xbt_os_mutex_release(command->mutex); - - + + /* wait the end of the timer, the reader and the writer */ if(command->timer && command->timer->thread) timer_wait(command->timer); - + /* wait the end of the writer */ if(command->writer && command->writer->thread) writer_wait(command->writer); - + /* wait the end of the reader */ if(command->reader && command->reader->thread) reader_wait(command->reader); - - + + return NULL; } @@ -265,64 +265,64 @@ command_start(void* p) void command_exec(command_t command, const char* command_line) { - + STARTUPINFO si = {0}; /* contains the informations about the child process windows*/ PROCESS_INFORMATION pi = {0}; /* contains child process informations */ SECURITY_ATTRIBUTES sa = {0}; /* contains the security descriptor for the pipe handles */ HANDLE child_stdin_handle[2] = {NULL}; /* child_stdin_handle[1] <-> stdout of the child process */ HANDLE child_stdout_handle[2] = {NULL}; /* child_stdout_handle[0] <-> stdin of the child process */ HANDLE child_stderr = NULL; - + sa.nLength = sizeof(SECURITY_ATTRIBUTES); sa.lpSecurityDescriptor = NULL; /* use default security for the pipe handles */ - + sa.bInheritHandle = TRUE; /* the pipe handles can be inherited */ - + if(!CreatePipe(&(child_stdin_handle[0]),&(child_stdin_handle[1]),&sa,0)) { ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, command->context->command_line, error_to_string((int)GetLastError(), 0)); - + unit_set_error(command->unit, (int)GetLastError(), 0, command->context->pos); command->failed = 1; command->status = cs_failed; - + return; } - - + + if(!DuplicateHandle(GetCurrentProcess(),(child_stdin_handle[1]),GetCurrentProcess(),&(child_stderr),0,TRUE,DUPLICATE_SAME_ACCESS)) { ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, command->context->command_line, error_to_string((int)GetLastError(), 0)); - + unit_set_error(command->unit, (int)GetLastError(), 0, command->context->pos); - + CloseHandle(child_stdin_handle[0]); CloseHandle(child_stdin_handle[1]); command->failed = 1; - command->status = cs_failed; + command->status = cs_failed; return; } - + if(!CreatePipe(&(child_stdout_handle[0]),&(child_stdout_handle[1]),&sa,0)) { ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, command->context->command_line, error_to_string((int)GetLastError(), 0)); unit_set_error(command->unit, (int)GetLastError(), 0, command->context->pos); - + CloseHandle(child_stdout_handle[0]); CloseHandle(child_stdout_handle[1]); CloseHandle(child_stdin_handle[0]); CloseHandle(child_stdin_handle[1]); command->failed = 1; - command->status = cs_failed; + command->status = cs_failed; return; } - + /* Read handle for read operations on the child std output. */ if(!DuplicateHandle(GetCurrentProcess(),(child_stdin_handle[0]),GetCurrentProcess(),&(command->stdout_fd),0,FALSE, DUPLICATE_SAME_ACCESS)) { @@ -332,15 +332,15 @@ command_exec(command_t command, const char* command_line) CloseHandle(child_stdin_handle[1]); command->failed = 1; - command->status = cs_failed; - + command->status = cs_failed; + ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, command->context->command_line, error_to_string((int)GetLastError(), 0)); unit_set_error(command->unit, (int)GetLastError(), 0, command->context->pos); - + return; } - - + + /* Write handle for write operations on the child std input. */ if(!DuplicateHandle(GetCurrentProcess(),(child_stdout_handle[1]),GetCurrentProcess(),&(command->stdin_fd), 0,FALSE,DUPLICATE_SAME_ACCESS)) { @@ -350,31 +350,31 @@ command_exec(command_t command, const char* command_line) CloseHandle(child_stdin_handle[1]); command->failed = 1; - command->status = cs_failed; - + command->status = cs_failed; + ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, command->context->command_line, error_to_string((int)GetLastError(), 0)); unit_set_error(command->unit, (int)GetLastError(), 0, command->context->pos); return; } - + CloseHandle(child_stdin_handle[0]); CloseHandle(child_stdout_handle[1]); - + if(command->timer) { /* launch the timer */ timer_time(command->timer); } - + if(command->reader) { /* launch the reader */ reader_read(command->reader); } - + if(command->writer) { @@ -385,17 +385,17 @@ command_exec(command_t command, const char* command_line) /* if there is a reader wait for its starting */ if(command->reader) xbt_os_sem_acquire(command->reader->started); - + /* if there is a reader wait for its ending */ if(command->writer) xbt_os_sem_acquire(command->writer->written); - + /* if there is a reader wait for its starting */ if(command->timer) xbt_os_sem_acquire(command->timer->started); si.cb = sizeof(STARTUPINFO); - + si.dwFlags |= STARTF_USESTDHANDLES; si.hStdOutput = child_stdin_handle[1]; si.hStdInput = child_stdout_handle[0]; @@ -429,7 +429,7 @@ command_exec(command_t command, const char* command_line) unit_set_error(command->unit, (int)GetLastError(), 0, command->context->pos); command_handle_failure(command, csr_create_process_function_failure); } - + } else { @@ -441,10 +441,10 @@ command_exec(command_t command, const char* command_line) /* close non used thread handle */ CloseHandle(pi.hThread); - + } - + /* close non used handles */ CloseHandle(child_stdin_handle[1]); CloseHandle(child_stdout_handle[0]); @@ -458,7 +458,7 @@ command_exec(command_t command, const char* command_line) { int child_stdin_fd[2] ; int child_stdout_fd[2]; - + #ifdef __CHKCMD int rv = is_cmd(command->unit->runner->path, command->unit->runner->builtin, command_line); @@ -477,151 +477,151 @@ command_exec(command_t command, const char* command_line) } command_handle_failure(command, csr_command_not_found); - + return; } - + #endif - - + + if(command->writer) { - if(pipe(child_stdin_fd)) + if(pipe(child_stdin_fd)) { ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, command->context->command_line, error_to_string(errno, 0)); - + unit_set_error(command->unit, errno, 0, command->context->pos); command_handle_failure(command, csr_pipe_function_failed); - - + + return; } - } - + } + if(command->reader) { - if(pipe(child_stdout_fd)) + if(pipe(child_stdout_fd)) { ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, command->context->command_line, error_to_string(errno, 0)); - + if(command->writer) { close(child_stdin_fd[0]); close(child_stdin_fd[1]); } - + unit_set_error(command->unit, errno, 0, command->context->pos); command_handle_failure(command, csr_pipe_function_failed); - + return; } } - + if(command->writer) { if(fcntl(child_stdin_fd[1], F_SETFL, fcntl(child_stdin_fd[1], F_GETFL) | O_NONBLOCK) < 0) { ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, command->context->command_line, error_to_string(errno, 0)); - + close(child_stdin_fd[0]); close(child_stdin_fd[1]); - + if(command->reader) { close(child_stdout_fd[0]); close(child_stdout_fd[1]); } - + unit_set_error(command->unit, errno, 0, command->context->pos); - command_handle_failure(command, csr_fcntl_function_failed); - + command_handle_failure(command, csr_fcntl_function_failed); + return; } } - + /* to write to the child stdin */ command->stdin_fd = child_stdin_fd[1]; - + /* to read from the child stdout */ command->stdout_fd = child_stdout_fd[0]; - + /* launch the reader if any*/ if(command->reader) reader_read(command->reader); - + /* launch the writer if any */ if(command->writer) writer_write(command->writer); - + /* launch the timer if any */ if(command->timer) timer_time(command->timer); - + /* if there is a reader wait for its starting */ if(command->reader) xbt_os_sem_acquire(command->reader->started); - + /* if there is a reader wait for its ending */ if(command->writer) xbt_os_sem_acquire(command->writer->written); - + /* if there is a reader wait for its starting */ if(command->timer) xbt_os_sem_acquire(command->timer->started); - + /* update the state of the command, assume it is in progress */ command->status = cs_in_progress; - + command->pid= fork(); - - if(command->pid < 0) + + if(command->pid < 0) {/* error */ if(command->writer) { close(child_stdin_fd[0]); close(child_stdin_fd[1]); } - + if(command->reader) { close(child_stdout_fd[0]); close(child_stdout_fd[1]); } - + ERROR2("[%s] Cannot fork the command `%s'", command->context->pos, command->context->command_line); unit_set_error(command->unit, errno, 0, command->context->pos); command_handle_failure(command,csr_fork_function_failure); } else { - if(command->pid) + if(command->pid) {/* father */ - + /* close unused file descriptors */ if(command->writer) close(child_stdin_fd[0]); - + if(command->reader) close(child_stdout_fd[1]); - } - else + } + else {/* child */ - + /* close unused file descriptors */ if(command->writer) close(child_stdin_fd[1]); - + if(command->reader) close(child_stdout_fd[0]); - + if(command->writer) { - /* redirect stdin to child_stdin_fd[0] (now fgets(), getchar() ... read from the pipe */ + /* redirect stdin to child_stdin_fd[0] (now fgets(), getchar() ... read from the pipe */ if(dup2(child_stdin_fd[0],STDIN_FILENO) < 0) { ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, command->context->command_line, error_to_string(errno, 0)); @@ -630,15 +630,15 @@ command_exec(command_t command, const char* command_line) unit_set_error(command->unit, errno, 0, command->context->pos); command_handle_failure(command,csr_dup2_function_failure); } - + /* close the unused file descriptor */ close(child_stdin_fd[0]); } - + if(command->reader) { - - /* redirect stdout and stderr to child_stdout_fd[1] (now printf(), perror()... write to the pipe */ + + /* redirect stdout and stderr to child_stdout_fd[1] (now printf(), perror()... write to the pipe */ if(dup2(child_stdout_fd[1],STDOUT_FILENO) < 0) { ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, command->context->command_line, error_to_string(errno, 0)); @@ -646,18 +646,18 @@ command_exec(command_t command, const char* command_line) unit_set_error(command->unit, errno, 0, command->context->pos); command_handle_failure(command, csr_dup2_function_failure); } - + if(dup2(child_stdout_fd[1], STDERR_FILENO) < 0) { ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, command->context->command_line, error_to_string(errno, 0)); unit_set_error(command->unit, errno, 0, command->context->pos); command_handle_failure(command, csr_dup2_function_failure); } - + /* close the unused file descriptor */ close(child_stdout_fd[1]); } - + /* launch the command */ if(execlp("/bin/sh", "sh", "-c", command->context->command_line, NULL) < 0) command->execlp_errno = errno; @@ -676,11 +676,11 @@ command_wait(command_t command) if(WAIT_FAILED == WaitForSingleObject(command->pid, INFINITE)) { ERROR2("[%s] Cannot wait for the child`%s'", command->context->pos, command->context->command_line); - + unit_set_error(command->unit, (int)GetLastError(), 0, command->context->pos); command_handle_failure(command, csr_wait_failure ); - /* TODO : see for the interruption */ + /* TODO : see for the interruption */ } else { @@ -690,10 +690,10 @@ command_wait(command_t command) if(!GetExitCodeProcess(command->pid,&rv)) { ERROR2("[%s] Cannot get the exit code of the process `%s'",command->context->pos, command->context->command_line); - + unit_set_error(command->unit, (int)GetLastError(), 0, command->context->pos); - command_handle_failure(command, csr_get_exit_code_process_function_failure ); + command_handle_failure(command, csr_get_exit_code_process_function_failure ); } else command->stat_val = command->exit_code = rv; @@ -708,8 +708,8 @@ command_wait(command_t command) { /* let this thread wait for the child so that the main thread can detect the timeout without blocking on the wait */ int pid = waitpid(command->pid, &(command->stat_val), 0); - - if(pid != command->pid) + + if(pid != command->pid) { ERROR2("[%s] Cannot wait for the child`%s'", command->context->pos, command->context->command_line); @@ -739,15 +739,15 @@ command_check(command_t command) { int success = 1; cs_reason_t reason; - + /* we have a signal, store it */ if(WIFSIGNALED(command->stat_val)) { command->signal = strdup(signal_name(WTERMSIG(command->stat_val),command->context->signal)); } - + /* we have a signal and no signal is expected */ - if(WIFSIGNALED(command->stat_val) && !command->context->signal) + if(WIFSIGNALED(command->stat_val) && !command->context->signal) { success = 0; ERROR3("[%s] `%s' : NOK (unexpected signal `%s' caught)", command->context->pos, command->context->command_line, command->signal); @@ -756,37 +756,37 @@ command_check(command_t command) reason = csr_unexpected_signal_caught; } - + /* we have a signal that differ form the expected signal */ - if(WIFSIGNALED(command->stat_val) && command->context->signal && strcmp(signal_name(WTERMSIG(command->stat_val),command->context->signal),command->context->signal)) + if(WIFSIGNALED(command->stat_val) && command->context->signal && strcmp(signal_name(WTERMSIG(command->stat_val),command->context->signal),command->context->signal)) { ERROR4("[%s] `%s' : NOK (got signal `%s' instead of `%s')", command->context->pos, command->context->command_line, command->signal, command->context->signal); - + if(success) { success = 0; unit_set_error(command->unit, ESIGNOTMATCH, 1, command->context->pos); } - + reason = csr_signals_dont_match; } - - /* we don't receipt the expected signal */ - if(!WIFSIGNALED(command->stat_val) && command->context->signal) + + /* we don't receive the expected signal */ + if(!WIFSIGNALED(command->stat_val) && command->context->signal) { - - ERROR3("[%s] `%s' : NOK (expected `%s' not receipt)", command->context->pos, command->context->command_line, command->context->signal); - + + ERROR3("[%s] `%s' : NOK (expected `%s' not received)", command->context->pos, command->context->command_line, command->context->signal); + if(success) { success = 0; - unit_set_error(command->unit, ESIGNOTRECEIPT, 1, command->context->pos); + unit_set_error(command->unit, ESIGNOTRECEIVED, 1, command->context->pos); } - - reason = csr_expected_signal_not_receipt; + + reason = csr_expected_signal_not_received; } - + /* if the command exit normaly and we expect a exit code : test it */ if(WIFEXITED(command->stat_val) /* && INDEFINITE != command->context->exit_code*/) { @@ -794,13 +794,13 @@ command_check(command_t command) if(WEXITSTATUS(command->stat_val) != command->context->exit_code) { ERROR4("[%s] %s : NOK (returned code `%d' instead `%d')", command->context->pos, command->context->command_line, WEXITSTATUS(command->stat_val), command->context->exit_code); - + if(success) { success = 0; unit_set_error(command->unit, EEXITCODENOTMATCH, 1, command->context->pos); } - + reason = csr_exit_codes_dont_match; } } @@ -808,7 +808,7 @@ command_check(command_t command) /* make sure the reader done */ while(!command->reader->done) xbt_os_thread_yield(); - + #ifdef WIN32 CloseHandle(command->stdout_fd); #else @@ -828,7 +828,7 @@ command_check(command_t command) char *out = xbt_str_join(a,"\n||"); xbt_dynar_free(&a); INFO2("Output of <%s> so far: \n||%s", command->context->pos,out); - free(out); + free(out); } /* if ouput handling flag is specified check the output */ else if(oh_check == command->context->output_handling && command->reader) @@ -837,9 +837,9 @@ command_check(command_t command) { char *diff; - + ERROR2("[%s] `%s' : NOK (outputs mismatch):", command->context->pos, command->context->command_line); - + if(success) { unit_set_error(command->unit, EOUTPUTNOTMATCH, 1, command->context->pos); @@ -849,28 +849,28 @@ command_check(command_t command) reason = csr_outputs_dont_match; /* display the diff */ - diff = xbt_str_diff(command->context->output->data,command->output->data); + diff = xbt_str_diff(command->context->output->data,command->output->data); INFO1("%s",diff); free(diff); } } - else if (oh_ignore == command->context->output_handling) + else if (oh_ignore == command->context->output_handling) { INFO1("(ignoring the output of <%s> as requested)",command->context->line); - } - else if (oh_display == command->context->output_handling) + } + else if (oh_display == command->context->output_handling) { xbt_dynar_t a = xbt_str_split(command->output->data, "\n"); char *out = xbt_str_join(a,"\n||"); xbt_dynar_free(&a); INFO3("[%s] Here is the (ignored) command `%s' output: \n||%s",command->context->pos, command->context->command_line, out); free(out); - } - + } + if(success) { xbt_os_mutex_acquire(command->mutex); - + if(command->status != cs_interrupted) { /* signal the success of the command */ @@ -880,8 +880,8 @@ command_check(command_t command) /* increment the number of successeded command of the unit */ (command->root->successeded_cmd_nb)++; } - - xbt_os_mutex_release(command->mutex); + + xbt_os_mutex_release(command->mutex); } else { @@ -906,19 +906,19 @@ command_kill(command_t command) if(INDEFINITE_PID != command->pid) { kill(command->pid,SIGTERM); - + if(!command->context->signal) command->context->signal = strdup("SIGTERM"); - + command->exit_code = INDEFINITE; command->killed = 1; - + usleep(100); INFO2("[%s] Kill the process `%s'", command->context->pos, command->context->command_line); - kill(command->pid,SIGKILL); + kill(command->pid,SIGKILL); + - } } #endif @@ -927,10 +927,10 @@ void command_interrupt(command_t command) { xbt_os_mutex_acquire(command->mutex); - + if((command->status != cs_interrupted) && (command->status != cs_failed) && (command->status != cs_successeded)) { - command->status = cs_interrupted; + command->status = cs_interrupted; command->reason = csr_interruption_request; command->interrupted = 1; command->unit->interrupted = 1; @@ -938,14 +938,14 @@ command_interrupt(command_t command) xbt_os_mutex_acquire(command->root->mutex); (command->root->interrupted_cmd_nb)++; xbt_os_mutex_release(command->root->mutex); - + if(command->pid != INDEFINITE_PID) command_kill(command); } - + xbt_os_mutex_release(command->mutex); - - + + } void @@ -953,12 +953,12 @@ command_summarize(command_t command) { if(cs_successeded != command->status) { - + #ifndef WIN32 if(command->killed) printf(" \n"); #endif - + /* display the reason of the status of the command */ switch(command->reason) { @@ -966,7 +966,7 @@ command_summarize(command_t command) case csr_pipe_function_failed : printf(" reason : pipe() or CreatePipe() function failed (system error)\n"); break; - + case csr_shell_failed : printf(" reason : shell failed (may be command not found)\n"); break; @@ -974,7 +974,7 @@ command_summarize(command_t command) case csr_get_exit_code_process_function_failure : printf(" reason : ExitCodeProcess() function failed (system error)\n"); break; - + /* reader failure reasons*/ case csr_read_pipe_broken : printf(" reason : command read pipe broken\n"); @@ -983,7 +983,7 @@ command_summarize(command_t command) case csr_read_failure : printf(" reason : command stdout read failed\n"); break; - + /* writer failure reasons */ case csr_write_failure : printf(" reason : command stdin write failed\n"); @@ -992,67 +992,67 @@ command_summarize(command_t command) case csr_write_pipe_broken : printf(" reason : command write pipe broken\n"); break; - + /* timer reason */ case csr_timeout : printf(" reason : command timeouted\n"); break; - + /* command failure reason */ case csr_command_not_found : printf(" reason : command not found\n"); break; - + /* context failure reasons */ case csr_exit_codes_dont_match : printf(" reason : exit codes don't match\n"); - + break; - + /* dup2 function failure reasons */ case csr_dup2_function_failure : printf(" reason : dup2() function failed\n"); - + break; - + /* execlp function failure reasons */ case csr_execlp_function_failure : printf(" reason : execlp() function failed\n"); - + break; - + /* waitpid function failure reasons */ case csr_waitpid_function_failure : printf(" reason : waitpid() function failed\n"); - + break; - + /* CreateProcess function failure reasons */ case csr_create_process_function_failure : printf(" reason : CreateProcesss() function failed\n"); - + break; - + case csr_outputs_dont_match : { /*char *diff;*/ printf(" reason : ouputs don't match\n"); - /*diff = xbt_str_diff(command->context->output->data,command->output->data); + /*diff = xbt_str_diff(command->context->output->data,command->output->data); printf(" output diff :\n%s\n",diff); free(diff);*/ - } + } break; case csr_signals_dont_match : - printf(" reason : signals don't match\n"); + printf(" reason : signals don't match\n"); break; - + case csr_unexpected_signal_caught: printf(" reason : unexpected signal caught\n"); break; - - case csr_expected_signal_not_receipt : + + case csr_expected_signal_not_received : printf(" reason : expected signal not receipt\n"); break; @@ -1060,16 +1060,16 @@ command_summarize(command_t command) case csr_fork_function_failure : printf(" reason : fork function failed\n"); break; - + case csr_wait_failure : printf(" reason : wait command failure\n"); break; - + /* global/local interruption */ case csr_interruption_request : printf(" reason : the command receive a interruption request\n"); break; - + /* unknown ? */ case csr_unknown : printf(" reason : unknown \n"); @@ -1081,13 +1081,13 @@ command_summarize(command_t command) if(INDEFINITE != command->exit_code) /* the command exit code */ printf(" exit code : %d\n",command->exit_code); - + /* if an expected exit code was specified display it */ if(INDEFINITE != command->context->exit_code) printf(" expected exit code : %d\n",command->context->exit_code); else printf(" no expected exit code specified\n"); - + /* no expected signal expected */ if(NULL == command->context->signal) { @@ -1095,7 +1095,7 @@ command_summarize(command_t command) if(command->signal) printf(" but got signal : %s\n",command->signal); - + } /* if an expected exit code was specified display it */ else @@ -1105,7 +1105,7 @@ command_summarize(command_t command) else printf(" no signal caugth\n"); } - + /* if the command has out put and the metacommand display output is specified display it */ if(command->output && (0 != command->output->used) && (oh_display == command->context->output_handling)) { @@ -1124,7 +1124,7 @@ void command_handle_failure(command_t command, cs_reason_t reason) { unit_t root = command->root; - + xbt_os_mutex_acquire(command->mutex); if((command->status != cs_interrupted) && (command->status != cs_failed)) @@ -1134,12 +1134,12 @@ command_handle_failure(command_t command, cs_reason_t reason) command->failed = 1; command->unit->failed = 1; - + xbt_os_mutex_acquire(root->mutex); - + /* increment the number of failed command of the unit */ root->failed_cmd_nb++; - + /* if the --ignore-failures option is not specified */ if(!keep_going_unit_flag) { @@ -1151,7 +1151,7 @@ command_handle_failure(command_t command, cs_reason_t reason) /* release the unit */ xbt_os_sem_release(root->sem); } - + /* if the --keep-going option is not specified */ if(!keep_going_flag) { @@ -1159,7 +1159,7 @@ command_handle_failure(command_t command, cs_reason_t reason) { /* request an global interruption by the runner */ interrupted = 1; - + /* release the runner */ xbt_os_sem_release(units_sem); } @@ -1180,40 +1180,40 @@ command_free(command_t* ptr) #ifdef WIN32 if((*ptr)->stdin_fd != INDEFINITE_FD) CloseHandle((*ptr)->stdin_fd); - + if((*ptr)->stdout_fd != INDEFINITE_FD) CloseHandle((*ptr)->stdout_fd); - + #else - + if((*ptr)->stdin_fd != INDEFINITE_FD) close((*ptr)->stdin_fd); - - if((*ptr)->stdout_fd != INDEFINITE_FD) + + if((*ptr)->stdout_fd != INDEFINITE_FD) close((*ptr)->stdout_fd); #endif - + if((*ptr)->timer) { if(timer_free(&((*ptr)->timer)) < 0) return -1; } - + if((*ptr)->writer) { if(writer_free(&((*ptr)->writer)) < 0) return -1; } - + if((*ptr)->reader) { if(reader_free(&((*ptr)->reader)) < 0) return -1; } - + if((*ptr)->output) xbt_strbuff_free((*ptr)->output); - + if((*ptr)->context) { if(context_free(&((*ptr)->context)) < 0) @@ -1224,9 +1224,9 @@ command_free(command_t* ptr) free((*ptr)->signal); free(*ptr); - + *ptr = NULL; - + return 0; }