Skip to content

Commit

Permalink
reaper: close file descriptors at end of Lua handler
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Dec 4, 2023
1 parent a07c091 commit 7f040da
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ cm4all-spawn (0.14) unstable; urgency=low
* split Debian package
* accessory: implement systemd socket activation
* reaper: rename "accounting.lua" to "reaper.lua"
* reaper: close file descriptors at end of Lua handler
* systemd: remove "WantedBy=multi-user.target"

--
Expand Down
2 changes: 1 addition & 1 deletion libcommon
7 changes: 7 additions & 0 deletions src/reaper/LAccounting.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "LAccounting.hxx"
#include "CgroupAccounting.hxx"
#include "lua/Assert.hxx"
#include "lua/AutoClose.hxx"
#include "lua/CoRunner.hxx"
#include "lua/Resume.hxx"
#include "lua/io/XattrTable.hxx"
Expand All @@ -29,6 +30,11 @@ class LuaAccounting::Thread final
:runner(L) {}

~Thread() noexcept {
auto *L = runner.GetMainState();
runner.Push(L);
AutoClose(L, RelativeStackIndex{-1});
lua_pop(L, 1);

runner.Cancel();
}

Expand Down Expand Up @@ -61,6 +67,7 @@ Push(lua_State *L, UniqueFileDescriptor &&cgroup_fd,

if (cgroup_fd.IsDefined()) {
NewXattrTable(L, std::move(cgroup_fd));
AddAutoClose(L, CurrentThread{}, RelativeStackIndex{-1});
lua_setfield(L, -2, "cgroup_xattr");
}

Expand Down

0 comments on commit 7f040da

Please sign in to comment.