Skip to content

Commit

Permalink
config: configure globabbly variables
Browse files Browse the repository at this point in the history
static boolean caused a race condition in threaded environnement
  • Loading branch information
bapt committed Feb 10, 2025
1 parent e52dd97 commit 2ab58f8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
8 changes: 1 addition & 7 deletions libpkg/pkg.c
Original file line number Diff line number Diff line change
Expand Up @@ -906,13 +906,7 @@ pkg_shlib_flags_from_abi(const struct pkg_abi *shlib_abi)
enum pkg_shlib_flags flags = PKG_SHLIB_FLAGS_NONE;

if (ctx.abi.os == PKG_OS_FREEBSD) {
static bool check_track_linux_compat_shlibs = false;
static bool track_linux_compat_shlibs = false;
if (!check_track_linux_compat_shlibs) {
track_linux_compat_shlibs = pkg_object_bool(pkg_config_get("TRACK_LINUX_COMPAT_SHLIBS"));
check_track_linux_compat_shlibs = true;
}
if (shlib_abi->os == PKG_OS_LINUX && track_linux_compat_shlibs)
if (shlib_abi->os == PKG_OS_LINUX && ctx.track_linux_compat_shlibs)
flags |= PKG_SHLIB_FLAGS_COMPAT_LINUX;

switch (ctx.abi.arch) {
Expand Down
3 changes: 3 additions & 0 deletions libpkg/pkg_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ struct pkg_ctx ctx = {
.compression_level = -1,
.compression_threads = -1,
.defer_triggers = false,
.no_version_for_deps = false,
};

struct config_entry {
Expand Down Expand Up @@ -1502,6 +1503,8 @@ pkg_ini(const char *path, const char *reposdir, pkg_init_flags flags)
ctx.compression_threads = pkg_object_int(pkg_config_get("COMPRESSION_THREADS"));
ctx.archive_symlink = pkg_object_bool(pkg_config_get("ARCHIVE_SYMLINK"));
ctx.repo_accept_legacy_pkg = pkg_object_bool(pkg_config_get("REPO_ACCEPT_LEGACY_PKG"));
ctx.no_version_for_deps = (getenv("PKG_NO_VERSION_FOR_DEPS") != NULL);
ctx.track_linux_compat_shlibs = pkg_object_bool(pkg_config_get("TRACK_LINUX_COMPAT_SHLIBS"));

it = NULL;
object = ucl_object_find_key(config, "PKG_ENV");
Expand Down
11 changes: 2 additions & 9 deletions libpkg/pkg_manifest.c
Original file line number Diff line number Diff line change
Expand Up @@ -690,13 +690,6 @@ pkg_set_deps_from_object(struct pkg *pkg, const ucl_object_t *obj)
const char *origin = NULL;
const char *version = NULL;
const char *key, *okey;
bool noversion = false;
static bool noversion_env_check = false;

if (!noversion_env_check) {
noversion = (getenv("PKG_NO_VERSION_FOR_DEPS") != NULL);
noversion_env_check = true;
}

okey = ucl_object_key(obj);
if (okey == NULL)
Expand All @@ -711,7 +704,7 @@ pkg_set_deps_from_object(struct pkg *pkg, const ucl_object_t *obj)
if (cur->type != UCL_STRING) {
/* accept version to be an integer */
if (cur->type == UCL_INT && STRIEQ(key, "version")) {
if (!noversion)
if (!ctx.no_version_for_deps)
version = ucl_object_tostring_forced(cur);
continue;
}
Expand All @@ -722,7 +715,7 @@ pkg_set_deps_from_object(struct pkg *pkg, const ucl_object_t *obj)
}
if (STRIEQ(key, "origin"))
origin = ucl_object_tostring(cur);
if (STRIEQ(key, "version") && !noversion)
if (STRIEQ(key, "version") && !ctx.no_version_for_deps)
version = ucl_object_tostring(cur);
}
if (origin != NULL)
Expand Down
2 changes: 2 additions & 0 deletions libpkg/private/pkg.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ struct pkg_ctx {
ip_version_t ip;
struct pkg_abi abi;
bool ischrooted;
bool no_version_for_deps;
bool track_linux_compat_shlibs;
};

extern struct pkg_ctx ctx;
Expand Down

0 comments on commit 2ab58f8

Please sign in to comment.