X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/72a105702165975d1702e64af7d28b60eb311672..f0019122700792b954b38d5e2a8b8a40d15e49fd:/tools/tesh2/src/writer.c diff --git a/tools/tesh2/src/writer.c b/tools/tesh2/src/writer.c index 419a11f51c..3755abc822 100644 --- a/tools/tesh2/src/writer.c +++ b/tools/tesh2/src/writer.c @@ -14,6 +14,7 @@ #include #include +#include XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); @@ -41,12 +42,15 @@ writer_new(command_t command) int writer_free(writer_t* ptr) { - /* TODO : check the parameter */ + + if((*ptr)->written) + xbt_os_sem_destroy((*ptr)->written); - /*xbt_os_sem_destroy((*writer)->started); - xbt_os_sem_destroy((*writer)->can_write);*/ + if((*ptr)->can_write) + xbt_os_sem_destroy((*ptr)->can_write); free(*ptr); + *ptr = NULL; return 0; @@ -70,6 +74,8 @@ writer_start_routine(void* p) DWORD number_of_bytes_to_write = command->context->input->used; DWORD number_of_bytes_written = 0; + xbt_os_sem_release(writer->written); + while(!command->failed && !command->interrupted && !command->successeded && ! writer->failed && ! writer->broken_pipe && number_of_bytes_to_write) { if(!WriteFile(writer->command->stdin_fd, input, number_of_bytes_to_write, &number_of_bytes_written, NULL)) @@ -92,15 +98,19 @@ writer_start_routine(void* p) if(writer->failed && !command->successeded && !command->failed && !command->interrupted) { - error_register("Write failure", errno, command->context->command_line, command->unit->fstream->name); + ERROR2("[%s] Error while writing input to 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_write_failure); } /*else if(writer->broken_pipe && !command->successeded && !command->failed && !command->interrupted) { + + ERROR2("[%s] Pipe broken while writing input to child `%s'", command->context->pos, command->context->command_line); + unit_set_error(command->unit, (int)GetLastError(), 0); command_kill(command); command_handle_failure(command, csr_write_pipe_broken); }*/ - + CloseHandle(command->stdin_fd); command->stdin_fd = INDEFINITE_FD; @@ -176,12 +186,16 @@ writer_start_routine(void* p) if(writer->failed && !command->successeded && !command->failed && !command->interrupted) { command_kill(command); - error_register("Write failure", errno, command->context->command_line, command->unit->fstream->name); + ERROR2("[%s] Error while writing input to child `%s'", command->context->pos, command->context->command_line); + + unit_set_error(command->unit, errno, 0, command->context->pos); command_handle_failure(command, csr_write_failure); } else if(writer->broken_pipe && !command->successeded && !command->failed && !command->interrupted) { - error_register("write() function failed", errno, command->context->command_line, command->unit->fstream->name); + ERROR2("[%s] Pipe broken while writing input to child `%s'", command->context->pos, command->context->command_line); + + unit_set_error(command->unit, errno, 0, command->context->pos); command_kill(command); command_handle_failure(command, csr_write_pipe_broken); }