// 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
// 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;
}