{"thread":{"id":"41461","subject":"Re: [PATCH] credential-cache--daemon: Change to root dir on startup","startedAt":"2016-02-21T23:52:26Z","lastAt":"2016-02-21T23:52:26Z","messageCount":1,"participants":["Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"278804","messageId":"20160221235225.GE4094@sigill.intra.peff.net","threadId":"41461","inReplyTo":"1456037497-9895-1-git-send-email-jon_p_griffiths@yahoo.com","subject":"Re: [PATCH] credential-cache--daemon: Change to root dir on startup","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-02-21T23:52:26Z","receivedAt":"2016-02-21T23:52:26Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Feb 21, 2016 at 07:51:37PM +1300, Jon Griffiths wrote:\n\n> Stop the daemon from preventing umount of the directory it\n> was started in.\n> \n> Without this change the daemon prevents umount because it\n> it holds open its cwd. If it starts in a directory we want\n> to unmount we have to manually kill the process which is\n> undesirable and also uncaches any credentials it is holding.\n> \n> Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>\n> ---\n>  credential-cache--daemon.c | 2 ++\n>  1 file changed, 2 insertions(+)\n> \n> diff --git a/credential-cache--daemon.c b/credential-cache--daemon.c\n> index cc65a9c..d911b40 100644\n> --- a/credential-cache--daemon.c\n> +++ b/credential-cache--daemon.c\n> @@ -270,6 +270,8 @@ int main(int argc, const char **argv)\n>  \tif (ignore_sighup)\n>  \t\tsignal(SIGHUP, SIG_IGN);\n>  \n> +\tchdir(\"/\");\n> +\n>  \tserve_cache(socket_path, debug);\n>  \tdelete_tempfile(&socket_file);\n\nWhat happens if socket_path is relative here?\n\nI don't know how common that would be in practice. In general, the\ndaemon is running out of $GIT_DIR or the top-level of the work-tree, I'd\nguess, which is inappropriate for any user-level config, and probably\nsimply confusing even for repo-level config. I'm actually tempted to\njust disallow relative paths entirely.\n\nI think your patch _just_ helps the case where the git repository is\nbeing unmounted (and our daemon's cwd happened to be there). It doesn't\nhelp the case that the socket path is unmounted (which will still get\nEBUSY because we have the socket open).\n\nI can't think of any reason that chdir() to \"/\" would be a bad thing (if\nyou get EPERM going to \"/\", you probably have bigger problems), but\nanother option would be:\n\n  1. chdir(dirname(socket_path));\n\n  2. serve_cache(basename(socket_path));\n\nThat works with relative paths, and it puts all of our open files in the\nsame part of the hierarchy.\n\n-Peff\n"}]}