unix-socket: handle long socket pathnames

On many systems, the sockaddr_un.sun_path field is quite
small. Even on Linux, it is only 108 characters. A user of
the credential-cache daemon can easily surpass this,
especially if their home directory is in a deep directory
tree (since the default location expands ~/.git-credentials).

We can hack around this in the unix-socket.[ch] code by
doing a chdir() to the enclosing directory, feeding the
relative basename to the socket functions, and then
restoring the working directory.

This introduces several new possible error cases for
creating a socket, including an irrecoverable one in the
case that we can't restore the working directory. In the
case of the credential-cache code, we could perhaps get away
with simply chdir()-ing to the socket directory and never
coming back. However, I'd rather do it at the lower level
for a few reasons:

  1. It keeps the hackery behind an opaque interface instead
     of polluting the main program logic.

  2. A hack in credential-cache won't help any unix-socket
     users who come along later.

  3. The chdir trickery isn't that likely to fail (basically
     it's only a problem if your cwd is missing or goes away
     while you're running).  And because we only enable the
     hack when we get a too-long name, it can only fail in
     cases that would have failed under the previous code
     anyway.

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