[systemd-devel] [PATCH] vconsole-setup: check error of child process

lucas.de.marchi at gmail.com lucas.de.marchi at gmail.com
Tue Mar 10 12:56:42 PDT 2015


From: Lucas De Marchi <lucas.demarchi at intel.com>

If we don't check the error of the child process, systemd-vconsole-setup
would exit with 0 even if it could not really setup the console.

For a simple test, move loadkeys elsewhere and execute
systemd-vconsole-setup:

	[root at localhost ~]# strace -f -e execve /usr/lib/systemd/systemd-vconsole-setup
	execve("/usr/lib/systemd/systemd-vconsole-setup", ["/usr/lib/systemd/systemd-vconsol"...], [/* 15 vars */]) = 0
	Process 171 attached
	[pid   171] execve("/usr/bin/loadkeys", ["/usr/bin/loadkeys", "-q", "-C", "/dev/tty0", "br-abnt2"], [/* 15 vars */]) = -1 ENOENT (No such file or directory)
	[pid   171] +++ exited with 1 +++
	--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=171, si_uid=0, si_status=1, si_utime=0, si_stime=0} ---
	+++ exited with 0 +++

Now systemd-vconsole-setup exits with EXIT_FAILURE if the child failed
for whatever reason.
---
 src/vconsole/vconsole-setup.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/vconsole/vconsole-setup.c b/src/vconsole/vconsole-setup.c
index bf681d9..601ca4a 100644
--- a/src/vconsole/vconsole-setup.c
+++ b/src/vconsole/vconsole-setup.c
@@ -304,8 +304,12 @@ int main(int argc, char **argv) {
                 return EXIT_FAILURE;
         }
 
-        if (font_pid > 0)
-                wait_for_terminate_and_warn(KBD_SETFONT, font_pid, true);
+        if (font_pid > 0) {
+                r = wait_for_terminate_and_warn(KBD_SETFONT, font_pid, true);
+                if (r != 0)
+                        return EXIT_FAILURE;
+        }
+
 
         r = keymap_load(vc, vc_keymap, vc_keymap_toggle, utf8, &keymap_pid);
         if (r < 0) {
@@ -313,10 +317,13 @@ int main(int argc, char **argv) {
                 return EXIT_FAILURE;
         }
 
-        if (keymap_pid > 0)
-                wait_for_terminate_and_warn(KBD_LOADKEYS, keymap_pid, true);
+        if (keymap_pid > 0) {
+                r = wait_for_terminate_and_warn(KBD_LOADKEYS, keymap_pid, true);
+                if (r != 0)
+                        return EXIT_FAILURE;
+        }
 
-        /* Only copy the font when we started setfont successfully */
+        /* Only copy the font when we executed setfont successfully */
         if (font_copy && font_pid > 0)
                 font_copy_to_all_vcs(fd);
 
-- 
2.3.2



More information about the systemd-devel mailing list