]> git.ipfire.org Git - pakfire.git/commitdiff
jail: Move the send buffer function from the PTY
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 24 Mar 2025 19:34:46 +0000 (19:34 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 24 Mar 2025 19:34:46 +0000 (19:34 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/build.c
src/pakfire/jail.c
src/pakfire/jail.h
src/pakfire/pty.c
src/pakfire/pty.h
src/python/pakfire.c

index 4ac347844191bdd0b63dc2cdcc66e0956e0faa68..56b5d993027c8b74790c167b79d07aa93b84dbaa 100644 (file)
@@ -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,
index 6d88b8d7e91794c1f07636adac47dfed9a0bae51..d91af07ce6f8ede6b01c0c149d7aa520cc577883 100644 (file)
@@ -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;
+}
index a54c3bb3ca304f0b9108f62d4ac54d319a8930dc..2e2223c2119850fd4994edaa454e059c1fcc7884 100644 (file)
@@ -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 */
index 8541c50dd4bcb1a9726f1c5a626f01d25829ad2c..f35d2f6cfc4a64c302ed24cb4cd9c5ac1e533a42 100644 (file)
@@ -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;
index 8acdffe5872475fa242d8cf02bd61c55c2c9ecf0..50b246756556b54e6af393aac4aa089634f44147 100644 (file)
@@ -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 {
index 77f91eb8234829d26244de9a845ceb819f4470e6..5bb720aabb4137f7ec7869378ec758cbc0a33b52 100644 (file)
@@ -34,7 +34,6 @@
 #include <pakfire/mount.h>
 #include <pakfire/packagelist.h>
 #include <pakfire/pakfire.h>
-#include <pakfire/pty.h>
 #include <pakfire/key.h>
 #include <pakfire/repo.h>
 #include <pakfire/repolist.h>
@@ -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);