]> git.ipfire.org Git - pakfire.git/commitdiff
python: execute: Implement setting the nice value
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 17 Mar 2025 11:22:58 +0000 (11:22 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 17 Mar 2025 11:22:58 +0000 (11:22 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/pakfire.c
tests/python/execute.py

index 783ffdfa9dda6c26ef3a47aa1d3a5a6ecbae0297..6ccbda93b0dba3f9a0c3b9851960cbf55935d4f8 100644 (file)
@@ -544,15 +544,18 @@ static PyObject* Pakfire_execute(PakfireObject* self, PyObject* args, PyObject*
 
        PyObject* command = NULL;
        PyObject* environ = NULL;
+       int nice = 0;
 
        const char* kwlist[] = {
                "command",
                "environ",
+               "nice",
                NULL,
        };
 
        // Parse arguments
-       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O", (char**)kwlist, &command, &environ))
+       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|Oi", (char**)kwlist,
+                       &command, &environ, &nice))
                goto ERROR;
 
        // Check if command is a list
@@ -629,6 +632,16 @@ static PyObject* Pakfire_execute(PakfireObject* self, PyObject* args, PyObject*
                goto ERROR;
        }
 
+       // Set the nice level
+       if (nice) {
+               r = pakfire_jail_nice(jail, nice);
+               if (r < 0) {
+                       errno = -r;
+                       PyErr_SetFromErrno(PyExc_OSError);
+                       goto ERROR;
+               }
+       }
+
        Py_BEGIN_ALLOW_THREADS
 
        // Execute command
index f3ddad9fd604506ee91dbbf03c6b2c6f15fb6cda..e2f8a2689d02e0c2d2e688905e541e1e6dd66dfc 100755 (executable)
@@ -92,15 +92,15 @@ class ExecuteTests(tests.TestCase):
                # Run a command that generates lots of lines
                self.pakfire.execute(["/command", "lines", "100", "40"])
 
-       #def test_nice(self):
-       #       self.pakfire.execute(["/command", "print-nice"], nice=5)
+       def test_nice(self):
+               self.pakfire.execute(["/command", "print-nice"], nice=5)
 
-       #def test_nice_invalid_input(self):
-       #       """
-       #               Tries using an invalid nice value
-       #       """
-       #       with self.assertRaises(OSError):
-       #               self.pakfire.execute(["/command", "print-nice"], nice=100)
+       def test_nice_invalid_input(self):
+               """
+                       Tries using an invalid nice value
+               """
+               with self.assertRaises(OSError):
+                       self.pakfire.execute(["/command", "print-nice"], nice=100)
 
        #def test_check_open_file_descriptors(self):
        #       """