{"thread":{"id":"44548","subject":"git-daemon regression: 650c449250d7 common-main: call git_extract_argv0_path()","startedAt":"2016-11-26T14:03:57Z","lastAt":"2016-11-27T04:37:42Z","messageCount":5,"participants":["Mike Galbraith","Dennis Kaarsemaker","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"306450","messageId":"1480169028.3830.24.camel@gmail.com","threadId":"44548","inReplyTo":null,"subject":"git-daemon regression: 650c449250d7 common-main: call git_extract_argv0_path()","fromName":"Mike Galbraith","fromEmail":"umgwanakikbuti@gmail.com","sentAt":"2016-11-26T14:03:48Z","receivedAt":"2016-11-26T14:03:57Z","isPatch":false,"sender":{"key":"umgwanakikbuti@gmail.com","avatar":null},"body":"Greetings,\n\ngit-daemon went broke on me post v2.9.3 due to binaries being installed\nin /usr/lib/git, which is not in PATH.  Reverting 650c449250d7 fixes it\nup, as does ln -s /usr/lib/git/git-daemon /usr/bin/git-daemon 'course,\nbut thought I should report it, since it used to work without that.\n\nProcess 18804 attached\nrestart_syscall(<... resuming interrupted call ...>) = 1\naccept(4, {sa_family=AF_INET6, sin6_port=htons(44400), inet_pton(AF_INET6, \"::1\", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, [28]) = 5\ndup(5)                                  = 6\npipe([7, 8])                            = 0\nclone(Process 18830 attached\nchild_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f0e6061c9d0) = 18830\n[pid 18830] set_robust_list(0x7f0e6061c9e0, 24 <unfinished ...>\n[pid 18804] close(8 <unfinished ...>\n[pid 18830] <... set_robust_list resumed> ) = 0\n[pid 18804] <... close resumed> )       = 0\n[pid 18804] read(7,  <unfinished ...>\n[pid 18830] close(7)                    = 0\n[pid 18830] fcntl(8, F_GETFD)           = 0\n[pid 18830] fcntl(8, F_SETFD, FD_CLOEXEC) = 0\n[pid 18830] dup2(5, 0)                  = 0\n[pid 18830] close(5)                    = 0\n[pid 18830] dup2(6, 1)                  = 1\n[pid 18830] close(6)                    = 0\n[pid 18830] execve(\"/usr/local/sbin/git-daemon\", [\"git-daemon\", \"--serve\", \"--syslog\", \"--detach\", \"--reuseaddr\", \"--user=git\", \"--group=daemon\", \"--pid-file=/var/run/git-daemon.p\"..., \"--export-all\", \"--user-path\"], [\"CONSOLE=/dev/console\", \"LC_ALL=POSIX\", \"REDIRECT=/dev/tty7\", \"COLUMNS=320\", \"PATH=/usr/local/sbin:/usr/local/\"..., \"PWD=/\", \"LINES=90\", \"SHLVL=1\", \"LC_CTYPE=en_US.UTF-8\", \"_=/sbin/startproc\", \"PREVLEVEL=\", \"RUNLEVEL=5\", \"DAEMON=/usr/lib/git/git-daemon\", \"REMOTE_ADDR=[::1]\", \"REMOTE_PORT=44400\"]) = -1 ENOENT (No such file or directory)\n[pid 18830] execve(\"/usr/local/bin/git-daemon\", [\"git-daemon\", \"--serve\", \"--syslog\", \"--detach\", \"--reuseaddr\", \"--user=git\", \"--group=daemon\", \"--pid-file=/var/run/git-daemon.p\"..., \"--export-all\", \"--user-path\"], [\"CONSOLE=/dev/console\", \"LC_ALL=POSIX\", \"REDIRECT=/dev/tty7\", \"COLUMNS=320\", \"PATH=/usr/local/sbin:/usr/local/\"..., \"PWD=/\", \"LINES=90\", \"SHLVL=1\", \"LC_CTYPE=en_US.UTF-8\", \"_=/sbin/startproc\", \"PREVLEVEL=\", \"RUNLEVEL=5\", \"DAEMON=/usr/lib/git/git-daemon\", \"REMOTE_ADDR=[::1]\", \"REMOTE_PORT=44400\"]) = -1 ENOENT (No such file or directory)\n[pid 18830] execve(\"/usr/sbin/git-daemon\", [\"git-daemon\", \"--serve\", \"--syslog\", \"--detach\", \"--reuseaddr\", \"--user=git\", \"--group=daemon\", \"--pid-file=/var/run/git-daemon.p\"..., \"--export-all\", \"--user-path\"], [\"CONSOLE=/dev/console\", \"LC_ALL=POSIX\", \"REDIRECT=/dev/tty7\", \"COLUMNS=320\", \"PATH=/usr/local/sbin:/usr/local/\"..., \"PWD=/\", \"LINES=90\", \"SHLVL=1\", \"LC_CTYPE=en_US.UTF-8\", \"_=/sbin/startproc\", \"PREVLEVEL=\", \"RUNLEVEL=5\", \"DAEMON=/usr/lib/git/git-daemon\", \"REMOTE_ADDR=[::1]\", \"REMOTE_PORT=44400\"]) = -1 ENOENT (No such file or directory)\n[pid 18830] execve(\"/usr/bin/git-daemon\", [\"git-daemon\", \"--serve\", \"--syslog\", \"--detach\", \"--reuseaddr\", \"--user=git\", \"--group=daemon\", \"--pid-file=/var/run/git-daemon.p\"..., \"--export-all\", \"--user-path\"], [\"CONSOLE=/dev/console\", \"LC_ALL=POSIX\", \"REDIRECT=/dev/tty7\", \"COLUMNS=320\", \"PATH=/usr/local/sbin:/usr/local/\"..., \"PWD=/\", \"LINES=90\", \"SHLVL=1\", \"LC_CTYPE=en_US.UTF-8\", \"_=/sbin/startproc\", \"PREVLEVEL=\", \"RUNLEVEL=5\", \"DAEMON=/usr/lib/git/git-daemon\", \"REMOTE_ADDR=[::1]\", \"REMOTE_PORT=44400\"]) = -1 ENOENT (No such file or directory)\n[pid 18830] execve(\"/sbin/git-daemon\", [\"git-daemon\", \"--serve\", \"--syslog\", \"--detach\", \"--reuseaddr\", \"--user=git\", \"--group=daemon\", \"--pid-file=/var/run/git-daemon.p\"..., \"--export-all\", \"--user-path\"], [\"CONSOLE=/dev/console\", \"LC_ALL=POSIX\", \"REDIRECT=/dev/tty7\", \"COLUMNS=320\", \"PATH=/usr/local/sbin:/usr/local/\"..., \"PWD=/\", \"LINES=90\", \"SHLVL=1\", \"LC_CTYPE=en_US.UTF-8\", \"_=/sbin/startproc\", \"PREVLEVEL=\", \"RUNLEVEL=5\", \"DAEMON=/usr/lib/git/git-daemon\", \"REMOTE_ADDR=[::1]\", \"REMOTE_PORT=44400\"]) = -1 ENOENT (No such file or directory)\n[pid 18830] execve(\"/bin/git-daemon\", [\"git-daemon\", \"--serve\", \"--syslog\", \"--detach\", \"--reuseaddr\", \"--user=git\", \"--group=daemon\", \"--pid-file=/var/run/git-daemon.p\"..., \"--export-all\", \"--user-path\"], [\"CONSOLE=/dev/console\", \"LC_ALL=POSIX\", \"REDIRECT=/dev/tty7\", \"COLUMNS=320\", \"PATH=/usr/local/sbin:/usr/local/\"..., \"PWD=/\", \"LINES=90\", \"SHLVL=1\", \"LC_CTYPE=en_US.UTF-8\", \"_=/sbin/startproc\", \"PREVLEVEL=\", \"RUNLEVEL=5\", \"DAEMON=/usr/lib/git/git-daemon\", \"REMOTE_ADDR=[::1]\", \"REMOTE_PORT=44400\"]) = -1 ENOENT (No such file or directory)\n[pid 18830] fstat(2, {st_dev=makedev(0, 6), st_ino=1029, st_mode=S_IFCHR|0666, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=0, st_rdev=makedev(1, 3), st_atime=2016/11/26-00:42:47, st_mtime=2016/11/26-00:42:47, st_ctime=2016/11/26-00:42:47}) = 0\n[pid 18830] ioctl(2, TCGETS, 0x7ffe6dbd09b0) = -1 ENOTTY (Inappropriate ioctl for device)\n[pid 18830] mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f0e60632000\n[pid 18830] write(2, \"error: cannot run git-daemon: No\"..., 56) = 56\n[pid 18830] write(8, \"\\0\", 1)           = 1\n[pid 18804] <... read resumed> \"\\0\", 1) = 1\n[pid 18830] exit_group(127)             = ?\n[pid 18804] wait4(18830,  <unfinished ...>\n[pid 18830] +++ exited with 127 +++\n<... wait4 resumed> [{WIFEXITED(s) && WEXITSTATUS(s) == 127}], 0, NULL) = 18830\n--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=18830, si_uid=1002, si_status=127, si_utime=0, si_stime=0} ---\nrt_sigaction(SIGCHLD, {0x404e10, [CHLD], SA_RESTORER|SA_RESTART, 0x7f0e5f6a7140}, {0x404e10, [CHLD], SA_RESTORER|SA_RESTART, 0x7f0e5f6a7140}, 8) = 0\nrt_sigreturn({mask=[]})                 = 18830\nclose(7)                                = 0\nclose(5)                                = 0\nclose(6)                                = 0\nopen(\"/etc/localtime\", O_RDONLY|O_CLOEXEC) = 5\nfstat(5, {st_dev=makedev(8, 5), st_ino=6031966, st_mode=S_IFREG|0644, st_nlink=2, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=8, st_size=2335, st_atime=2016/11/26-01:00:02, st_mtime=2016/11/08-18:09:53, st_ctime=2016/11/09-21:15:24}) = 0\nfstat(5, {st_dev=makedev(8, 5), st_ino=6031966, st_mode=S_IFREG|0644, st_nlink=2, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=8, st_size=2335, st_atime=2016/11/26-01:00:02, st_mtime=2016/11/08-18:09:53, st_ctime=2016/11/09-21:15:24}) = 0\nmmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f0e60632000\nread(5, \"TZif2\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\t\\0\\0\\0\\t\\0\\0\\0\\0\"..., 4096) = 2335\nlseek(5, -1476, SEEK_CUR)               = 859\nread(5, \"TZif2\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\t\\0\\0\\0\\t\\0\\0\\0\\0\"..., 4096) = 1476\nclose(5)                                = 0\nmunmap(0x7f0e60632000, 4096)            = 0\nsocket(PF_LOCAL, SOCK_DGRAM|SOCK_CLOEXEC, 0) = 5\nconnect(5, {sa_family=AF_LOCAL, sun_path=\"/dev/log\"}, 110) = 0\nsendto(5, \"<27>Nov 26 14:25:55 git-daemon[1\"..., 53, MSG_NOSIGNAL, NULL, 0) = 53\npoll([{fd=3, events=POLLIN}, {fd=4, events=POLLIN}], 2, 4294967295\n\nrevert 650c449250d7\n\nProcess 18934 attached\nrestart_syscall(<... resuming interrupted call ...>) = 1\naccept(4, {sa_family=AF_INET6, sin6_port=htons(44404), inet_pton(AF_INET6, \"::1\", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, [28]) = 5\ndup(5)                                  = 6\npipe([7, 8])                            = 0\nclone(Process 19010 attached\nchild_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f62fcb5e9d0) = 19010\n[pid 18934] close(8 <unfinished ...>\n[pid 19010] set_robust_list(0x7f62fcb5e9e0, 24) = 0\n[pid 18934] <... close resumed> )       = 0\n[pid 18934] read(7,  <unfinished ...>\n[pid 19010] close(7)                    = 0\n[pid 19010] fcntl(8, F_GETFD)           = 0\n[pid 19010] fcntl(8, F_SETFD, FD_CLOEXEC) = 0\n[pid 19010] dup2(5, 0)                  = 0\n[pid 19010] close(5)                    = 0\n[pid 19010] dup2(6, 1)                  = 1\n[pid 19010] close(6)                    = 0\n[pid 19010] execve(\"/usr/lib/git/git-daemon\", [\"/usr/lib/git/git-daemon\", \"--serve\", \"--syslog\", \"--detach\", \"--reuseaddr\", \"--user=git\", \"--group=daemon\", \"--pid-file=/var/run/git-daemon.p\"..., \"--export-all\", \"--user-path\"], [\"CONSOLE=/dev/console\", \"LC_ALL=POSIX\", \"REDIRECT=/dev/tty7\", \"COLUMNS=320\", \"PATH=/usr/local/sbin:/usr/local/\"..., \"PWD=/\", \"LINES=90\", \"SHLVL=1\", \"LC_CTYPE=en_US.UTF-8\", \"_=/sbin/startproc\", \"PREVLEVEL=\", \"RUNLEVEL=5\", \"DAEMON=/usr/lib/git/git-daemon\", \"REMOTE_ADDR=[::1]\", \"REMOTE_PORT=44404\"] <unfinished ...>\n[pid 18934] <... read resumed> \"\", 1)   = 0\n[pid 19010] <... execve resumed> )      = 0\n.... works\n\n\nln -s /usr/lib/git/git-daemon /usr/bin/git-daemon\n\n\nProcess 19862 attached\nrestart_syscall(<... resuming interrupted call ...>) = 1\naccept(4, {sa_family=AF_INET6, sin6_port=htons(44412), inet_pton(AF_INET6, \"::1\", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, [28]) = 5\ndup(5)                                  = 6\npipe([7, 8])                            = 0\nclone(Process 19915 attached\nchild_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fc97962e9d0) = 19915\n[pid 19862] close(8)                    = 0\n[pid 19915] set_robust_list(0x7fc97962e9e0, 24 <unfinished ...>\n[pid 19862] read(7,  <unfinished ...>\n[pid 19915] <... set_robust_list resumed> ) = 0\n[pid 19915] close(7)                    = 0\n[pid 19915] fcntl(8, F_GETFD)           = 0\n[pid 19915] fcntl(8, F_SETFD, FD_CLOEXEC) = 0\n[pid 19915] dup2(5, 0)                  = 0\n[pid 19915] close(5)                    = 0\n[pid 19915] dup2(6, 1)                  = 1\n[pid 19915] close(6)                    = 0\n[pid 19915] execve(\"/usr/local/sbin/git-daemon\", [\"git-daemon\", \"--serve\", \"--syslog\", \"--detach\", \"--reuseaddr\", \"--user=git\", \"--group=daemon\", \"--pid-file=/var/run/git-daemon.p\"..., \"--export-all\", \"--user-path\"], [\"CONSOLE=/dev/console\", \"LC_ALL=POSIX\", \"REDIRECT=/dev/tty7\", \"COLUMNS=320\", \"PATH=/usr/local/sbin:/usr/local/\"..., \"PWD=/\", \"LINES=90\", \"SHLVL=1\", \"LC_CTYPE=en_US.UTF-8\", \"_=/sbin/startproc\", \"PREVLEVEL=\", \"RUNLEVEL=5\", \"DAEMON=/usr/lib/git/git-daemon\", \"REMOTE_ADDR=[::1]\", \"REMOTE_PORT=44412\"]) = -1 ENOENT (No such file or directory)\n[pid 19915] execve(\"/usr/local/bin/git-daemon\", [\"git-daemon\", \"--serve\", \"--syslog\", \"--detach\", \"--reuseaddr\", \"--user=git\", \"--group=daemon\", \"--pid-file=/var/run/git-daemon.p\"..., \"--export-all\", \"--user-path\"], [\"CONSOLE=/dev/console\", \"LC_ALL=POSIX\", \"REDIRECT=/dev/tty7\", \"COLUMNS=320\", \"PATH=/usr/local/sbin:/usr/local/\"..., \"PWD=/\", \"LINES=90\", \"SHLVL=1\", \"LC_CTYPE=en_US.UTF-8\", \"_=/sbin/startproc\", \"PREVLEVEL=\", \"RUNLEVEL=5\", \"DAEMON=/usr/lib/git/git-daemon\", \"REMOTE_ADDR=[::1]\", \"REMOTE_PORT=44412\"]) = -1 ENOENT (No such file or directory)\n[pid 19915] execve(\"/usr/sbin/git-daemon\", [\"git-daemon\", \"--serve\", \"--syslog\", \"--detach\", \"--reuseaddr\", \"--user=git\", \"--group=daemon\", \"--pid-file=/var/run/git-daemon.p\"..., \"--export-all\", \"--user-path\"], [\"CONSOLE=/dev/console\", \"LC_ALL=POSIX\", \"REDIRECT=/dev/tty7\", \"COLUMNS=320\", \"PATH=/usr/local/sbin:/usr/local/\"..., \"PWD=/\", \"LINES=90\", \"SHLVL=1\", \"LC_CTYPE=en_US.UTF-8\", \"_=/sbin/startproc\", \"PREVLEVEL=\", \"RUNLEVEL=5\", \"DAEMON=/usr/lib/git/git-daemon\", \"REMOTE_ADDR=[::1]\", \"REMOTE_PORT=44412\"]) = -1 ENOENT (No such file or directory)\n[pid 19915] execve(\"/usr/bin/git-daemon\", [\"git-daemon\", \"--serve\", \"--syslog\", \"--detach\", \"--reuseaddr\", \"--user=git\", \"--group=daemon\", \"--pid-file=/var/run/git-daemon.p\"..., \"--export-all\", \"--user-path\"], [\"CONSOLE=/dev/console\", \"LC_ALL=POSIX\", \"REDIRECT=/dev/tty7\", \"COLUMNS=320\", \"PATH=/usr/local/sbin:/usr/local/\"..., \"PWD=/\", \"LINES=90\", \"SHLVL=1\", \"LC_CTYPE=en_US.UTF-8\", \"_=/sbin/startproc\", \"PREVLEVEL=\", \"RUNLEVEL=5\", \"DAEMON=/usr/lib/git/git-daemon\", \"REMOTE_ADDR=[::1]\", \"REMOTE_PORT=44412\"] <unfinished ...>\n[pid 19862] <... read resumed> \"\", 1)   = 0\n[pid 19915] <... execve resumed> )      = 0\n.... works\n\n\n"},{"id":"306452","messageId":"1480179391.10220.19.camel@kaarsemaker.net","threadId":"44548","inReplyTo":"1480169028.3830.24.camel@gmail.com","subject":"Re: git-daemon regression: 650c449250d7 common-main: call git_extract_argv0_path()","fromName":"Dennis Kaarsemaker","fromEmail":"dennis@kaarsemaker.net","sentAt":"2016-11-26T16:56:31Z","receivedAt":"2016-11-26T16:56:40Z","isPatch":false,"sender":{"key":"dennis@kaarsemaker.net","avatar":"https://avatars.githubusercontent.com/u/200649?v=4"},"body":"Hi Mike,\n\nOn Sat, 2016-11-26 at 15:03 +0100, Mike Galbraith wrote:\n> Greetings,\n> \n> git-daemon went broke on me post v2.9.3 due to binaries being installed\n> in /usr/lib/git, which is not in PATH.  Reverting 650c449250d7 fixes it\n> up, as does ln -s /usr/lib/git/git-daemon /usr/bin/git-daemon 'course,\n> but thought I should report it, since it used to work without that.\n\nI don't know how you usually install git, but git-daemon is not\nsupposed to be in $PATH, the correct way to invoke the git daemon is\n'git daemon' not 'git-daemon'\n\nHaving all subcommands of git as separate binaries in your $PATH is an\nancient git.git practice that stopped being used/supported quite a\nwhile ago.\n\nI don't know why this patch broke that obsolete practice, but hopefully\nthis can help you forward.\n\nD.\n"},{"id":"306453","messageId":"20161126170933.6tge6j5etuchqy33@sigill.intra.peff.net","threadId":"44548","inReplyTo":"1480169028.3830.24.camel@gmail.com","subject":"Re: git-daemon regression: 650c449250d7 common-main: call git_extract_argv0_path()","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-11-26T17:09:33Z","receivedAt":"2016-11-26T17:09:49Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Nov 26, 2016 at 03:03:48PM +0100, Mike Galbraith wrote:\n\n> git-daemon went broke on me post v2.9.3 due to binaries being installed\n> in /usr/lib/git, which is not in PATH.  Reverting 650c449250d7 fixes it\n> up, as does ln -s /usr/lib/git/git-daemon /usr/bin/git-daemon 'course,\n> but thought I should report it, since it used to work without that.\n\nGenerally /usr/lib/git _should_ be in your PATH, as it is added by the\ngit wrapper when you run \"git daemon\".\n\nThe only behavior difference caused by 650c449250d7 is that we replace\nargv[0] with the output of git_extract_argv0_path(argv[0]), which will\ngive the basename, not a full path. So presumably you are running:\n\n  /usr/lib/git/git-daemon\n\ndirectly. I'm not sure that's even supposed to work these days, and it\nwas not just a happy accident that it did.\n\nOn the other hand, I am sympathetic that something used to work and now\ndoesn't. It probably wouldn't be that hard to work around it.\n\nThe reason for the behavior change is that one of the cmd_main()\nfunctions was relying on the basename side-effect of the\nextract_argv0_path function, so 650c449250d7 just feeds the munged\nargv[0] to all of the programs. The cleanest fix would probably be\nsomething like:\n\ndiff --git a/common-main.c b/common-main.c\nindex 44a29e8b1..c654f9555 100644\n--- a/common-main.c\n+++ b/common-main.c\n@@ -33,7 +33,7 @@ int main(int argc, const char **argv)\n \n \tgit_setup_gettext();\n \n-\targv[0] = git_extract_argv0_path(argv[0]);\n+\tgit_extract_argv0_path(argv[0]);\n \n \trestore_sigpipe_to_default();\n \ndiff --git a/git.c b/git.c\nindex bd66a2e0a..05986680c 100644\n--- a/git.c\n+++ b/git.c\n@@ -730,6 +730,11 @@ int cmd_main(int argc, const char **argv)\n \tcmd = argv[0];\n \tif (!cmd)\n \t\tcmd = \"git-help\";\n+\telse {\n+\t\tconst char *base = find_last_dir_sep(cmd);\n+\t\tif (base)\n+\t\t\tcmd = base + 1;\n+\t}\n \n \ttrace_command_performance(argv);\n \ttrace_stdin();\n\n-Peff\n"},{"id":"306454","messageId":"1480182671.3830.38.camel@gmail.com","threadId":"44548","inReplyTo":"20161126170933.6tge6j5etuchqy33@sigill.intra.peff.net","subject":"Re: git-daemon regression: 650c449250d7 common-main: call git_extract_argv0_path()","fromName":"Mike Galbraith","fromEmail":"umgwanakikbuti@gmail.com","sentAt":"2016-11-26T17:51:11Z","receivedAt":"2016-11-26T17:51:20Z","isPatch":false,"sender":{"key":"umgwanakikbuti@gmail.com","avatar":null},"body":"On Sat, 2016-11-26 at 12:09 -0500, Jeff King wrote:\n> On Sat, Nov 26, 2016 at 03:03:48PM +0100, Mike Galbraith wrote:\n> \n> > git-daemon went broke on me post v2.9.3 due to binaries being installed\n> > in /usr/lib/git, which is not in PATH.  Reverting 650c449250d7 fixes it\n> > up, as does ln -s /usr/lib/git/git-daemon /usr/bin/git-daemon 'course,\n> > but thought I should report it, since it used to work without that.\n> \n> Generally /usr/lib/git _should_ be in your PATH, as it is added by the\n> git wrapper when you run \"git daemon\".\n> \n> The only behavior difference caused by 650c449250d7 is that we replace\n> argv[0] with the output of git_extract_argv0_path(argv[0]), which will\n> give the basename, not a full path. So presumably you are running:\n> \n>   /usr/lib/git/git-daemon\n> \n> directly. I'm not sure that's even supposed to work these days, and it\n> was not just a happy accident that it did.\n\nAh.  I'm using suse's rpm glue to package my modified source, and its\nstartup script still calls it directly, so wants some modernization.\n\n> On the other hand, I am sympathetic that something used to work and now\n> doesn't. It probably wouldn't be that hard to work around it.\n> \n> The reason for the behavior change is that one of the cmd_main()\n> functions was relying on the basename side-effect of the\n> extract_argv0_path function, so 650c449250d7 just feeds the munged\n> argv[0] to all of the programs. The cleanest fix would probably be\n> something like:\n\nThat did fix it up, thanks.  I'll try twiddling the script instead.\n\n> diff --git a/common-main.c b/common-main.c\n> index 44a29e8b1..c654f9555 100644\n> --- a/common-main.c\n> +++ b/common-main.c\n> @@ -33,7 +33,7 @@ int main(int argc, const char **argv)\n>  \n>  > \t> git_setup_gettext();\n>  \n> -> \t> argv[0] = git_extract_argv0_path(argv[0]);\n> +> \t> git_extract_argv0_path(argv[0]);\n>  \n>  > \t> restore_sigpipe_to_default();\n>  \n> diff --git a/git.c b/git.c\n> index bd66a2e0a..05986680c 100644\n> --- a/git.c\n> +++ b/git.c\n> @@ -730,6 +730,11 @@ int cmd_main(int argc, const char **argv)\n>  > \t> cmd = argv[0];\n>  > \t> if (!cmd)\n>  > \t> \t> cmd = \"git-help\";\n> +> \t> else {\n> +> \t> \t> const char *base = find_last_dir_sep(cmd);\n> +> \t> \t> if (base)\n> +> \t> \t> \t> cmd = base + 1;\n> +> \t> }\n>  \n>  > \t> trace_command_performance(argv);\n>  > \t> trace_stdin();\n> \n> -Peff\n"},{"id":"306456","messageId":"20161127043113.opirwcpda6lboxmi@sigill.intra.peff.net","threadId":"44548","inReplyTo":"1480182671.3830.38.camel@gmail.com","subject":"[PATCH] common-main: stop munging argv[0] path","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-11-27T04:31:13Z","receivedAt":"2016-11-27T04:37:42Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Nov 26, 2016 at 06:51:11PM +0100, Mike Galbraith wrote:\n\n> > On the other hand, I am sympathetic that something used to work and now\n> > doesn't. It probably wouldn't be that hard to work around it.\n> > \n> > The reason for the behavior change is that one of the cmd_main()\n> > functions was relying on the basename side-effect of the\n> > extract_argv0_path function, so 650c449250d7 just feeds the munged\n> > argv[0] to all of the programs. The cleanest fix would probably be\n> > something like:\n> \n> That did fix it up, thanks.  I'll try twiddling the script instead.\n\nThanks for confirming. Here it is, with a commit message and a little\nbit of polish.\n\n-- >8 --\nSubject: [PATCH] common-main: stop munging argv[0] path\n\nSince 650c44925 (common-main: call git_extract_argv0_path(),\n2016-07-01), the argv[0] that is seen in cmd_main() of\nindividual programs is always the basename of the\nexecutable, as common-main strips off the full path. This\ncan produce confusing results for git-daemon, which wants to\nre-exec itself.\n\nFor instance, if the program was originally run as\n\"/usr/lib/git/git-daemon\", it will try just re-execing\n\"git-daemon\", which will find the first instance in $PATH.\nIf git's exec-path has not been prepended to $PATH, we may\nfind the git-daemon from a different version (or no\ngit-daemon at all).\n\nNormally this isn't a problem. Git commands are run as \"git\ndaemon\", the git wrapper puts the exec-path at the front of\n$PATH, and argv[0] is already \"daemon\" anyway. But running\ngit-daemon via its full exec-path, while not really a\nrecommended method, did work prior to 650c44925. Let's make\nit work again.\n\nThe real goal of 650c44925 was not to munge argv[0], but to\nreliably set the argv0_path global. The only reason it\nmunges at all is that one caller, the git.c wrapper,\npiggy-backed on that computation to find the command\nbasename.  Instead, let's leave argv[0] untouched in\ncommon-main, and have git.c do its own basename computation.\n\nWhile we're at it, let's drop the return value from\ngit_extract_argv0_path(). It was only ever used in this one\ncallsite, and its dual purposes is what led to this\nconfusion in the first place.\n\nNote that by changing the interface, the compiler can\nconfirm for us that there are no other callers storing the\nreturn value. But the compiler can't tell us whether any of\nthe cmd_main() functions (besides git.c) were relying on the\nbasename munging. However, we can observe that prior to\n650c44925, no other cmd_main() functions did that munging,\nand no new cmd_main() functions have been introduced since\nthen. So we can't be regressing any of those cases.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n common-main.c |  2 +-\n exec_cmd.c    | 10 +++-------\n exec_cmd.h    |  2 +-\n git.c         |  5 +++++\n 4 files changed, 10 insertions(+), 9 deletions(-)\n\ndiff --git a/common-main.c b/common-main.c\nindex 44a29e8b1..c654f9555 100644\n--- a/common-main.c\n+++ b/common-main.c\n@@ -33,7 +33,7 @@ int main(int argc, const char **argv)\n \n \tgit_setup_gettext();\n \n-\targv[0] = git_extract_argv0_path(argv[0]);\n+\tgit_extract_argv0_path(argv[0]);\n \n \trestore_sigpipe_to_default();\n \ndiff --git a/exec_cmd.c b/exec_cmd.c\nindex 9d5703a15..19ac2146d 100644\n--- a/exec_cmd.c\n+++ b/exec_cmd.c\n@@ -38,21 +38,17 @@ char *system_path(const char *path)\n \treturn strbuf_detach(&d, NULL);\n }\n \n-const char *git_extract_argv0_path(const char *argv0)\n+void git_extract_argv0_path(const char *argv0)\n {\n \tconst char *slash;\n \n \tif (!argv0 || !*argv0)\n-\t\treturn NULL;\n+\t\treturn;\n \n \tslash = find_last_dir_sep(argv0);\n \n-\tif (slash) {\n+\tif (slash)\n \t\targv0_path = xstrndup(argv0, slash - argv0);\n-\t\treturn slash + 1;\n-\t}\n-\n-\treturn argv0;\n }\n \n void git_set_argv_exec_path(const char *exec_path)\ndiff --git a/exec_cmd.h b/exec_cmd.h\nindex 1f6b43378..ff0b48048 100644\n--- a/exec_cmd.h\n+++ b/exec_cmd.h\n@@ -4,7 +4,7 @@\n struct argv_array;\n \n extern void git_set_argv_exec_path(const char *exec_path);\n-extern const char *git_extract_argv0_path(const char *path);\n+extern void git_extract_argv0_path(const char *path);\n extern const char *git_exec_path(void);\n extern void setup_path(void);\n extern const char **prepare_git_cmd(struct argv_array *out, const char **argv);\ndiff --git a/git.c b/git.c\nindex e8b2baf2d..dce529fcb 100644\n--- a/git.c\n+++ b/git.c\n@@ -654,6 +654,11 @@ int cmd_main(int argc, const char **argv)\n \tcmd = argv[0];\n \tif (!cmd)\n \t\tcmd = \"git-help\";\n+\telse {\n+\t\tconst char *slash = find_last_dir_sep(cmd);\n+\t\tif (slash)\n+\t\t\tcmd = slash + 1;\n+\t}\n \n \ttrace_command_performance(argv);\n \n-- \n2.11.0.rc3.313.g1055eca\n\n"}]}