changeset 2183:e62319868844

Fix external password support (esp. on OS X) pclose() can return -1 and set errno to ECHILD if the process has already terminated. Thanks to languitar for the report and troubleshooting.
author Mikael Berthe <mikael@lilotux.net>
date Tue, 22 Sep 2015 21:30:00 +0200
parents 09508eeb81dc
children f30459c47092
files mcabber/mcabber/main.c
diffstat 1 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/mcabber/main.c	Sat Sep 05 18:28:12 2015 +0200
+++ b/mcabber/mcabber/main.c	Tue Sep 22 21:30:00 2015 +0200
@@ -30,6 +30,7 @@
 #include <glib.h>
 #include <config.h>
 #include <poll.h>
+#include <errno.h>
 
 #include "caps.h"
 #include "screen.h"
@@ -175,22 +176,29 @@
   char *pwd;
   FILE *outfp = popen(command, "r");
   if (outfp == NULL) {
-    scr_log_print(LPRINT_NORMAL, "** ERROR: Failed to execute password_eval command.");
+    scr_log_print(LPRINT_NORMAL,
+                  "** ERROR: Failed to execute password_eval command.");
     *status = -1;
     return NULL;
   }
 
   pwd = g_new0(char, MAX_PWD);
   if (fgets(pwd, MAX_PWD, outfp) == NULL) {
-    scr_log_print(LPRINT_NORMAL, "** ERROR: Failed to read from password_eval command.");
+    scr_log_print(LPRINT_NORMAL,
+                  "** ERROR: Failed to read from password_eval command.");
     g_free(pwd);
     *status = -1;
     return NULL;
   }
 
   int res = pclose(outfp);
-  if (res != 0) {
-    scr_log_print(LPRINT_NORMAL, "** ERROR: Password evaluation command exited with error %d.", res);
+  if (res != 0 && errno != ECHILD) {
+    scr_log_print(LPRINT_NORMAL,
+                  "** ERROR: Password evaluation command exited with error %d.",
+                  res);
+    if (res == -1) {
+    scr_log_print(LPRINT_NORMAL, "   errno=%d", errno);
+    }
     g_free(pwd);
     *status = res;
     return NULL;