From: Nguyễn Thái Ngọc Duy <pclo...@gmail.com>

We detach after creating and opening the socket, because otherwise
we might return control to the shell before index-helper is ready to
accept commands.  This might lead to flaky tests.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclo...@gmail.com>
---
 Documentation/git-index-helper.txt |  3 +++
 index-helper.c                     | 11 +++++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-index-helper.txt 
b/Documentation/git-index-helper.txt
index b177fb8..bb344cf 100644
--- a/Documentation/git-index-helper.txt
+++ b/Documentation/git-index-helper.txt
@@ -31,6 +31,9 @@ OPTIONS
        for reading an index, but because it will happen in the
        background, it's not noticable. `--strict` is enabled by default.
 
+--detach::
+       Detach from the shell.
+
 NOTES
 -----
 $GIT_DIR/index-helper.path is a symlink to a Unix domain socket in
diff --git a/index-helper.c b/index-helper.c
index 8288e30..10f29f5 100644
--- a/index-helper.c
+++ b/index-helper.c
@@ -15,7 +15,7 @@ struct shm {
 
 static struct shm shm_index;
 static struct shm shm_base_index;
-static int to_verify = 1;
+static int daemonized, to_verify = 1;
 
 static void release_index_shm(struct shm *is)
 {
@@ -34,6 +34,8 @@ static void cleanup_shm(void)
 
 static void cleanup(void)
 {
+       if (daemonized)
+               return;
        unlink(git_path("index-helper.path"));
        cleanup_shm();
 }
@@ -289,7 +291,7 @@ static void make_socket_path(struct strbuf *path)
 int main(int argc, char **argv)
 {
        const char *prefix;
-       int idle_in_seconds = 600;
+       int idle_in_seconds = 600, detach = 0;
        int fd;
        struct strbuf socket_path = STRBUF_INIT;
        struct option options[] = {
@@ -297,6 +299,7 @@ int main(int argc, char **argv)
                            N_("exit if not used after some seconds")),
                OPT_BOOL(0, "strict", &to_verify,
                         "verify shared memory after creating"),
+               OPT_BOOL(0, "detach", &detach, "detach the process"),
                OPT_END()
        };
 
@@ -326,6 +329,10 @@ int main(int argc, char **argv)
                die(_("failed to delete old index-helper.path"));
        if (symlink(socket_path.buf, git_path("index-helper.path")))
                die(_("failed to symlink socket path into index-helper.path"));
+
+       if (detach && daemonize(&daemonized))
+               die_errno(_("unable to detach"));
+
        loop(fd, idle_in_seconds);
 
        return 0;
-- 
2.4.2.767.g62658d5-twtrsrc

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to