]> git.ipfire.org Git - pakfire.git/commitdiff
python: execute: Use the send buffer callback we already have
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 22 Mar 2025 16:35:57 +0000 (16:35 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 22 Mar 2025 16:35:57 +0000 (16:35 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/pakfire.c

index 104bbe36690946b4d856c740dd22d6f996caaff9..e53587166e92228ef39937108ad8ff703dac0fb3 100644 (file)
@@ -533,33 +533,6 @@ ERROR:
  * Execute
  */
 
-struct Pakfire_execute_input {
-       const char* data;
-       size_t length;
-};
-
-static ssize_t Pakfire_execute_stdin_callback(
-               struct pakfire_ctx* ctx, void* data, char* buffer, size_t length) {
-       struct Pakfire_execute_input* input = data;
-
-       // Return zero if we are done writing the input
-       if (!input->length)
-               return 0;
-
-       // Cap the memory if we have less input
-       if (input->length < length)
-               length = input->length;
-
-       // Copy the data into the output buffer
-       memcpy(buffer, input->data, length);
-
-       // Move the pointer forward
-       input->data += length;
-       input->length -= length;
-
-       return length;
-}
-
 static int Pakfire_execute_stdout_callback(
                struct pakfire_ctx* ctx, void* data, const char* line, const size_t length) {
        PyObject** output = data;
@@ -577,7 +550,7 @@ static int Pakfire_execute_stdout_callback(
 }
 
 static PyObject* Pakfire_execute(PakfireObject* self, PyObject* args, PyObject* kwargs) {
-       struct Pakfire_execute_input input = {};
+       struct pakfire_pty_buffer input = {};
        struct pakfire_jail* jail = NULL;
        struct pakfire_env* env = NULL;
        const char** argv = NULL;
@@ -683,7 +656,7 @@ static PyObject* Pakfire_execute(PakfireObject* self, PyObject* args, PyObject*
 
        // Register the input callback
        if (input.data)
-               stdin_callback = Pakfire_execute_stdin_callback;
+               stdin_callback = pakfire_pty_send_buffer;
 
        // Create a new jail
        r = pakfire_jail_create(&jail, self->pakfire);