From 1b805a31720727008b32b1129a167758519fd4db Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Mon, 2 May 2022 16:04:21 +0200 Subject: New upstream version 3.2.0 --- linux/CGroupUtils.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'linux/CGroupUtils.c') diff --git a/linux/CGroupUtils.c b/linux/CGroupUtils.c index 6f3b6fe..22cce91 100644 --- a/linux/CGroupUtils.c +++ b/linux/CGroupUtils.c @@ -33,7 +33,7 @@ static bool StrBuf_putc_write(StrBuf_state* p, char c) { } static bool StrBuf_putsn(StrBuf_state* p, StrBuf_putc_t w, const char* s, size_t count) { - while (count--) + for (; count; count--) if (!w(p, *s++)) return false; @@ -66,6 +66,7 @@ static bool CGroup_filterName_internal(const char *cgroup, StrBuf_state* s, StrB const char* str_user_slice = "user.slice"; const char* str_machine_slice = "machine.slice"; const char* str_user_slice_prefix = "/user-"; + const char* str_system_slice_prefix = "/system-"; const char* str_lxc_monitor_legacy = "lxc.monitor"; const char* str_lxc_payload_legacy = "lxc.payload"; @@ -76,6 +77,8 @@ static bool CGroup_filterName_internal(const char *cgroup, StrBuf_state* s, StrB const char* str_nspawn_monitor_label = "/supervisor"; const char* str_nspawn_payload_label = "/payload"; + const char* str_snap_scope_prefix = "snap."; + const char* str_service_suffix = ".service"; const char* str_scope_suffix = ".scope"; @@ -100,6 +103,11 @@ static bool CGroup_filterName_internal(const char *cgroup, StrBuf_state* s, StrB if (!StrBuf_putsz(s, w, "[S]")) return false; + if (String_startsWith(cgroup, str_system_slice_prefix)) { + cgroup = strchrnul(cgroup + 1, '/'); + continue; + } + continue; } @@ -266,6 +274,22 @@ static bool CGroup_filterName_internal(const char *cgroup, StrBuf_state* s, StrB else if (String_startsWith(nextSlash, str_nspawn_payload_label)) cgroup += strlen(str_nspawn_payload_label); + continue; + } else if(Label_checkPrefix(labelStart, scopeNameLen, str_snap_scope_prefix)) { + const char* nextDot = strchrnul(labelStart + strlen(str_snap_scope_prefix), '.'); + + if (!StrBuf_putsz(s, w, "!snap:")) + return false; + + if (nextDot >= labelStart + scopeNameLen) { + nextDot = labelStart + scopeNameLen; + } + + if (!StrBuf_putsn(s, w, labelStart + strlen(str_snap_scope_prefix), nextDot - (labelStart + strlen(str_snap_scope_prefix)))) + return false; + + cgroup = nextSlash; + continue; } -- cgit v1.2.3