From: Michael Tremer Date: Fri, 18 Aug 2023 16:28:48 +0000 (+0000) Subject: Move all static buffers into Thread-local storage X-Git-Tag: 0.9.29~70 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=18684c4d86b2fe80951a4104d890561e676e338b;p=pakfire.git Move all static buffers into Thread-local storage Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/arch.c b/src/libpakfire/arch.c index 5fb842056..2dc62585c 100644 --- a/src/libpakfire/arch.c +++ b/src/libpakfire/arch.c @@ -163,19 +163,19 @@ int __pakfire_arch_buildtarget(char* buffer, size_t length, const char* arch, co return 0; } -static const char* __pakfire_arch_native = NULL; - PAKFIRE_EXPORT const char* pakfire_arch_native() { struct utsname buf; - if (!__pakfire_arch_native) { + static __thread const char* arch_native = NULL; + + if (!arch_native) { if (uname(&buf) < 0) return NULL; - __pakfire_arch_native = strdup(buf.machine); + arch_native = strdup(buf.machine); } - return __pakfire_arch_native; + return arch_native; } int pakfire_arch_is_compatible(const char* name, const char* compatible_arch) { diff --git a/src/libpakfire/cgroup.c b/src/libpakfire/cgroup.c index 3f6e05854..ed00f6df3 100644 --- a/src/libpakfire/cgroup.c +++ b/src/libpakfire/cgroup.c @@ -34,7 +34,7 @@ #include #include -static char bpf_log_buffer[BPF_LOG_BUF_SIZE]; +static __thread char bpf_log_buffer[BPF_LOG_BUF_SIZE]; #define BUFFER_SIZE 64 * 1024 diff --git a/src/libpakfire/util.c b/src/libpakfire/util.c index 2faefe573..090be50e1 100644 --- a/src/libpakfire/util.c +++ b/src/libpakfire/util.c @@ -372,14 +372,14 @@ char* pakfire_remove_trailing_newline(char* str) { return str; } -static char __hostname[256]; - const char* pakfire_hostname() { - int r = gethostname(__hostname, sizeof(__hostname)); + static __thread char hostname[256]; + + int r = gethostname(hostname, sizeof(hostname)); if (r) return NULL; - return __hostname; + return hostname; } int pakfire_read_file_into_buffer(FILE* f, char** buffer, size_t* len) {