Skip to content

Fix errno race condition and logging macro issues#575

Merged
jnovy merged 1 commit intocontainers:mainfrom
jnovy:574
Aug 18, 2025
Merged

Fix errno race condition and logging macro issues#575
jnovy merged 1 commit intocontainers:mainfrom
jnovy:574

Conversation

@jnovy
Copy link
Collaborator

@jnovy jnovy commented Aug 12, 2025

  • Fix errno race condition in logging macros
  • Fix pwarnf macro structure to prevent control flow issues
  • Add missing log level check to pwarn macro
  • Fix syslog tag inconsistency in pwarnf
  • Remove trailing spaces from syslog format strings
  • Add missing colon in nexit stderr format

Fixes: #574

@jnovy jnovy requested a review from mtrmac August 12, 2025 08:38
@jnovy
Copy link
Collaborator Author

jnovy commented Aug 12, 2025

@mtrmac PTAL

Copy link
Collaborator

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locally this looks good, except that strerror is not thread-safe. Is this all guaranteed to run on the main thread?

I didn’t find anything to suggest multi-threaded use, the code seems to be centered around a GMainLoop, but I am not familiar with the codebase.

@jnovy jnovy force-pushed the 574 branch 2 times, most recently from be021e1 to 822ff00 Compare August 13, 2025 06:00
@jnovy
Copy link
Collaborator Author

jnovy commented Aug 13, 2025

The conmon is single thread - just updated the implementation so that it's thread safe if we decide to go that way.

@haircommander
Copy link
Collaborator

LGTM

src/utils.h Outdated
{
static __thread char errbuf[256];
int saved_errno = errno;
snprintf(errbuf, sizeof(errbuf), "%s", strerror(saved_errno));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if … >= sizeof(errbuf) { abort() } or something? (sprintf("[unexpected error %d"]) is an option but unreasonable)

src/utils.h Outdated

static inline const char *get_errno_string(void)
{
static __thread char errbuf[256];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Absolutely unblocking: The __thread works but it seems unnecessary, the caller can allocate a buffer on stack.)

src/utils.h Outdated
{
static __thread char errbuf[256];
int saved_errno = errno;
snprintf(errbuf, sizeof(errbuf), "%s", strerror(saved_errno));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not avoid the usage of strerror, so I don’t think this is an improvement compared to the previous version?!

Using %m here might work.

- Fix errno race condition in logging macros
- Fix pwarnf macro structure to prevent control flow issues
- Add missing log level check to pwarn macro
- Fix syslog tag inconsistency in pwarnf
- Remove trailing spaces from syslog format strings
- Add missing colon in nexit stderr format

Fixes: containers#574

Signed-off-by: Jindrich Novy <jnovy@redhat.com>
@jnovy
Copy link
Collaborator Author

jnovy commented Aug 13, 2025

Ok, let's do it in the simple way without any helper functions and exactly what it has to do.

@mtrmac
Copy link
Collaborator

mtrmac commented Aug 13, 2025

Fine :) I’ll read that carefully later, but this clearly works.

Copy link
Collaborator

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Thanks!

@jnovy jnovy merged commit b91d4ee into containers:main Aug 18, 2025
29 of 32 checks passed
@jnovy jnovy deleted the 574 branch September 1, 2025 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Most log macros functions in utils.h are incorrect

3 participants