Mercurial > ~mikael > mcabber > hg
comparison mcabber/mcabber/main.c @ 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 | cf08c3b630af |
children | f30459c47092 |
comparison
equal
deleted
inserted
replaced
2182:09508eeb81dc | 2183:e62319868844 |
---|---|
28 #include <sys/types.h> | 28 #include <sys/types.h> |
29 #include <sys/wait.h> | 29 #include <sys/wait.h> |
30 #include <glib.h> | 30 #include <glib.h> |
31 #include <config.h> | 31 #include <config.h> |
32 #include <poll.h> | 32 #include <poll.h> |
33 #include <errno.h> | |
33 | 34 |
34 #include "caps.h" | 35 #include "caps.h" |
35 #include "screen.h" | 36 #include "screen.h" |
36 #include "settings.h" | 37 #include "settings.h" |
37 #include "roster.h" | 38 #include "roster.h" |
173 { | 174 { |
174 #define MAX_PWD 100 | 175 #define MAX_PWD 100 |
175 char *pwd; | 176 char *pwd; |
176 FILE *outfp = popen(command, "r"); | 177 FILE *outfp = popen(command, "r"); |
177 if (outfp == NULL) { | 178 if (outfp == NULL) { |
178 scr_log_print(LPRINT_NORMAL, "** ERROR: Failed to execute password_eval command."); | 179 scr_log_print(LPRINT_NORMAL, |
180 "** ERROR: Failed to execute password_eval command."); | |
179 *status = -1; | 181 *status = -1; |
180 return NULL; | 182 return NULL; |
181 } | 183 } |
182 | 184 |
183 pwd = g_new0(char, MAX_PWD); | 185 pwd = g_new0(char, MAX_PWD); |
184 if (fgets(pwd, MAX_PWD, outfp) == NULL) { | 186 if (fgets(pwd, MAX_PWD, outfp) == NULL) { |
185 scr_log_print(LPRINT_NORMAL, "** ERROR: Failed to read from password_eval command."); | 187 scr_log_print(LPRINT_NORMAL, |
188 "** ERROR: Failed to read from password_eval command."); | |
186 g_free(pwd); | 189 g_free(pwd); |
187 *status = -1; | 190 *status = -1; |
188 return NULL; | 191 return NULL; |
189 } | 192 } |
190 | 193 |
191 int res = pclose(outfp); | 194 int res = pclose(outfp); |
192 if (res != 0) { | 195 if (res != 0 && errno != ECHILD) { |
193 scr_log_print(LPRINT_NORMAL, "** ERROR: Password evaluation command exited with error %d.", res); | 196 scr_log_print(LPRINT_NORMAL, |
197 "** ERROR: Password evaluation command exited with error %d.", | |
198 res); | |
199 if (res == -1) { | |
200 scr_log_print(LPRINT_NORMAL, " errno=%d", errno); | |
201 } | |
194 g_free(pwd); | 202 g_free(pwd); |
195 *status = res; | 203 *status = res; |
196 return NULL; | 204 return NULL; |
197 } | 205 } |
198 | 206 |