// Do nothing if we have a callback set
} else if (stdout_callback) {
- // Nothing
+ // Perform line-buffering on the callback
+ r = pakfire_pty_log_stream(ctx.pty, stdout_callback, stdout_data);
+ if (r < 0) {
+ ERROR(jail->ctx, "Failed to setup log stream: %s\n", strerror(-r));
+ goto ERROR;
+ }
// Capture Output?
} else if (output) {
// Configure the callbacks
if (stdin_callback)
pakfire_pty_set_stdin_callback(ctx.pty, stdin_callback, stdin_data);
- if (stdout_callback)
- pakfire_pty_set_stdout_callback(ctx.pty, stdout_callback, stdout_data);
// Setup pipes for logging
// INFO
int pakfire_jail_communicate(
struct pakfire_jail* jail, const char* argv[], struct pakfire_env* env, int flags,
pakfire_pty_stdin_callback stdin_callback, void* stdin_data,
- pakfire_pty_stdout_callback stdout_callback, void* stdout_data);
+ pakfire_log_stream_callback stdout_callback, void* stdout_data);
// Convenience functions
int pakfire_jail_run(struct pakfire* pakfire,
#include <pakfire/ctx.h>
#include <pakfire/file.h>
#include <pakfire/filelist.h>
+#include <pakfire/log_stream.h>
#include <pakfire/pty.h>
#include <pakfire/string.h>
#include <pakfire/util.h>
// Stream for output
FILE* output;
+
+ // Log Stream
+ struct pakfire_log_stream* stream;
};
static int pakfire_pty_same_inode(struct pakfire_pty* pty, int fd1, int fd2) {
if (pty->exit_event)
sd_event_source_unref(pty->exit_event);
+ if (pty->stream)
+ pakfire_log_stream_unref(pty->stream);
if (pty->loop)
sd_event_unref(pty->loop);
if (pty->ctx)
return 0;
}
+/*
+ Log Stream
+*/
+int pakfire_pty_log_stream(struct pakfire_pty* self,
+ pakfire_log_stream_callback callback, void* data) {
+ int r;
+
+ // Create a new log stream
+ r = pakfire_log_stream_create(&self->stream, self->ctx, callback, data);
+ if (r < 0)
+ return r;
+
+ // Register the callback
+ pakfire_pty_set_stdout_callback(self, pakfire_log_stream_pty, self->stream);
+
+ return 0;
+}
+
/*
Interactive Mode
*/
#include <pakfire/ctx.h>
#include <pakfire/filelist.h>
+#include <pakfire/log_stream.h>
struct pakfire_pty;
int pakfire_pty_interactive(struct pakfire_pty* pty);
int pakfire_pty_capture_output(struct pakfire_pty* pty, char** output, size_t* length);
+int pakfire_pty_log_stream(struct pakfire_pty* pty,
+ pakfire_log_stream_callback callback, void* data);
+
typedef ssize_t (*pakfire_pty_stdin_callback)(
struct pakfire_ctx* ctx, void* data, char* buffer, size_t length);
typedef int (*pakfire_pty_stdout_callback)(