Skip to content

Add container labels to JournalD logs#553

Closed
OZoneGuy wants to merge 4 commits intocontainers:mainfrom
OZoneGuy:feat/log-labels
Closed

Add container labels to JournalD logs#553
OZoneGuy wants to merge 4 commits intocontainers:mainfrom
OZoneGuy:feat/log-labels

Conversation

@OZoneGuy
Copy link
Contributor

@OZoneGuy OZoneGuy commented Apr 14, 2025

Add the ability to add the container labels to the journald logs as extra parameters.

Relies on the caller to pass the label key and value.

Usage:

conmon ... --log-labels label1=val1,label2=val2

The labels and values will be added to the journald entry.

This is my first contribution to a C codebase. Feedback is most

Still need to test the changes locally.

Signed-off-by: OZoneGuy <oalkersh@protonmail.com>
Signed-off-by: OZoneGuy <oalkersh@protonmail.com>
pass NULL as the first argument for subsequent calls

Signed-off-by: OZoneGuy <oalkersh@protonmail.com>
}
container_labels = g_alloca((sizeof(char *)) * container_labels_count);
container_labels_lengths = g_alloca((sizeof(int *)) * container_labels_count);
char *pair = strtok(log_labels, ",");
Copy link
Member

Choose a reason for hiding this comment

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

strtok modifies the buffer, so log_labels will be modified. The correct way to do it is to g_strdup the string before passing it to strtok.

Comment on lines +350 to +352
if (writev_buffer_append_segment_no_flush(&bufv, container_labels[i], container_labels_lengths[i]) < 0)
return -1;
}
Copy link
Member

Choose a reason for hiding this comment

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

I suggest to not create the arrays before and then have to worry about cleaning them up.

Just strdup container_labels here and call writev_buffer_append_segment_no_flush while you parse it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Going back to this. Since the array will live for the entire of the program. Is this needed? Not to challenge, just want to get more familiar with C and this codebase.

@OZoneGuy OZoneGuy requested a review from giuseppe April 17, 2025 23:57
Signed-off-by: OZoneGuy <oalkersh@protonmail.com>
@packit-as-a-service
Copy link

Ephemeral COPR build failed. @containers/packit-build please check.

@p12tic
Copy link
Contributor

p12tic commented Jun 4, 2025

This PR can be closed due to #562 being merged

@giuseppe giuseppe closed this Jun 4, 2025
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.

3 participants