From: Michael Tremer Date: Wed, 13 Jan 2021 23:08:50 +0000 (+0000) Subject: libpakfire: Add pakfire_execute_command X-Git-Tag: 0.9.28~1285^2~863 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4c574ffcac4d17113bfee41f39c92ad0c6520a89;p=pakfire.git libpakfire: Add pakfire_execute_command 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 --- diff --git a/src/libpakfire/execute.c b/src/libpakfire/execute.c index e62116e0f..fa4f5256d 100644 --- a/src/libpakfire/execute.c +++ b/src/libpakfire/execute.c @@ -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); +} diff --git a/src/libpakfire/include/pakfire/execute.h b/src/libpakfire/include/pakfire/execute.h index 94f737d8a..6fef62c17 100644 --- a/src/libpakfire/include/pakfire/execute.h +++ b/src/libpakfire/include/pakfire/execute.h @@ -24,5 +24,6 @@ #include 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 */ diff --git a/src/libpakfire/libpakfire.sym b/src/libpakfire/libpakfire.sym index 531ce6d04..3331d3e50 100644 --- a/src/libpakfire/libpakfire.sym +++ b/src/libpakfire/libpakfire.sym @@ -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; diff --git a/src/libpakfire/step.c b/src/libpakfire/step.c index 8642927bc..321fb614c 100644 --- a/src/libpakfire/step.c +++ b/src/libpakfire/step.c @@ -39,9 +39,7 @@ #include #include -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); }