From: Michael Tremer Date: Tue, 19 Dec 2023 13:10:02 +0000 (+0000) Subject: jail: PTY forwarding: Call the output callback if available X-Git-Tag: 0.9.30~1273 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=112458fcfb454a953b8faa19b19806a43713b1e5;p=pakfire.git jail: PTY forwarding: Call the output callback if available Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/jail.c b/src/libpakfire/jail.c index 83e7af91b..764bb5a80 100644 --- a/src/libpakfire/jail.c +++ b/src/libpakfire/jail.c @@ -1122,10 +1122,24 @@ static int pakfire_jail_forward_pty(struct pakfire_jail* jail, struct pakfire_ja // Write to standard output if (ctx->pty.stdout.flags & PAKFIRE_JAIL_PTY_READY_TO_WRITE) { - r = pakfire_jail_drain_buffer(jail, ctx->pty.stdout.fd, &ctx->pty.stdout.buffer); - if (r) { - CTX_ERROR(jail->ctx, "Failed writing to standard output: %s\n", strerror(-r)); - return r; + // If we have a callback, we will send any output to the callback + if (ctx->communicate.out) { + r = pakfire_jail_drain_buffer_with_callback(jail, &ctx->pty.stdout.buffer, + LOG_INFO, ctx->communicate.out, ctx->communicate.data); + if (r) + return r; + + // If we have a file descriptor, we will forward any output + } else if (ctx->pty.stdout.fd >= 0) { + r = pakfire_jail_drain_buffer(jail, ctx->pty.stdout.fd, &ctx->pty.stdout.buffer); + if (r) { + CTX_ERROR(jail->ctx, "Failed writing to standard output: %s\n", strerror(-r)); + return r; + } + + // Otherwise we log a message + } else { + CTX_ERROR(jail->ctx, "No output configured for the PTY\n"); } // We are done writing for now @@ -1389,9 +1403,10 @@ int pakfire_jail_capture_stdout(struct pakfire* pakfire, void* data, // Append everything from stdout to a buffer if (output && priority == LOG_INFO) { - r = asprintf(output, "%s%s", (output && *output) ? *output : "", line); + r = asprintf(output, "%s%.*s", (output && *output) ? *output : "", (int)length, line); if (r < 0) - return 1; + return -errno; + return 0; }