diff options
Diffstat (limited to 'src/Program.c')
-rw-r--r-- | src/Program.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/Program.c b/src/Program.c index fc80e5e..a82bcd2 100644 --- a/src/Program.c +++ b/src/Program.c @@ -74,14 +74,20 @@ int exec_program(const char **args, ProgramOutputCallback output_callback, void int err = errno; fprintf(stderr, "Failed to read from pipe to program %s, error: %s\n", args[0], strerror(err)); result = -err; - goto cleanup; + break; } buffer[bytes_read] = '\0'; - if(output_callback && output_callback(buffer, bytes_read, userdata) != 0) - break; + if(output_callback) { + result = output_callback(buffer, bytes_read, userdata); + if(result != 0) + break; + } } + if(result != 0) + kill(read_program.pid, SIGTERM); + if(waitpid(read_program.pid, &status, 0) == -1) { perror("waitpid failed"); result = -5; @@ -105,7 +111,6 @@ int exec_program(const char **args, ProgramOutputCallback output_callback, void } fprintf(stderr, "), exit status %d\n", exit_status); result = -exit_status; - goto cleanup; } cleanup: |