From 421e9f942ce8bf8c1095200998cf3b4f3bc5c060 Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sat, 15 Nov 2014 19:40:43 +0100 Subject: [PATCH] wmaker: improve error messages when trying to start the helper Try to provide better messages to understand what went wrong, including more information, and made them translatable; Changed the call to 'dup' into 'dup2' which has a safer behaviour because we can specify the target descriptor we want; Removed a few check for the 'close()' because in these cases we do not really care if they fail (we can't do anything about it and it just adds noise in the logs). Signed-off-by: Christophe CURIS Signed-off-by: Carlos R. Mafra --- src/misc.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/misc.c b/src/misc.c index 5d54561a..b4c71023 100644 --- a/src/misc.c +++ b/src/misc.c @@ -33,6 +33,7 @@ #include #include #include +#include #include @@ -929,48 +930,51 @@ Bool start_bg_helper(WScreen *scr) int filedes[2]; if (pipe(filedes) < 0) { - werror("pipe() failed:can't set workspace specific background image"); + werror(_("%s failed, can't set workspace specific background image (%s)"), + "pipe()", strerror(errno)); return False; } pid = fork(); if (pid < 0) { - werror("fork() failed:can't set workspace specific background image"); - if (close(filedes[0]) < 0) - werror("could not close pipe"); - if (close(filedes[1]) < 0) - werror("could not close pipe"); + werror(_("%s failed, can't set workspace specific background image (%s)"), + "fork()", strerror(errno)); + close(filedes[0]); + close(filedes[1]); return False; } else if (pid == 0) { - char *dither; + const char *dither; /* We don't need this side of the pipe in the child process */ close(filedes[1]); SetupEnvironment(scr); - if (close(0) < 0) - werror("could not close pipe"); - if (dup(filedes[0]) < 0) { - werror("dup() failed:can't set workspace specific background image"); + close(STDIN_FILENO); + if (dup2(filedes[0], STDIN_FILENO) < 0) { + werror(_("%s failed, can't set workspace specific background image (%s)"), + "dup2()", strerror(errno)); + exit(1); } close(filedes[0]); + dither = wPreferences.no_dithering ? "-m" : "-d"; if (wPreferences.smooth_workspace_back) execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL); else execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL); - werror("could not execute wmsetbg"); + + werror(_("could not execute \"%s\": %s"), "wmsetbg", strerror(errno)); exit(1); } else { /* We don't need this side of the pipe in the parent process */ close(filedes[0]); - if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) { - werror("error setting close-on-exec flag"); - } + if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) + wwarning(_("could not set close-on-exec flag for bg_helper's communication file handle (%s)"), + strerror(errno)); scr->helper_fd = filedes[1]; scr->helper_pid = pid; -- 2.11.4.GIT