summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Turner <dturner@twopensource.com>2016-07-03 03:58:07 -0400
committerJunio C Hamano <gitster@pobox.com>2016-07-06 11:22:40 -0700
commit2c8e96d61fa4c79e690d90f326756bd8fc816c06 (patch)
tree04883854c06b5c681811b86799a36ddc38d3250f
parentba004ddc07be28b4f2c5c8adb271662a050cdce8 (diff)
downloadgit-2c8e96d61fa4c79e690d90f326756bd8fc816c06.tar.gz
index-helper: kill mode
Add a new command (and command-line arg) to allow index-helpers to exit cleanly. This is mainly useful for tests. 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.c31
-rwxr-xr-xt/t7900-index-helper.sh9
3 files changed, 42 insertions, 1 deletions
diff --git a/Documentation/git-index-helper.txt b/Documentation/git-index-helper.txt
index b2ca51172d..6f63a9ef53 100644
--- a/Documentation/git-index-helper.txt
+++ b/Documentation/git-index-helper.txt
@@ -40,6 +40,9 @@ OPTIONS
--detach::
Detach from the shell.
+--kill::
+ Kill any running index-helper and clean up the socket
+
NOTES
-----
diff --git a/index-helper.c b/index-helper.c
index 1edec9207b..943197e00e 100644
--- a/index-helper.c
+++ b/index-helper.c
@@ -336,6 +336,8 @@ static void loop(int fd, int idle_in_seconds)
* alive, nothing to do.
*/
}
+ } else if (!strcmp(buf, "die")) {
+ break;
} else {
warning("BUG: Bogus command %s", buf);
}
@@ -357,10 +359,29 @@ static const char * const usage_text[] = {
NULL
};
+static void request_kill(void)
+{
+ int fd = unix_stream_connect(git_path("index-helper.sock"));
+
+ if (fd >= 0) {
+ write_in_full(fd, "die", 4);
+ close(fd);
+ }
+
+ /*
+ * The child will try to do this anyway, but we want to be
+ * ready to launch a new daemon immediately after this command
+ * returns.
+ */
+
+ unlink(git_path("index-helper.sock"));
+ return;
+}
+
int main(int argc, char **argv)
{
const char *prefix;
- int idle_in_seconds = 600, detach = 0;
+ int idle_in_seconds = 600, detach = 0, kill = 0;
int fd;
struct strbuf socket_path = STRBUF_INIT;
struct option options[] = {
@@ -369,6 +390,7 @@ int main(int argc, char **argv)
OPT_BOOL(0, "strict", &to_verify,
N_("verify shared memory after creating")),
OPT_BOOL(0, "detach", &detach, N_("detach the process")),
+ OPT_BOOL(0, "kill", &kill, N_("request that existing index helper processes exit")),
OPT_END()
};
@@ -383,6 +405,13 @@ int main(int argc, char **argv)
options, usage_text, 0))
die(_("too many arguments"));
+ if (kill) {
+ if (detach)
+ die(_("--kill doesn't want any other options"));
+ request_kill();
+ return 0;
+ }
+
atexit(cleanup);
sigchain_push_common(cleanup_on_signal);
diff --git a/t/t7900-index-helper.sh b/t/t7900-index-helper.sh
index 3bf19e03fb..a33112552b 100755
--- a/t/t7900-index-helper.sh
+++ b/t/t7900-index-helper.sh
@@ -22,4 +22,13 @@ test_expect_success 'index-helper smoke test' '
test_path_is_missing .git/index-helper.sock
'
+test_expect_success 'index-helper creates usable path file and can be killed' '
+ test_when_finished "git index-helper --kill" &&
+ test_path_is_missing .git/index-helper.sock &&
+ git index-helper --detach &&
+ test -S .git/index-helper.sock &&
+ git index-helper --kill &&
+ test_path_is_missing .git/index-helper.sock
+'
+
test_done