From a614818b64758666c0a7e6e50ee63f50b8236261 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Oto=20=C5=A0=C5=A5=C3=A1va?= <oto.stava@nic.cz>
Date: Fri, 24 Feb 2023 11:08:59 +0100
Subject: [PATCH] daemon/engine: warning when log_groups contains a
 non-existent group

Until now, kresd would refuse to start when a log_groups Lua call
contained a non-existent group. After this change, only a warning is
printed, which helps during development while switching between branches
with new logging groups. I don't think changing the configuration all
the time just for a logging group is warranted.
---
 daemon/engine.c         | 9 ++++++---
 daemon/lua/log.test.lua | 2 +-
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/daemon/engine.c b/daemon/engine.c
index 26c225f39..7ee565121 100644
--- a/daemon/engine.c
+++ b/daemon/engine.c
@@ -229,11 +229,14 @@ static int l_log_groups(lua_State *L)
 			const char *grp_str = lua_tostring(L, -1);
 			if (!grp_str)
 				goto bad_call;
+
 			enum kr_log_group grp = kr_log_name2grp(grp_str);
-			if (grp < 0)
-				lua_error_p(L, "unknown log group '%s'", lua_tostring(L, -1));
+			if (grp >= 0) {
+				kr_log_group_add(grp);
+			} else {
+				kr_log_warning(SYSTEM, "WARNING: unknown log group '%s'\n", lua_tostring(L, -1));
+			}
 
-			kr_log_group_add(grp);
 			++idx;
 			lua_pop(L, 1);
 		}
diff --git a/daemon/lua/log.test.lua b/daemon/lua/log.test.lua
index 197aa74cc..ec5abd28c 100644
--- a/daemon/lua/log.test.lua
+++ b/daemon/lua/log.test.lua
@@ -30,8 +30,8 @@ local function test_log_groups()
 	same(log_groups({'devel'}), {'devel'}, 'another call overrides previously set groups')
 	same(log_groups({'devel', 'system'}), {'system', 'devel'}, 'configure multiple groups')
 	same(log_groups({}), {}, 'clear groups with empty table')
+	same(log_groups({'nonexistent'}), {}, "nonexistent group is ignored")
 	boom(log_groups, { 'string' }, "group argument can't be string")
-	boom(log_groups, { {'nonexistent'} }, "nonexistent group can't be added")
 	boom(log_groups, { 1, 2 }, "group doesn't take multiple arguments")
 end
 
-- 
GitLab