start_command: report child process setup errors to the parent's stderr

When the child process's environment is set up in start_command(), error
messages were written to wherever the parent redirected the child's stderr
channel. However, even if the parent redirected the child's stderr, errors
during this setup process, including the exec itself, are usually an
indication of a problem in the parent's environment. Therefore, the error
messages should go to the parent's stderr.

Redirection of the child's error messages is usually only used to redirect
hook error messages during client-server exchanges. In these cases, hook
setup errors could be regarded as information leak.

This patch makes a copy of stderr if necessary and uses a special
die routine that is used for all die() calls in the child that sends the
errors messages to the parent's stderr.

The trace call that reported a failed execvp is removed (because it writes
to stderr) and replaced by die_errno() with special treatment of ENOENT.
The improvement in the error message can be seen with this sequence:

   mkdir .git/hooks/pre-commit
   git commit

Previously, the error message was

   error: cannot run .git/hooks/pre-commit: No such file or directory

and now it is

   fatal: cannot exec '.git/hooks/pre-commit': Permission denied

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 file changed
tree: f040ea63783875b502bc78d998df511593a9f92e
  1. block-sha1/
  2. compat/
  3. contrib/
  4. Documentation/
  5. git-gui/
  6. git_remote_helpers/
  7. gitk-git/
  8. gitweb/
  9. perl/
  10. ppc/
  11. t/
  12. templates/
  13. xdiff/
  14. .gitattributes
  15. .gitignore
  16. .mailmap
  17. abspath.c
  18. advice.c
  19. advice.h
  20. alias.c
  21. alloc.c
  22. archive-tar.c
  23. archive-zip.c
  24. archive.c
  25. archive.h
  26. attr.c
  27. attr.h
  28. base85.c
  29. bisect.c
  30. bisect.h
  31. blob.c
  32. blob.h
  33. branch.c
  34. branch.h
  35. builtin-add.c
  36. builtin-annotate.c
  37. builtin-apply.c
  38. builtin-archive.c
  39. builtin-bisect--helper.c
  40. builtin-blame.c
  41. builtin-branch.c
  42. builtin-bundle.c
  43. builtin-cat-file.c
  44. builtin-check-attr.c
  45. builtin-check-ref-format.c
  46. builtin-checkout-index.c
  47. builtin-checkout.c
  48. builtin-clean.c
  49. builtin-clone.c
  50. builtin-commit-tree.c
  51. builtin-commit.c
  52. builtin-config.c
  53. builtin-count-objects.c
  54. builtin-describe.c
  55. builtin-diff-files.c
  56. builtin-diff-index.c
  57. builtin-diff-tree.c
  58. builtin-diff.c
  59. builtin-fast-export.c
  60. builtin-fetch-pack.c
  61. builtin-fetch.c
  62. builtin-fmt-merge-msg.c
  63. builtin-for-each-ref.c
  64. builtin-fsck.c
  65. builtin-gc.c
  66. builtin-grep.c
  67. builtin-help.c
  68. builtin-init-db.c
  69. builtin-log.c
  70. builtin-ls-files.c
  71. builtin-ls-remote.c
  72. builtin-ls-tree.c
  73. builtin-mailinfo.c
  74. builtin-mailsplit.c
  75. builtin-merge-base.c
  76. builtin-merge-file.c
  77. builtin-merge-ours.c
  78. builtin-merge-recursive.c
  79. builtin-merge.c
  80. builtin-mktree.c
  81. builtin-mv.c
  82. builtin-name-rev.c
  83. builtin-pack-objects.c
  84. builtin-pack-refs.c
  85. builtin-prune-packed.c
  86. builtin-prune.c
  87. builtin-push.c
  88. builtin-read-tree.c
  89. builtin-receive-pack.c
  90. builtin-reflog.c
  91. builtin-remote.c
  92. builtin-replace.c
  93. builtin-rerere.c
  94. builtin-reset.c
  95. builtin-rev-list.c
  96. builtin-rev-parse.c
  97. builtin-revert.c
  98. builtin-rm.c
  99. builtin-send-pack.c
  100. builtin-shortlog.c
  101. builtin-show-branch.c
  102. builtin-show-ref.c
  103. builtin-stripspace.c
  104. builtin-symbolic-ref.c
  105. builtin-tag.c
  106. builtin-tar-tree.c
  107. builtin-unpack-objects.c
  108. builtin-update-index.c
  109. builtin-update-ref.c
  110. builtin-update-server-info.c
  111. builtin-upload-archive.c
  112. builtin-verify-pack.c
  113. builtin-verify-tag.c
  114. builtin-write-tree.c
  115. builtin.h
  116. bundle.c
  117. bundle.h
  118. cache-tree.c
  119. cache-tree.h
  120. cache.h
  121. check-builtins.sh
  122. check-racy.c
  123. check_bindir
  124. color.c
  125. color.h
  126. combine-diff.c
  127. command-list.txt
  128. commit.c
  129. commit.h
  130. config.c
  131. config.mak.in
  132. configure.ac
  133. connect.c
  134. convert.c
  135. copy.c
  136. COPYING
  137. csum-file.c
  138. csum-file.h
  139. ctype.c
  140. daemon.c
  141. date.c
  142. decorate.c
  143. decorate.h
  144. delta.h
  145. diff-delta.c
  146. diff-lib.c
  147. diff-no-index.c
  148. diff.c
  149. diff.h
  150. diffcore-break.c
  151. diffcore-delta.c
  152. diffcore-order.c
  153. diffcore-pickaxe.c
  154. diffcore-rename.c
  155. diffcore.h
  156. dir.c
  157. dir.h
  158. editor.c
  159. entry.c
  160. environment.c
  161. exec_cmd.c
  162. exec_cmd.h
  163. fast-import.c
  164. fetch-pack.h
  165. fixup-builtins
  166. fsck.c
  167. fsck.h
  168. generate-cmdlist.sh
  169. git-add--interactive.perl
  170. git-am.sh
  171. git-archimport.perl
  172. git-bisect.sh
  173. git-compat-util.h
  174. git-cvsexportcommit.perl
  175. git-cvsimport.perl
  176. git-cvsserver.perl
  177. git-difftool--helper.sh
  178. git-difftool.perl
  179. git-filter-branch.sh
  180. git-instaweb.sh
  181. git-lost-found.sh
  182. git-merge-octopus.sh
  183. git-merge-one-file.sh
  184. git-merge-resolve.sh
  185. git-mergetool--lib.sh
  186. git-mergetool.sh
  187. git-notes.sh
  188. git-parse-remote.sh
  189. git-pull.sh
  190. git-quiltimport.sh
  191. git-rebase--interactive.sh
  192. git-rebase.sh
  193. git-relink.perl
  194. git-repack.sh
  195. git-request-pull.sh
  196. git-send-email.perl
  197. git-sh-setup.sh
  198. git-stash.sh
  199. git-submodule.sh
  200. git-svn.perl
  201. GIT-VERSION-GEN
  202. git-web--browse.sh
  203. git.c
  204. git.spec.in
  205. graph.c
  206. graph.h
  207. grep.c
  208. grep.h
  209. hash-object.c
  210. hash.c
  211. hash.h
  212. help.c
  213. help.h
  214. http-backend.c
  215. http-fetch.c
  216. http-push.c
  217. http-walker.c
  218. http.c
  219. http.h
  220. ident.c
  221. imap-send.c
  222. index-pack.c
  223. INSTALL
  224. levenshtein.c
  225. levenshtein.h
  226. list-objects.c
  227. list-objects.h
  228. ll-merge.c
  229. ll-merge.h
  230. lockfile.c
  231. log-tree.c
  232. log-tree.h
  233. mailmap.c
  234. mailmap.h
  235. Makefile
  236. match-trees.c
  237. merge-file.c
  238. merge-index.c
  239. merge-recursive.c
  240. merge-recursive.h
  241. merge-tree.c
  242. mktag.c
  243. name-hash.c
  244. notes.c
  245. notes.h
  246. object.c
  247. object.h
  248. pack-check.c
  249. pack-redundant.c
  250. pack-refs.c
  251. pack-refs.h
  252. pack-revindex.c
  253. pack-revindex.h
  254. pack-write.c
  255. pack.h
  256. pager.c
  257. parse-options.c
  258. parse-options.h
  259. patch-delta.c
  260. patch-id.c
  261. patch-ids.c
  262. patch-ids.h
  263. path.c
  264. pkt-line.c
  265. pkt-line.h
  266. preload-index.c
  267. pretty.c
  268. progress.c
  269. progress.h
  270. quote.c
  271. quote.h
  272. reachable.c
  273. reachable.h
  274. read-cache.c
  275. README
  276. reflog-walk.c
  277. reflog-walk.h
  278. refs.c
  279. refs.h
  280. remote-curl.c
  281. remote.c
  282. remote.h
  283. replace_object.c
  284. rerere.c
  285. rerere.h
  286. revision.c
  287. revision.h
  288. run-command.c
  289. run-command.h
  290. send-pack.h
  291. server-info.c
  292. setup.c
  293. sha1-lookup.c
  294. sha1-lookup.h
  295. sha1_file.c
  296. sha1_name.c
  297. shallow.c
  298. shell.c
  299. shortlog.h
  300. show-index.c
  301. sideband.c
  302. sideband.h
  303. sigchain.c
  304. sigchain.h
  305. strbuf.c
  306. strbuf.h
  307. string-list.c
  308. string-list.h
  309. submodule.c
  310. submodule.h
  311. symlinks.c
  312. tag.c
  313. tag.h
  314. tar.h
  315. test-chmtime.c
  316. test-ctype.c
  317. test-date.c
  318. test-delta.c
  319. test-dump-cache-tree.c
  320. test-genrandom.c
  321. test-match-trees.c
  322. test-parse-options.c
  323. test-path-utils.c
  324. test-sha1.c
  325. test-sha1.sh
  326. test-sigchain.c
  327. thread-utils.c
  328. thread-utils.h
  329. trace.c
  330. transport-helper.c
  331. transport.c
  332. transport.h
  333. tree-diff.c
  334. tree-walk.c
  335. tree-walk.h
  336. tree.c
  337. tree.h
  338. unimplemented.sh
  339. unpack-file.c
  340. unpack-trees.c
  341. unpack-trees.h
  342. upload-pack.c
  343. usage.c
  344. userdiff.c
  345. userdiff.h
  346. utf8.c
  347. utf8.h
  348. var.c
  349. walker.c
  350. walker.h
  351. wrapper.c
  352. write_or_die.c
  353. ws.c
  354. wt-status.c
  355. wt-status.h
  356. xdiff-interface.c
  357. xdiff-interface.h