]> git.ipfire.org Git - pakfire.git/commitdiff
env: Create its own type
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Jun 2025 10:47:19 +0000 (10:47 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Jun 2025 10:47:19 +0000 (10:47 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/build.c
src/pakfire/env.c
src/pakfire/env.h
src/pakfire/jail.c
src/pakfire/jail.h
src/pakfire/parser.c
src/pakfire/parser.h
src/python/pakfire.c
tests/libpakfire/env.c

index 98bf25de76e628e8e050f1f7ba6c1c9522736c2b..e2825396f6a1cfb68cc5894a3bca2d31e3d86050 100644 (file)
@@ -88,7 +88,7 @@ struct pakfire_build {
        struct pakfire_jail* jail;
 
        // Environment
-       struct pakfire_env* env;
+       pakfire_env* env;
 
        // The build repository
        struct pakfire_repo* repo;
@@ -440,7 +440,7 @@ static int pakfire_build_find_pkgconfig_provides(
 
 static int pakfire_build_find_pkgconfig_requires(
                pakfire_ctx* ctx, struct pakfire_file* file, struct pakfire_find_deps_ctx* deps) {
-       struct pakfire_env* env = NULL;
+       pakfire_env* env = NULL;
        int r;
 
        // Fetch the absolute path
@@ -1378,7 +1378,7 @@ ERROR:
 
 static int pakfire_build_stage(pakfire_build* build,
                struct pakfire_parser* makefile, const char* stage) {
-       struct pakfire_env* env = NULL;
+       pakfire_env* env = NULL;
        char* script = NULL;
        char template[1024];
        int r;
index ab1a0f1f67d1e5acfcfbf7e06351ed3688465183..9d0faf3aaa47c259513370b2415ad2802f1e22d3 100644 (file)
@@ -34,7 +34,7 @@ struct pakfire_env {
        char* env[ENVIRON_SIZE];
 };
 
-static void pakfire_env_free(struct pakfire_env* env) {
+static void pakfire_env_free(pakfire_env* env) {
        // Free environment
        for (unsigned int i = 0; env->env[i]; i++)
                free(env->env[i]);
@@ -44,8 +44,8 @@ static void pakfire_env_free(struct pakfire_env* env) {
        free(env);
 }
 
-int pakfire_env_create(struct pakfire_env** env, pakfire_ctx* ctx) {
-       struct pakfire_env* e = NULL;
+int pakfire_env_create(pakfire_env** env, pakfire_ctx* ctx) {
+       pakfire_env* e = NULL;
 
        // Allocate a new environment
        e = calloc(1, sizeof(*e));
@@ -64,13 +64,13 @@ int pakfire_env_create(struct pakfire_env** env, pakfire_ctx* ctx) {
        return 0;
 }
 
-struct pakfire_env* pakfire_env_ref(struct pakfire_env* env) {
+pakfire_env* pakfire_env_ref(pakfire_env* env) {
        ++env->nrefs;
 
        return env;
 }
 
-struct pakfire_env* pakfire_env_unref(struct pakfire_env* env) {
+pakfire_env* pakfire_env_unref(pakfire_env* env) {
        if (--env->nrefs > 0)
                return env;
 
@@ -78,7 +78,7 @@ struct pakfire_env* pakfire_env_unref(struct pakfire_env* env) {
        return NULL;
 }
 
-char** pakfire_env_get_envp(struct pakfire_env* env) {
+char** pakfire_env_get_envp(pakfire_env* env) {
        if (!env->env[0])
                return NULL;
 
@@ -86,7 +86,7 @@ char** pakfire_env_get_envp(struct pakfire_env* env) {
 }
 
 // Returns the length of the environment
-static unsigned int pakfire_env_length(struct pakfire_env* env) {
+static unsigned int pakfire_env_length(pakfire_env* env) {
        unsigned int i = 0;
 
        // Count everything in the environment
@@ -97,7 +97,7 @@ static unsigned int pakfire_env_length(struct pakfire_env* env) {
 }
 
 // Finds an existing environment variable and returns its index or -1 if not found
-static int pakfire_env_find(struct pakfire_env* env, const char* key) {
+static int pakfire_env_find(pakfire_env* env, const char* key) {
        if (!key)
                return -EINVAL;
 
@@ -115,7 +115,7 @@ static int pakfire_env_find(struct pakfire_env* env, const char* key) {
 }
 
 // Returns the value of an environment variable or NULL
-const char* pakfire_env_get(struct pakfire_env* env, const char* key) {
+const char* pakfire_env_get(pakfire_env* env, const char* key) {
        int i = pakfire_env_find(env, key);
        if (i < 0)
                return NULL;
@@ -124,7 +124,7 @@ const char* pakfire_env_get(struct pakfire_env* env, const char* key) {
 }
 
 // Sets an environment variable
-int pakfire_env_set(struct pakfire_env* env, const char* key, const char* format, ...) {
+int pakfire_env_set(pakfire_env* env, const char* key, const char* format, ...) {
        char value[PATH_MAX];
        va_list args;
        int r;
@@ -162,7 +162,7 @@ int pakfire_env_set(struct pakfire_env* env, const char* key, const char* format
 }
 
 // Appends something to an environment variable, separated by :
-int pakfire_env_append(struct pakfire_env* env, const char* key, const char* format, ...) {
+int pakfire_env_append(pakfire_env* env, const char* key, const char* format, ...) {
        const char* old_value = NULL;
        char value[PATH_MAX];
        va_list args;
@@ -187,7 +187,7 @@ int pakfire_env_append(struct pakfire_env* env, const char* key, const char* for
 }
 
 // Imports an environment
-int pakfire_env_import(struct pakfire_env* env, const char** e) {
+int pakfire_env_import(pakfire_env* env, const char** e) {
        char* key = NULL;
        char* val = NULL;
        int r;
@@ -218,6 +218,6 @@ int pakfire_env_import(struct pakfire_env* env, const char** e) {
        return 0;
 }
 
-int pakfire_env_merge(struct pakfire_env* env1, struct pakfire_env* env2) {
+int pakfire_env_merge(pakfire_env* env1, pakfire_env* env2) {
        return pakfire_env_import(env1, (const char**)env2->env);
 }
index 05fbe438b021e322aef61ded998d4dc74ce25f31..52fb33f8cbcd221b22b70c4f0f80e29322efb3b7 100644 (file)
 #ifndef PAKFIRE_ENV_H
 #define PAKFIRE_ENV_H
 
-struct pakfire_env;
+typedef struct pakfire_env pakfire_env;
 
 #include <pakfire/ctx.h>
 
-int pakfire_env_create(struct pakfire_env** env, pakfire_ctx* ctx);
+int pakfire_env_create(pakfire_env** env, pakfire_ctx* ctx);
 
-struct pakfire_env* pakfire_env_ref(struct pakfire_env* env);
-struct pakfire_env* pakfire_env_unref(struct pakfire_env* env);
+pakfire_env* pakfire_env_ref(pakfire_env* env);
+pakfire_env* pakfire_env_unref(pakfire_env* env);
 
-char** pakfire_env_get_envp(struct pakfire_env* env);
+char** pakfire_env_get_envp(pakfire_env* env);
 
-const char* pakfire_env_get(struct pakfire_env* env, const char* key);
-int pakfire_env_set(struct pakfire_env* env, const char* key, const char* format, ...)
+const char* pakfire_env_get(pakfire_env* env, const char* key);
+int pakfire_env_set(pakfire_env* env, const char* key, const char* format, ...)
        __attribute__((format(printf, 3, 4)));
-int pakfire_env_append(struct pakfire_env* env, const char* key, const char* format, ...)
+int pakfire_env_append(pakfire_env* env, const char* key, const char* format, ...)
        __attribute__((format(printf, 3, 4)));
 
-int pakfire_env_import(struct pakfire_env* env, const char** e);
+int pakfire_env_import(pakfire_env* env, const char** e);
 
-int pakfire_env_merge(struct pakfire_env* env1, struct pakfire_env* env2);
+int pakfire_env_merge(pakfire_env* env1, pakfire_env* env2);
 
 #endif /* PAKFIRE_ENV_H */
index d28c037e8002129c6bec21fa654722d8feba23f5..cb820b1e5518a250b8dae0194ee91f61ae41a222 100644 (file)
@@ -108,7 +108,7 @@ struct pakfire_jail {
        pakfire_cgroup* cgroup;
 
        // Environment
-       struct pakfire_env* env;
+       pakfire_env* env;
 
        // Mountpoints
        struct pakfire_jail_mountpoint mountpoints[MAX_MOUNTPOINTS];
@@ -1221,12 +1221,12 @@ static int pakfire_jail_exited(sd_event_source* source, const siginfo_t* si, voi
 struct pakfire_jail_command {
        struct pakfire_jail* jail;
        const char** argv;
-       struct pakfire_env* env;
+       pakfire_env* env;
 };
 
 static int pakfire_jail_launch_command(pakfire_ctx* ctx, void* data) {
        struct pakfire_jail_command* command = data;
-       struct pakfire_env* env = NULL;
+       pakfire_env* env = NULL;
        char** envp = NULL;
        int r;
 
@@ -2044,7 +2044,7 @@ int pakfire_jail_exec(struct pakfire_jail* jail,
 }
 
 int pakfire_jail_exec_command(struct pakfire_jail* jail,
-               const char* argv[], struct pakfire_env* env, int flags) {
+               const char* argv[], pakfire_env* env, int flags) {
        struct pakfire_jail_command command = {
                .jail = jail,
                .argv = argv,
@@ -2056,7 +2056,7 @@ int pakfire_jail_exec_command(struct pakfire_jail* jail,
 }
 
 int pakfire_jail_exec_capture_output(struct pakfire_jail* jail,
-               const char* argv[], struct pakfire_env* env, int flags, char** output, size_t* length) {
+               const char* argv[], pakfire_env* env, int flags, char** output, size_t* length) {
        struct pakfire_jail_command command = {
                .jail = jail,
                .argv = argv,
@@ -2068,7 +2068,7 @@ int pakfire_jail_exec_capture_output(struct pakfire_jail* jail,
 }
 
 int pakfire_jail_communicate(
-               struct pakfire_jail* jail, const char* argv[], struct pakfire_env* env, int flags,
+               struct pakfire_jail* jail, const char* argv[], pakfire_env* env, int flags,
                pakfire_jail_input_callback input_callback, void* input_data,
                pakfire_jail_output_callback output_callback, void* output_data) {
        struct pakfire_jail_command command = {
@@ -2082,7 +2082,7 @@ int pakfire_jail_communicate(
 }
 
 int pakfire_jail_exec_script(struct pakfire_jail* jail,
-               const char* script, const size_t size, const char* args[], struct pakfire_env* env,
+               const char* script, const size_t size, const char* args[], pakfire_env* env,
                pakfire_jail_input_callback input_callback, void* input_data,
                pakfire_jail_output_callback output_callback, void* output_data) {
        char path[PATH_MAX];
@@ -2163,7 +2163,7 @@ ERROR:
        A convenience function that creates a new jail, runs the given command and destroys
        the jail again.
 */
-int pakfire_jail_run(struct pakfire* pakfire, const char* argv[], struct pakfire_env* env,
+int pakfire_jail_run(struct pakfire* pakfire, const char* argv[], pakfire_env* env,
                int flags, char** output, size_t* output_length) {
        struct pakfire_jail* jail = NULL;
        int r;
@@ -2184,7 +2184,7 @@ ERROR:
 }
 
 int pakfire_jail_run_script(struct pakfire* pakfire, const char* script, const size_t length,
-               const char* argv[], struct pakfire_env* env, int flags) {
+               const char* argv[], pakfire_env* env, int flags) {
        struct pakfire_jail* jail = NULL;
        int r;
 
@@ -2203,8 +2203,8 @@ ERROR:
        return r;
 }
 
-int pakfire_jail_shell(struct pakfire_jail* jail, struct pakfire_env* e) {
-       struct pakfire_env* env = NULL;
+int pakfire_jail_shell(struct pakfire_jail* jail, pakfire_env* e) {
+       pakfire_env* env = NULL;
        int r;
 
        const char* argv[] = {
index 7255684ff53b501f9991e521b8f98be3bcee7094..7cd4bd6d6ef90bc83b2c7202727c5119e869a9b5 100644 (file)
@@ -68,31 +68,31 @@ int pakfire_jail_exec(struct pakfire_jail* jail,
        pakfire_jail_main_callback callback, void* data, int flags);
 
 int pakfire_jail_exec_command(struct pakfire_jail* jail,
-       const char* argv[], struct pakfire_env* env, int flags);
+       const char* argv[], pakfire_env* env, int flags);
 
 int pakfire_jail_exec_capture_output(struct pakfire_jail* jail,
-       const char* argv[], struct pakfire_env* env, int flags, char** output, size_t* length);
+       const char* argv[], pakfire_env* env, int flags, char** output, size_t* length);
 
 // Resource limits
 int pakfire_jail_set_cgroup(struct pakfire_jail* jail, pakfire_cgroup* cgroup);
 
 int pakfire_jail_communicate(
-       struct pakfire_jail* jail, const char* argv[], struct pakfire_env* env, int flags,
+       struct pakfire_jail* jail, const char* argv[], pakfire_env* env, int flags,
        pakfire_jail_input_callback input_callback, void* input_data,
        pakfire_jail_output_callback output_callback, void* output_data);
 
 // Convenience functions
 int pakfire_jail_run(struct pakfire* pakfire,
-       const char* argv[], struct pakfire_env* env, int flags, char** output, size_t* output_length);
+       const char* argv[], pakfire_env* env, int flags, char** output, size_t* output_length);
 int pakfire_jail_run_script(struct pakfire* pakfire,
-       const char* script, const size_t length, const char* argv[], struct pakfire_env* env, int flags);
+       const char* script, const size_t length, const char* argv[], pakfire_env* env, int flags);
 
 int pakfire_jail_exec_script(struct pakfire_jail* jail,
-       const char* script, const size_t size, const char* args[], struct pakfire_env* env,
+       const char* script, const size_t size, const char* args[], pakfire_env* env,
        pakfire_jail_input_callback input_callback, void* input_data,
        pakfire_jail_output_callback output_callback, void* output_data);
 
-int pakfire_jail_shell(struct pakfire_jail* jail, struct pakfire_env* env);
+int pakfire_jail_shell(struct pakfire_jail* jail, pakfire_env* env);
 int pakfire_jail_ldconfig(struct pakfire* pakfire);
 int pakfire_jail_run_systemd_tmpfiles(struct pakfire* pakfire);
 
index a99d06c030c6ed1930e345eea1ae076ba03cde10..8a6bfb40c339d2d83ed13fc878456bf46b8fcef9 100644 (file)
@@ -1010,7 +1010,7 @@ int pakfire_parser_set_namespace(struct pakfire_parser* parser, const char* name
        return pakfire_string_set(parser->namespace, namespace);
 }
 
-int pakfire_parser_set_env(struct pakfire_parser* parser, struct pakfire_env* env) {
+int pakfire_parser_set_env(struct pakfire_parser* parser, pakfire_env* env) {
        struct pakfire_parser_declaration* d = NULL;
        char* value = NULL;
        int r;
index d0cf9275a913707655dd5226a6872b996f663e63..37dd96d831ccf803e2cc6908e0678fbda768c3ff 100644 (file)
@@ -112,6 +112,6 @@ int pakfire_parser_apply_declaration(
 int pakfire_parser_parse_data(struct pakfire_parser* parent, const char* data, size_t len,
        struct pakfire_parser_error** error);
 
-int pakfire_parser_set_env(struct pakfire_parser* parser, struct pakfire_env* env);
+int pakfire_parser_set_env(struct pakfire_parser* parser, pakfire_env* env);
 
 #endif /* PAKFIRE_PARSER_H */
index 00837c61668b53a2a27e49e1783f1541b95264bd..5dbdac3213362ba4a8edff626e717c080f90188a 100644 (file)
@@ -566,7 +566,7 @@ static int Pakfire_execute_stdout_callback(pakfire_ctx* ctx, void* data,
 static PyObject* Pakfire_execute(PakfireObject* self, PyObject* args, PyObject* kwargs) {
        struct pakfire_input_buffer input = {};
        struct pakfire_jail* jail = NULL;
-       struct pakfire_env* env = NULL;
+       pakfire_env* env = NULL;
        PyObject* mountpoint = NULL;
        const char** argv = NULL;
        PyObject* bind = NULL;
index 9544ec8ef7ebfa933ea68fe31b4ea73c8cee6bfa..f347b309f66bda3d14073d6939046af995d56e79 100644 (file)
@@ -23,7 +23,7 @@
 #include "../testsuite.h"
 
 static int test_set_get(const struct test* t) {
-       struct pakfire_env* env = NULL;
+       pakfire_env* env = NULL;
        int r = EXIT_FAILURE;
 
        // Create the environment
@@ -49,8 +49,8 @@ FAIL:
 }
 
 static int test_merge(const struct test* t) {
-       struct pakfire_env* env1 = NULL;
-       struct pakfire_env* env2 = NULL;
+       pakfire_env* env1 = NULL;
+       pakfire_env* env2 = NULL;
        int r = EXIT_FAILURE;
 
        // Create the environments