summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2016-07-03 03:57:59 -0400
committerJunio C Hamano <gitster@pobox.com>2016-07-06 11:22:40 -0700
commit9dc631a17b8f1f22bf480a99698df0b230fb3281 (patch)
tree314c372d9e197a27347b4aa85f59b1adf78e0a65
parent1a63c9ca18689c047a11036ae0faa42d69e45668 (diff)
downloadgit-9dc631a17b8f1f22bf480a99698df0b230fb3281.tar.gz
index-helper: add --detach
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 <pclouds@gmail.com> Signed-off-by: David Turner <dturner@twopensource.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--Documentation/git-index-helper.txt3
-rw-r--r--index-helper.c9
2 files changed, 10 insertions, 2 deletions
diff --git a/Documentation/git-index-helper.txt b/Documentation/git-index-helper.txt
index ca5a9dec7f..228b1df511 100644
--- a/Documentation/git-index-helper.txt
+++ b/Documentation/git-index-helper.txt
@@ -34,6 +34,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
-----
diff --git a/index-helper.c b/index-helper.c
index 163586a7f8..eca8ae97aa 100644
--- a/index-helper.c
+++ b/index-helper.c
@@ -17,7 +17,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)
{
@@ -36,6 +36,8 @@ static void cleanup_shm(void)
static void cleanup(void)
{
+ if (daemonized)
+ return;
unlink(git_path("index-helper.sock"));
cleanup_shm();
}
@@ -264,7 +266,7 @@ static const char * const usage_text[] = {
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[] = {
@@ -272,6 +274,7 @@ int main(int argc, char **argv)
N_("exit if not used after some seconds")),
OPT_BOOL(0, "strict", &to_verify,
N_("verify shared memory after creating")),
+ OPT_BOOL(0, "detach", &detach, N_("detach the process")),
OPT_END()
};
@@ -299,6 +302,8 @@ int main(int argc, char **argv)
die("--exit-after value must be less than %d seconds",
INT_MAX / 1000);
+ if (detach && daemonize(&daemonized))
+ die_errno(_("unable to detach"));
loop(fd, idle_in_seconds);
close(fd);