Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common: print basic lib info when new logging function is set #6021

Merged
merged 4 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/core/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@
core_log_default_fini();
}

static void
core_log_lib_info(void)
{
CORE_LOG_HARK("src version: " SRCVERSION);
#if SDS_ENABLED
CORE_LOG_HARK("compiled with support for shutdown state");
#endif
#if NDCTL_ENABLED
CORE_LOG_HARK("compiled with libndctl 63+");
#endif
}
/*
* core_log_set_function -- set the log function pointer either to
* a user-provided function pointer or to the default logging function.
Expand All @@ -127,10 +138,12 @@
core_log_function_old, (uintptr_t)log_function))
return EAGAIN;
if (__sync_bool_compare_and_swap(&Core_log_function_context,
context_old, context))
context_old, context)) {
core_log_lib_info();
return 0;
}

__sync_bool_compare_and_swap(&Core_log_function,
(void) __sync_bool_compare_and_swap(&Core_log_function,

Check warning on line 146 in src/core/log.c

View check run for this annotation

Codecov / codecov/patch

src/core/log.c#L146

Added line #L146 was not covered by tests
(uintptr_t)log_function, core_log_function_old);
return EAGAIN;

Expand Down
93 changes: 43 additions & 50 deletions src/core/out.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,32 +83,15 @@

Log_prefix = log_prefix;

#ifdef DEBUG
char *log_level;
char *log_file;
int log_level_cropped = 0;
int ret;

if ((log_level = os_getenv(log_level_var)) != NULL) {
Log_level = atoi(log_level);
if (Log_level < 0) {
Log_level = 0;
}
if (Log_level <= OUT_MAX_LEVEL) {
log_level_cropped = Log_level;
} else {
log_level_cropped = OUT_MAX_LEVEL;
}
}

if (log_level != NULL) {
ret = core_log_set_threshold(CORE_LOG_THRESHOLD,
level_to_core_log_level[log_level_cropped]);
if (ret) {
CORE_LOG_FATAL("Cannot set log threshold");
}
char *log_alignment = os_getenv("PMDK_LOG_ALIGN");
if (log_alignment) {
int align = atoi(log_alignment);
if (align > 0)
Log_alignment = (unsigned)align;

Check warning on line 90 in src/core/out.c

View check run for this annotation

Codecov / codecov/patch

src/core/out.c#L88-L90

Added lines #L88 - L90 were not covered by tests
}

#ifdef DEBUG
char *log_file;
if ((log_file = os_getenv(log_file_var)) != NULL &&
log_file[0] != '\0') {

Expand All @@ -133,6 +116,37 @@
abort();
}
}
#endif /* DEBUG */

if (Out_fp == NULL)
Out_fp = stderr;
else
setlinebuf(Out_fp);

#ifdef DEBUG
char *log_level;
int log_level_cropped = 0;
int ret;

if ((log_level = os_getenv(log_level_var)) != NULL) {
Log_level = atoi(log_level);
if (Log_level < 0) {
Log_level = 0;

Check warning on line 134 in src/core/out.c

View check run for this annotation

Codecov / codecov/patch

src/core/out.c#L134

Added line #L134 was not covered by tests
}
if (Log_level <= OUT_MAX_LEVEL) {
log_level_cropped = Log_level;
} else {
log_level_cropped = OUT_MAX_LEVEL;
}
}

if (log_level != NULL) {
ret = core_log_set_threshold(CORE_LOG_THRESHOLD,
level_to_core_log_level[log_level_cropped]);
if (ret) {
CORE_LOG_FATAL("Cannot set log threshold");

Check warning on line 147 in src/core/out.c

View check run for this annotation

Codecov / codecov/patch

src/core/out.c#L147

Added line #L147 was not covered by tests
}
}

if (log_level != NULL || log_file != NULL) {
ret = core_log_set_function(out_legacy, NULL);
Expand All @@ -142,29 +156,18 @@
}
#endif /* DEBUG */

char *log_alignment = os_getenv("PMDK_LOG_ALIGN");
if (log_alignment) {
int align = atoi(log_alignment);
if (align > 0)
Log_alignment = (unsigned)align;
}

if (Out_fp == NULL)
Out_fp = stderr;
else
setlinebuf(Out_fp);

/*
* Print library info
*/
#ifdef DEBUG
static char namepath[PATH_MAX];
CORE_LOG_HARK("pid %d: program: %s", getpid(),
util_getexecname(namepath, PATH_MAX));
#endif
#endif /* DEBUG */

CORE_LOG_HARK("%s version %d.%d", log_prefix, major_version,
minor_version);

static __attribute__((used)) const char *version_msg =
"src version: " SRCVERSION;
CORE_LOG_HARK("%s", version_msg);
#if VG_PMEMCHECK_ENABLED
/*
* Attribute "used" to prevent compiler from optimizing out the variable
Expand All @@ -189,16 +192,6 @@
"compiled with support for Valgrind drd";
CORE_LOG_HARK("%s", drd_msg);
#endif /* VG_DRD_ENABLED */
#if SDS_ENABLED
static __attribute__((used)) const char *shutdown_state_msg =
"compiled with support for shutdown state";
CORE_LOG_HARK("%s", shutdown_state_msg);
#endif
#if NDCTL_ENABLED
static __attribute__((used)) const char *ndctl_ge_63_msg =
"compiled with libndctl 63+";
CORE_LOG_HARK("%s", ndctl_ge_63_msg);
#endif

last_error_msg_init();
}
Expand Down
19 changes: 10 additions & 9 deletions src/test/arch_flags/log0.log.match
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<arch_flags>: <1> [$(nW) out_init]$(W)pid $(nW): program: $(nW)
<arch_flags>: <1> [$(nW) out_init]$(W)arch_flags version 0.0
<arch_flags>: <1> [$(nW) out_init]$(W)src version: $(nW)
$(OPT)<arch_flags>: <1> [$(nW) out_init]$(W)compiled with support for Valgrind pmemcheck
$(OPT)<arch_flags>: <1> [$(nW) out_init]$(W)compiled with support for Valgrind helgrind
$(OPT)<arch_flags>: <1> [$(nW) out_init]$(W)compiled with support for Valgrind memcheck
$(OPT)<arch_flags>: <1> [$(nW) out_init]$(W)compiled with support for Valgrind drd
$(OPT)<arch_flags>: <1> [$(nW) out_init]$(W)compiled with support for shutdown state
$(OPT)<arch_flags>: <1> [$(nW) out_init]$(W)compiled with libndctl 63+
<arch_flags>: <1> [$(*)]$(W)src version: $(nW)
$(OPT)<arch_flags>: <1> [$(*)]$(W)compiled with support for shutdown state
$(OPT)<arch_flags>: <1> [$(*)]$(W)compiled with libndctl 63+
<arch_flags>: <1> [$(*)]$(W)pid $(nW): program: $(nW)
<arch_flags>: <1> [$(*)]$(W)arch_flags version 0.0
<arch_flags>: <1> [$(*)]$(W)src version: $(nW)
$(OPT)<arch_flags>: <1> [$(*)]$(W)compiled with support for Valgrind pmemcheck
$(OPT)<arch_flags>: <1> [$(*)]$(W)compiled with support for Valgrind helgrind
$(OPT)<arch_flags>: <1> [$(*)]$(W)compiled with support for Valgrind memcheck
$(OPT)<arch_flags>: <1> [$(*)]$(W)compiled with support for Valgrind drd
<arch_flags>: <3> [$(nW) util_mmap_init]
<arch_flags>: <1> [$(nW) util_check_arch_flags]$(W)invalid machine value
<arch_flags>: <1> [$(nW) util_check_arch_flags]$(W)invalid machine_class value
Expand Down
6 changes: 3 additions & 3 deletions src/test/core_log_max/call_all.c.generated
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,9 @@ call_all_CORE_LOG_FATAL(void)
CORE_LOG_FATAL("os_thread_key_create");
// src/core/last_error_msg.c:78
CORE_LOG_FATAL("os_tls_set");
// src/core/out.c:113
// src/core/out.c:147
CORE_LOG_FATAL("Cannot set log threshold");
// src/core/out.c:145
// src/core/out.c:154
CORE_LOG_FATAL("Cannot set legacy log function");
// src/core/sys_util.h:108
CORE_LOG_FATAL("os_rwlock_init");
Expand Down Expand Up @@ -1000,7 +1000,7 @@ call_all_ERR_W_ERRNO(int errnum)
// src/common/vecq.h:68
ERR_W_ERRNO("Realloc");
UT_ASSERTeq(errno, errnum);
// src/core/out.c:126
// src/core/out.c:104
ERR_W_ERRNO("snprintf");
UT_ASSERTeq(errno, errnum);
// src/core/ravl.c:167
Expand Down
6 changes: 3 additions & 3 deletions src/test/out_err/traces0.log.match
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<trace>: <1> [$(*)]$(W)src version: $(nW)
$(OPT)<trace>: <1> [$(*)]$(W)compiled with support for shutdown state
$(OPT)<trace>: <1> [$(*)]$(W)compiled with libndctl 63+
<trace>: <1> [out.c:$(N) out_init]$(W)pid $(N): program: $(nW)
<trace>: <1> [out.c:$(N) out_init]$(W)trace version 1.0
<trace>: <1> [out.c:$(N) out_init]$(W)src version: $(nW)
$(OPT)<trace>: <1> [out.c:$(N) out_init]$(W)compiled with support for Valgrind pmemcheck
$(OPT)<trace>: <1> [out.c:$(N) out_init]$(W)compiled with support for Valgrind helgrind
$(OPT)<trace>: <1> [out.c:$(N) out_init]$(W)compiled with support for Valgrind memcheck
$(OPT)<trace>: <1> [out.c:$(N) out_init]$(W)compiled with support for Valgrind drd
$(OPT)<trace>: <1> [out.c:$(N) out_init]$(W)compiled with support for shutdown state
$(OPT)<trace>: <1> [out.c:$(N) out_init]$(W)compiled with libndctl 63+
<trace>: <1> [out_err$(nW).c:$(N) $(nW)main]$(W)ERR #1
$(OPT)<trace>: <1> [out_err$(nW).c:$(N) $(nW)main]$(W)ERR #2: Success
$(OPX)<trace>: <1> [out_err$(nW).c:$(N) $(nW)main]$(W)ERR #2: No error: 0
Expand Down
14 changes: 7 additions & 7 deletions src/test/traces/custom_file0.log.match
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
$(nW) <1> $(nW) $(nW) src version: $(nW)
$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for shutdown state
$(OPT)$(nW) <1> $(nW) $(nW) compiled with libndctl 63+
$(nW) <1> $(nW) $(nW) pid $(N): program: $(nW)
$(nW) <1> $(nW) $(nW) ut version 1.0
$(nW) <1> $(nW) $(nW) src version: $(nW)
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd
$(nW) <1> $(nW) $(nW) compiled with support for shutdown state
$(nW) <1> $(nW) $(nW) compiled with libndctl 63+
$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck
$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind
$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck
$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd
$(nW) <3> $(nW) $(nW)
$(nW) <1> $(nW) $(nW) Log level HARK
$(nW) <1> $(nW) $(nW) Log level ERROR
Expand Down
14 changes: 7 additions & 7 deletions src/test/traces/redir_stderr2.log.match
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
$(nW) <1> $(nW) $(nW) src version: $(nW)
$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for shutdown state
$(OPT)$(nW) <1> $(nW) $(nW) compiled with libndctl 63+
$(nW) <1> $(nW) $(nW) pid $(N): program: $(nW)
$(nW) <1> $(nW) $(nW) ut version 1.0
$(nW) <1> $(nW) $(nW) src version: $(nW)
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd
$(nW) <1> $(nW) $(nW) compiled with support for shutdown state
$(nW) <1> $(nW) $(nW) compiled with libndctl 63+
$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck
$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind
$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck
$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd
$(nW) <1> $(nW) $(nW) Log level HARK
$(nW) <1> $(nW) $(nW) Log level ERROR
14 changes: 7 additions & 7 deletions src/test/traces/redir_stderr3.log.match
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
$(nW) <1> $(nW) $(nW) src version: $(nW)
$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for shutdown state
$(OPT)$(nW) <1> $(nW) $(nW) compiled with libndctl 63+
$(nW) <1> $(nW) $(nW) pid $(N): program: $(nW)
$(nW) <1> $(nW) $(nW) ut version 1.0
$(nW) <1> $(nW) $(nW) src version: $(nW)
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd
$(nW) <1> $(nW) $(nW) compiled with support for shutdown state
$(nW) <1> $(nW) $(nW) compiled with libndctl 63+
$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck
$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind
$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck
$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd
$(nW) <1> $(nW) $(nW) Log level HARK
$(nW) <1> $(nW) $(nW) Log level ERROR
$(nW) <2> $(nW) $(nW) Log level WARNING
14 changes: 7 additions & 7 deletions src/test/traces/redir_stderr4.log.match
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
$(nW) <1> $(nW) $(nW) src version: $(nW)
$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for shutdown state
$(OPT)$(nW) <1> $(nW) $(nW) compiled with libndctl 63+
$(nW) <1> $(nW) $(nW) pid $(N): program: $(nW)
$(nW) <1> $(nW) $(nW) ut version 1.0
$(nW) <1> $(nW) $(nW) src version: $(nW)
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd
$(nW) <1> $(nW) $(nW) compiled with support for shutdown state
$(nW) <1> $(nW) $(nW) compiled with libndctl 63+
$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck
$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind
$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck
$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd
$(nW) <3> $(nW) $(nW)
$(nW) <1> $(nW) $(nW) Log level HARK
$(nW) <1> $(nW) $(nW) Log level ERROR
Expand Down
14 changes: 7 additions & 7 deletions src/test/traces/redir_stderr5.log.match
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
$(nW) <1> $(nW) $(nW) src version: $(nW)
$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for shutdown state
$(OPT)$(nW) <1> $(nW) $(nW) compiled with libndctl 63+
$(nW) <1> $(nW) $(nW) pid $(N): program: $(nW)
$(nW) <1> $(nW) $(nW) ut version 1.0
$(nW) <1> $(nW) $(nW) src version: $(nW)
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd
$(nW) <1> $(nW) $(nW) compiled with support for shutdown state
$(nW) <1> $(nW) $(nW) compiled with libndctl 63+
$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck
$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind
$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck
$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd
$(nW) <3> $(nW) $(nW)
$(nW) <1> $(nW) $(nW) Log level HARK
$(nW) <1> $(nW) $(nW) Log level ERROR
Expand Down
6 changes: 3 additions & 3 deletions src/test/util_poolset/grep0.log.match
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
src version: $(nW)
$(OPT)compiled with support for shutdown state
$(OPT)compiled with libndctl 63+
pid $(N): program: $(nW)/util_poolset$(nW)
ut version 1.0
src version: $(nW)
$(OPT)compiled with support for Valgrind pmemcheck
$(OPT)compiled with support for Valgrind helgrind
$(OPT)compiled with support for Valgrind memcheck
$(OPT)compiled with support for Valgrind drd
$(OPT)compiled with support for shutdown state
$(OPT)compiled with libndctl 63+
open "$(nW)/testset0": No such file or directory
cannot create pool set -- '$(nW)/testset0'
$(OPT)Cannot read device usc - ndctl is not available
Expand Down
6 changes: 3 additions & 3 deletions src/test/util_poolset/grep1.log.match
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
src version: $(nW)
$(OPT)compiled with support for shutdown state
$(OPT)compiled with libndctl 63+
pid $(N): program: $(nW)/util_poolset$(nW)
ut version 1.0
src version: $(nW)
$(OPT)compiled with support for Valgrind pmemcheck
$(OPT)compiled with support for Valgrind helgrind
$(OPT)compiled with support for Valgrind memcheck
$(OPT)compiled with support for Valgrind drd
$(OPT)compiled with support for shutdown state
$(OPT)compiled with libndctl 63+
open "$(nW)/testset0": No such file or directory
cannot open pool set -- '$(nW)/testset0'
invalid major version (0)
Expand Down
6 changes: 3 additions & 3 deletions src/test/util_poolset/grep10.log.match
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
src version: $(nW)
$(OPT)compiled with support for shutdown state
$(OPT)compiled with libndctl 63+
pid $(N): program: $(nW)/util_poolset$(nW)
ut version 1.0
src version: $(nW)
$(OPT)compiled with support for Valgrind pmemcheck
$(OPT)compiled with support for Valgrind helgrind
$(OPT)compiled with support for Valgrind memcheck
$(OPT)compiled with support for Valgrind drd
$(OPT)compiled with support for shutdown state
$(OPT)compiled with libndctl 63+
invalid checksum of pool header
wrong pool type: "ERRORXX"
pool version 99 (library expects 1)
Expand Down
6 changes: 3 additions & 3 deletions src/test/util_poolset/grep2.log.match
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
src version: $(nW)
$(OPT)compiled with support for shutdown state
$(OPT)compiled with libndctl 63+
pid $(N): program: $(nW)/util_poolset$(nW)
ut version 1.0
src version: $(nW)
$(OPT)compiled with support for Valgrind pmemcheck
$(OPT)compiled with support for Valgrind helgrind
$(OPT)compiled with support for Valgrind memcheck
$(OPT)compiled with support for Valgrind drd
$(OPT)compiled with support for shutdown state
$(OPT)compiled with libndctl 63+
invalid checksum of pool header
header check failed - part #1
wrong pool type: "ERRORXX"
Expand Down
6 changes: 3 additions & 3 deletions src/test/util_poolset/grep3.log.match
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
src version: $(nW)
$(OPT)compiled with support for shutdown state
$(OPT)compiled with libndctl 63+
pid $(N): program: $(nW)util_poolset$(nW)
ut version 1.0
src version: $(nW)
$(OPT)compiled with support for Valgrind pmemcheck
$(OPT)compiled with support for Valgrind helgrind
$(OPT)compiled with support for Valgrind memcheck
$(OPT)compiled with support for Valgrind drd
$(OPT)compiled with support for shutdown state
$(OPT)compiled with libndctl 63+
Loading
Loading