-
-
Notifications
You must be signed in to change notification settings - Fork 531
New column for LXC containers name using the CGroups #217
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -533,6 +533,33 @@ static void LinuxProcessList_readCGroupFile(LinuxProcess* process, const char* d | |
| if (!ok) break; | ||
| char* group = strchr(buffer, ':'); | ||
| if (!group) break; | ||
|
|
||
| if (!process->lxc) { | ||
| // Each line have 3 columns separated by a ':', the 3rd column contains the pathname | ||
| char* groupPathname = strchr(group + 1, ':') + 1; | ||
| if (groupPathname) { | ||
| if ( String_startsWith(groupPathname, "/lxc.payload/") || String_startsWith(groupPathname, "/lxc.payload.") ) { | ||
| // The process is inside a LXC container using CGroup V2 (/lxc.payload.) or a modern CGroup V1 terminology (/lxc.payload/), for a better readability, only the container name is kept | ||
| char *slashpostion = strchr((groupPathname + 13), '/'); | ||
| if (slashpostion) { | ||
| // There is a '/' in the CGroup string (after the initial "/lxc.payload"), a '\0' will truncate the string at this position | ||
| groupPathname[(slashpostion - groupPathname)] = '\0'; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we are modifying the string behind There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In all fairness, the current implementation of the CGROUP column is fairly useless on modern systems as it will show lengty SystemD CGroups for services started by it that breaks the alignment of columns as the values are too long compared to the column size. I initially did put my code inside the |
||
| } | ||
| free(process->lxc); | ||
| process->lxc = String_trim(groupPathname + 13); | ||
| } else if (String_startsWith(groupPathname, "/lxc/")) { | ||
| // The process is inside a LXC container using a legacy CGroup V1 (/lxc/), for a better readability, only the container name is kept | ||
| char *slashpostion = strchr((groupPathname + 5), '/'); | ||
| if (slashpostion) { | ||
| // There is a '/' in the CGroup string (after the initial "/lxc/"), a '\0' will truncate the string at this position | ||
| groupPathname[(slashpostion - groupPathname)] = '\0'; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dito |
||
| } | ||
| free(process->lxc); | ||
| process->lxc = String_trim(groupPathname + 5); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (at != output) { | ||
| *at = ';'; | ||
| at++; | ||
|
|
@@ -542,6 +569,12 @@ static void LinuxProcessList_readCGroupFile(LinuxProcess* process, const char* d | |
| left -= wrote; | ||
| } | ||
| fclose(file); | ||
| if (!process->lxc) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This whole block is now a no-op (it is only entered if |
||
| // The process is not in a LXC container | ||
| free(process->lxc); | ||
| // To show an empty value instead of (null) | ||
| process->lxc = NULL; | ||
| } | ||
| free(process->cgroup); | ||
| process->cgroup = xStrdup(output); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the LXC cgroup never change for a running process? (Cause it's only computed once)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically it could (changed process namespace), but practically it doesn't.