run-command: be more informative about what failed

While debugging an error with verify_signed_buffer() the error messages from run-command weren't very useful: error: cannot create pipe for gpg: Too many open files error: could not run gpg. because they didn't indicate *which* pipe couldn't be created. Print which pipe failed to be created in the error message so we can more easily debug similar problems in the future. For example, the above error now prints: error: cannot create standard error pipe for gpg: Too many open files error: could not run gpg. Signed-off-by: Stephen Boyd <sboyd@codeaurora.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stephen Boyd committed Jan 30, 2013 at 18:01 UTC 939296c4a42b0eb22542f0fe2e50b53993489eff
1 file changed +6 -2
run-command.c
+6 -2
@@ -273,6 +273,7 @@ int start_command(struct child_process *cmd)
273 int need_in, need_out, need_err;
274 int fdin[2], fdout[2], fderr[2];
275 int failed_errno = failed_errno;
276 + char *str;
277
278 /*
279 * In case of errors we must keep the promise to close FDs
@@ -285,6 +286,7 @@ int start_command(struct child_process *cmd)
286 failed_errno = errno;
287 if (cmd->out > 0)
288 close(cmd->out);
289 + str = "standard input";
290 goto fail_pipe;
291 }
292 cmd->in = fdin[1];
@@ -300,6 +302,7 @@ int start_command(struct child_process *cmd)
302 close_pair(fdin);
303 else if (cmd->in)
304 close(cmd->in);
305 + str = "standard output";
306 goto fail_pipe;
307 }
308 cmd->out = fdout[0];
@@ -317,9 +320,10 @@ int start_command(struct child_process *cmd)
320 close_pair(fdout);
321 else if (cmd->out)
322 close(cmd->out);
323 + str = "standard error";
324 fail_pipe:
321 - error("cannot create pipe for %s: %s",
322 - cmd->argv[0], strerror(failed_errno));
325 + error("cannot create %s pipe for %s: %s",
326 + str, cmd->argv[0], strerror(failed_errno));
327 errno = failed_errno;
328 return -1;
329 }