Fix pcl-0c1: make pdbg_runtime_level atomic (#343)

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
This commit is contained in:
Levi Neely 2026-03-03 20:08:18 +01:00 committed by GitHub
parent 5ce7118a35
commit ede53b6b89
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 14 deletions

View File

@ -35,29 +35,31 @@ static void pdbg_init_level(void) {
const char *level_str = getenv("PCLOUD_LOG_LEVEL");
if (!level_str || level_str[0] == '\0') {
pdbg_runtime_level = D_INFO; /* default to INFO */
__atomic_store_n(&pdbg_runtime_level, D_INFO, __ATOMIC_RELAXED);
return;
}
unsigned int level;
/* Parse log level string (case-insensitive) */
if (strcasecmp(level_str, "NONE") == 0) {
pdbg_runtime_level = D_NONE;
level = D_NONE;
} else if (strcasecmp(level_str, "BUG") == 0 || strcasecmp(level_str, "DEBUG") == 0) {
pdbg_runtime_level = D_BUG;
level = D_BUG;
} else if (strcasecmp(level_str, "CRITICAL") == 0) {
pdbg_runtime_level = D_CRITICAL;
level = D_CRITICAL;
} else if (strcasecmp(level_str, "ERROR") == 0) {
pdbg_runtime_level = D_ERROR;
level = D_ERROR;
} else if (strcasecmp(level_str, "WARNING") == 0 || strcasecmp(level_str, "WARN") == 0) {
pdbg_runtime_level = D_WARNING;
level = D_WARNING;
} else if (strcasecmp(level_str, "INFO") == 0) {
pdbg_runtime_level = D_INFO;
level = D_INFO;
} else if (strcasecmp(level_str, "NOTICE") == 0) {
pdbg_runtime_level = D_NOTICE;
level = D_NOTICE;
} else {
/* Invalid level, default to INFO */
pdbg_runtime_level = D_INFO;
level = D_INFO;
}
__atomic_store_n(&pdbg_runtime_level, level, __ATOMIC_RELAXED);
}
char *psync_debug_path() {

View File

@ -1,14 +1,14 @@
#ifndef __PDBG_H
#define __PDBG_H
#ifdef __cplusplus
extern "C" {
#endif
#include "pcompiler.h"
#include "putil.h" // need for macros...
#include "psynclib.h" // need for macros...
#ifdef __cplusplus
extern "C" {
#endif
#define D_NONE 0
#define D_CRITICAL 10
@ -36,7 +36,7 @@ extern unsigned int pdbg_runtime_level;
#define pdbg_logf(level, ...) \
do { \
if (level <= pdbg_runtime_level) \
if (level <= __atomic_load_n(&pdbg_runtime_level, __ATOMIC_RELAXED)) \
pdbg_printf(__FILE__, __FUNCTION__, __LINE__, level, __VA_ARGS__); \
} while (0)
#define pdbg_assert(cond) \