diff --git a/debian/changelog b/debian/changelog index 1a80dbe..2aca9db 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,6 @@ cm4all-qrelay (0.26) unstable; urgency=low - * lua: remove deprecated method "mail:get_cgroup()" + * lua: refactor the cgroup API * lua: close Lua file descriptors when connection is closed * lua: fix broken cgroup xattr access diff --git a/doc/index.rst b/doc/index.rst index cc871ba..e3d9550 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -75,12 +75,14 @@ The following attributes can be queried: * :samp:`gid`: The client's group id. -* :samp:`cgroup`: The control group path of the client process as - noted in :file:`/proc/self/cgroup`, - e.g. :file:`/user.slice/user-1000.slice/session-42.scope` +* :samp:`cgroup`: The control group of the client process with the + following attributes: -* ``cgroup_xattr``: A table containing extended attributes of the - control group. + * ``path``: the cgroup path as noted in :file:`/proc/self/cgroup`, + e.g. :file:`/user.slice/user-1000.slice/session-42.scope` + + * ``xattr``: A table containing extended attributes of the + control group. The following methods can access more data: diff --git a/libcommon b/libcommon index 0d94305..de0030a 160000 --- a/libcommon +++ b/libcommon @@ -1 +1 @@ -Subproject commit 0d943059a7b9ef146639d66c439bcefd0e610177 +Subproject commit de0030adf7e178fc84d19c72764d0657e756ec7a diff --git a/src/LMail.cxx b/src/LMail.cxx index d42c062..df95997 100644 --- a/src/LMail.cxx +++ b/src/LMail.cxx @@ -10,7 +10,7 @@ #include "lua/Class.hxx" #include "lua/Error.hxx" #include "lua/FenvCache.hxx" -#include "lua/io/XattrTable.hxx" +#include "lua/io/CgroupInfo.hxx" #include "lua/net/SocketAddress.hxx" #include "uri/EmailAddress.hxx" #include "util/StringAPI.hxx" @@ -314,26 +314,7 @@ IncomingMail::Index(lua_State *L) if (path.empty()) return 0; - Lua::Push(L, path); - return 1; - } else if (StringIsEqual(name, "cgroup_xattr")) { - if (!HavePeerCred()) - return 0; - - const auto path = ReadProcessCgroup(GetPid()); - if (path.empty()) - return 0; - - try { - const auto sys_fs_cgroup = OpenPath("/sys/fs/cgroup"); - auto fd = OpenReadOnlyBeneath({sys_fs_cgroup, path.c_str() + 1}); - Lua::NewXattrTable(L, std::move(fd)); - } catch (...) { - Lua::RaiseCurrent(L); - } - - // auto-close the file descriptor when the connection is closed - auto_close->Add(L, Lua::RelativeStackIndex{-1}); + Lua::NewCgroupInfo(L, *auto_close, path); // copy a reference to the fenv (our cache) Lua::SetFenvCache(L, 1, name, Lua::RelativeStackIndex{-1}); diff --git a/src/Main.cxx b/src/Main.cxx index 3e7573f..ace0220 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -15,6 +15,7 @@ #include "lua/PushCClosure.hxx" #include "lua/RunFile.hxx" #include "lua/io/XattrTable.hxx" +#include "lua/io/CgroupInfo.hxx" #include "lua/net/SocketAddress.hxx" #include "lua/event/Init.hxx" #include "lua/pg/Init.hxx" @@ -143,6 +144,7 @@ SetupRuntimeState(lua_State *L) Lua::SetGlobal(L, "qmqp_listen", nullptr); Lua::InitXattrTable(L); + Lua::RegisterCgroupInfo(L); QmqpRelayConnection::Register(L);