From 18221ff472e95df5d36d1422868c7263b5495be7 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Mar 17 2016 14:19:54 +0000 Subject: Fork to execute systemctl calls Calling os.execute() to apply presets was a mistake for two reasons: 1) os.execute() calls out to a shell, which defeated the purpose of rewriting the scriptlet in Lua to avoid a /bin/sh dependency. 2) os.execute() only took a single argument, so it wasn't actually applying the presets at all. Rewriting this to explicitly fork()/exec() results in properly- applied presets without the /bin/sh dependency. Signed-off-by: Stephen Gallagher --- diff --git a/convert-to-edition.lua b/convert-to-edition.lua index d52a471..2a5b9d9 100644 --- a/convert-to-edition.lua +++ b/convert-to-edition.lua @@ -125,8 +125,17 @@ local function set_presets(edition, apply_presets) local presets = read_presets(target) local systemctl = "/usr/bin/systemctl" if posix.access(systemctl, "x") then - os.execute(systemctl, "preset", "-q", - table.unpack(presets)) + --fork off a systemctl call + local pid = assert(posix.fork()) + if pid == 0 then + -- Child + posix.exec(systemctl, "preset", "-q", table.unpack(presets)) + -- In case exec() fails + os.exit(17) + else + -- RPM + assert(posix.wait(pid)) + end end end end