From b98a4f8d56a61b5f98269d757cc69bd07b2b49b5 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sun, 28 Nov 2021 20:08:45 +0100 Subject: Include support for legacy LXC cgroup naming --- linux/CGroupUtils.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/linux/CGroupUtils.c b/linux/CGroupUtils.c index 1c8b05ff..6f3b6fe7 100644 --- a/linux/CGroupUtils.c +++ b/linux/CGroupUtils.c @@ -67,6 +67,8 @@ static bool CGroup_filterName_internal(const char *cgroup, StrBuf_state* s, StrB const char* str_machine_slice = "machine.slice"; const char* str_user_slice_prefix = "/user-"; + const char* str_lxc_monitor_legacy = "lxc.monitor"; + const char* str_lxc_payload_legacy = "lxc.payload"; const char* str_lxc_monitor_prefix = "lxc.monitor."; const char* str_lxc_payload_prefix = "lxc.payload."; @@ -193,6 +195,34 @@ static bool CGroup_filterName_internal(const char *cgroup, StrBuf_state* s, StrB continue; } + // LXC legacy cgroup naming + if (Label_checkEqual(labelStart, labelLen, str_lxc_monitor_legacy) || + Label_checkEqual(labelStart, labelLen, str_lxc_payload_legacy)) { + bool isMonitor = Label_checkEqual(labelStart, labelLen, str_lxc_monitor_legacy); + + labelStart = nextSlash; + while (*labelStart == '/') + labelStart++; + + nextSlash = strchrnul(labelStart, '/'); + if (nextSlash - labelStart > 0) { + if (!StrBuf_putsz(s, w, isMonitor ? "[LXC:" : "[lxc:")) + return false; + + if (!StrBuf_putsn(s, w, labelStart, nextSlash - labelStart)) + return false; + + if (!w(s, ']')) + return false; + + cgroup = nextSlash; + continue; + } + + labelStart = cgroup; + nextSlash = labelStart + labelLen; + } + if (Label_checkSuffix(labelStart, labelLen, str_service_suffix)) { const size_t serviceNameLen = labelLen - strlen(str_service_suffix); -- cgit v1.2.3