From: Michael Tremer Date: Mon, 24 Mar 2025 19:34:46 +0000 (+0000) Subject: jail: Move the send buffer function from the PTY X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9b6c43f62693f3b27ae83b64cb49c07f8ff4ef39;p=pakfire.git jail: Move the send buffer function from the PTY Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/build.c b/src/pakfire/build.c index 4ac34784..56b5d993 100644 --- a/src/pakfire/build.c +++ b/src/pakfire/build.c @@ -1113,7 +1113,7 @@ static int pakfire_build_process_scriptlet_dep(struct pakfire_ctx* ctx, void* da static int pakfire_build_add_scriptlet_requires(struct pakfire_build* build, struct pakfire_package* pkg, struct pakfire_scriptlet* scriptlet) { - struct pakfire_pty_buffer buffer = {}; + struct pakfire_input_buffer buffer = {}; int r; struct pakfire_find_deps_ctx ctx = { @@ -1137,7 +1137,7 @@ static int pakfire_build_add_scriptlet_requires(struct pakfire_build* build, }; return pakfire_jail_communicate(build->jail, argv, NULL, 0, - pakfire_pty_send_buffer, &buffer, pakfire_build_process_scriptlet_dep, &ctx); + pakfire_jail_send_buffer, &buffer, pakfire_build_process_scriptlet_dep, &ctx); } static int pakfire_build_package_add_scriptlet(struct pakfire_build* build, diff --git a/src/pakfire/jail.c b/src/pakfire/jail.c index 6d88b8d7..d91af07c 100644 --- a/src/pakfire/jail.c +++ b/src/pakfire/jail.c @@ -2262,3 +2262,29 @@ int pakfire_jail_run_systemd_tmpfiles(struct pakfire* pakfire) { return pakfire_jail_run_if_possible(pakfire, argv); } + +ssize_t pakfire_jail_send_buffer(struct pakfire_ctx* ctx, + void* data, char* buffer, size_t length) { + struct pakfire_input_buffer* input = data; + + // Check input + if (!input) + return -EINVAL; + + // If there is nothing left to send we are done + if (!input->length) + return 0; + + // Cap length if we have less data to send + if (input->length < length) + length = input->length; + + // Copy the data + memcpy(buffer, input->data, length); + + // Advance the buffer + input->data += length; + input->length -= length; + + return length; +} diff --git a/src/pakfire/jail.h b/src/pakfire/jail.h index a54c3bb3..2e2223c2 100644 --- a/src/pakfire/jail.h +++ b/src/pakfire/jail.h @@ -96,4 +96,13 @@ int pakfire_jail_shell(struct pakfire_jail* jail, struct pakfire_env* env); int pakfire_jail_ldconfig(struct pakfire* pakfire); int pakfire_jail_run_systemd_tmpfiles(struct pakfire* pakfire); +// Streaming functions +struct pakfire_input_buffer { + const char* data; + size_t length; +}; + +ssize_t pakfire_jail_send_buffer(struct pakfire_ctx* ctx, + void* data, char* buffer, size_t length); + #endif /* PAKFIRE_JAIL_H */ diff --git a/src/pakfire/pty.c b/src/pakfire/pty.c index 8541c50d..f35d2f6c 100644 --- a/src/pakfire/pty.c +++ b/src/pakfire/pty.c @@ -1207,32 +1207,6 @@ int pakfire_pty_open(struct pakfire_pty* pty) { return 0; } -ssize_t pakfire_pty_send_buffer(struct pakfire_ctx* ctx, - void* data, char* buffer, size_t length) { - struct pakfire_pty_buffer* input = data; - - // Check input - if (!input) - return -EINVAL; - - // If there is nothing left to send we are done - if (!input->length) - return 0; - - // Cap length if we have less data to send - if (input->length < length) - length = input->length; - - // Copy the data - memcpy(buffer, input->data, length); - - // Advance the buffer - input->data += length; - input->length -= length; - - return length; -} - ssize_t pakfire_pty_send_filelist(struct pakfire_ctx* ctx, void* data, char* buffer, size_t length) { struct pakfire_pty_filelist* input = data; diff --git a/src/pakfire/pty.h b/src/pakfire/pty.h index 8acdffe5..50b24675 100644 --- a/src/pakfire/pty.h +++ b/src/pakfire/pty.h @@ -37,17 +37,6 @@ struct pakfire_pty* pakfire_pty_unref(struct pakfire_pty* pty); int pakfire_pty_open(struct pakfire_pty* pty); -typedef int (*pakfire_pty_stdout_callback)( - struct pakfire_ctx* ctx, void* data, const char* line, const size_t length); - -struct pakfire_pty_buffer { - const char* data; - size_t length; -}; - -ssize_t pakfire_pty_send_buffer(struct pakfire_ctx* ctx, - void* data, char* buffer, size_t length); - // Stream a filelist struct pakfire_pty_filelist { diff --git a/src/python/pakfire.c b/src/python/pakfire.c index 77f91eb8..5bb720aa 100644 --- a/src/python/pakfire.c +++ b/src/python/pakfire.c @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include @@ -555,7 +554,7 @@ static int Pakfire_execute_stdout_callback(struct pakfire_ctx* ctx, void* data, } static PyObject* Pakfire_execute(PakfireObject* self, PyObject* args, PyObject* kwargs) { - struct pakfire_pty_buffer input = {}; + struct pakfire_input_buffer input = {}; struct pakfire_jail* jail = NULL; struct pakfire_env* env = NULL; const char** argv = NULL; @@ -661,7 +660,7 @@ static PyObject* Pakfire_execute(PakfireObject* self, PyObject* args, PyObject* // Register the input callback if (input.data) - input_callback = pakfire_pty_send_buffer; + input_callback = pakfire_jail_send_buffer; // Create a new jail r = pakfire_jail_create(&jail, self->pakfire);