diff options
| author | Egor Tensin <Egor.Tensin@gmail.com> | 2023-07-09 15:53:11 +0200 |
|---|---|---|
| committer | Egor Tensin <Egor.Tensin@gmail.com> | 2023-07-09 17:37:44 +0200 |
| commit | 0600cacfadf00e916340f2394f1d3bfc173a3d0b (patch) | |
| tree | 4b1900b096de3d2b3ad49094e86adc310ec79dac /src/process.c | |
| parent | test: attempt to fix random port selection again (diff) | |
| download | cimple-0600cacfadf00e916340f2394f1d3bfc173a3d0b.tar.gz cimple-0600cacfadf00e916340f2394f1d3bfc173a3d0b.zip | |
store process output in SQLite
Diffstat (limited to 'src/process.c')
| -rw-r--r-- | src/process.c | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/src/process.c b/src/process.c index f800ad4..ee387bb 100644 --- a/src/process.c +++ b/src/process.c @@ -106,18 +106,18 @@ int proc_capture(const char *args[], const char *envp[], struct proc_output *res file_close(pipe_fds[1]); - ret = file_read(pipe_fds[0], &result->output, &result->output_len); + ret = file_read(pipe_fds[0], &result->data, &result->data_size); if (ret < 0) goto close_pipe; ret = wait_for_child(child_pid, &result->ec); if (ret < 0) - goto free_output; + goto free_data; goto close_pipe; -free_output: - free(result->output); +free_data: + free(result->data); close_pipe: file_close(pipe_fds[0]); @@ -127,23 +127,30 @@ close_pipe: return ret; } -void proc_output_init(struct proc_output *output) +int proc_output_create(struct proc_output **_output) { + struct proc_output *output = calloc(1, sizeof(struct proc_output)); + if (!output) { + log_errno("calloc"); + return -1; + } + output->ec = 0; - output->output = NULL; - output->output_len = 0; + output->data = NULL; + output->data_size = 0; + + *_output = output; + return 0; } -void proc_output_free(const struct proc_output *output) +void proc_output_destroy(struct proc_output *output) { - free(output->output); + free(output->data); + free(output); } void proc_output_dump(const struct proc_output *output) { log("Process exit code: %d\n", output->ec); - log("Process output:\n%s", output->output); - if (!output->output || !output->output_len || - output->output[output->output_len - 1] != '\n') - log("\n"); + log("Process output: %zu bytes\n", output->data_size); } |
