]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: Add pakfire_execute_command
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 13 Jan 2021 23:08:50 +0000 (23:08 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 13 Jan 2021 23:08:50 +0000 (23:08 +0000)
This is a convenience function when only a simple command without any
arguments is called and it saves us from allocating argv in the calling
function.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/execute.c
src/libpakfire/include/pakfire/execute.h
src/libpakfire/libpakfire.sym
src/libpakfire/step.c

index e62116e0fe294fc4a5c54dc7564376e65e69d1f1..fa4f5256ddb39f9d84a026b550a5737d9f6d8117 100644 (file)
@@ -119,3 +119,11 @@ PAKFIRE_EXPORT int pakfire_execute(Pakfire pakfire, const char* argv[], char* en
 
        return 0;
 }
+
+PAKFIRE_EXPORT int pakfire_execute_command(Pakfire pakfire, const char* command, char* envp[], int flags) {
+       const char* argv[2] = {
+               command, NULL,
+       };
+
+       return pakfire_execute(pakfire, argv, envp, flags);
+}
index 94f737d8a23070549727fcf3eb06914bf24ac284..6fef62c172fe69c54a786210278693b24c27f48e 100644 (file)
@@ -24,5 +24,6 @@
 #include <pakfire/types.h>
 
 int pakfire_execute(Pakfire pakfire, const char* argv[], char* envp[], int flags);
+int pakfire_execute_command(Pakfire pakfire, const char* command, char* envp[], int flags);
 
 #endif /* PAKFIRE_EXECUTE_H */
index 531ce6d04984f7103e90a6b6d82b478e7dd5768e..3331d3e504fc2c49af177e6daf5496dbb5cc675d 100644 (file)
@@ -26,6 +26,7 @@ global:
        pakfire_count_packages;
        pakfire_create;
        pakfire_execute;
+       pakfire_execute_command;
        pakfire_get_arch;
        pakfire_get_cache_path;
        pakfire_get_installed_repo;
index 8642927bc10535446875a8f6bb3f0f284c1e7a27..321fb614c75790fe337ed33176c6099ac9c54edb 100644 (file)
@@ -39,9 +39,7 @@
 #include <pakfire/types.h>
 #include <pakfire/util.h>
 
-static const char* LDCONFIG[2] = {
-       "/sbin/ldconfig", NULL,
-};
+#define LDCONFIG "/sbin/ldconfig"
 
 struct _PakfireStep {
        Pakfire pakfire;
@@ -366,12 +364,8 @@ static int pakfire_step_run_shell_script(PakfireStep step, const char* data, con
        if (root)
                command = pakfire_path_relpath(root, path);
 
-       const char* argv[2];
-       argv[0] = command;
-       argv[1] = NULL;
-
        // Run the script
-       r = pakfire_execute(step->pakfire, argv, NULL, 0);
+       r = pakfire_execute_command(step->pakfire, command, NULL, 0);
        if (r) {
                DEBUG(step->pakfire, "Script return code: %d\n", r);
        }
@@ -427,8 +421,8 @@ static int pakfire_run_ldconfig(PakfireStep step) {
 
        const char* path = pakfire_get_path(step->pakfire);
 
-       if (pakfire_access(step->pakfire, path, LDCONFIG[0], X_OK) == 0) {
-               r = pakfire_execute(step->pakfire, LDCONFIG, NULL, 0);
+       if (pakfire_access(step->pakfire, path, LDCONFIG, X_OK) == 0) {
+               r = pakfire_execute_command(step->pakfire, LDCONFIG, NULL, 0);
 
                DEBUG(step->pakfire, "ldconfig returned %d\n", r);
        }