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@xxxxxxxxxxxxxxxx> --- index-helper.c | 31 ++++++++++++++++++++++++++++++- t/t7900-index-helper.sh | 12 ++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/index-helper.c b/index-helper.c index 1d30400..3e0990e 100644 --- a/index-helper.c +++ b/index-helper.c @@ -395,6 +395,8 @@ static void loop(int fd, int idle_in_seconds) * alive, nothing to do. */ } + } else if (!strcmp(command.buf, "die")) { + break; } else { warning("BUG: Bogus command %s", command.buf); } @@ -425,10 +427,29 @@ static const char * const usage_text[] = { NULL }; +static void request_kill(void) +{ + int fd = connect_to_index_helper(); + + 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.path")); + 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[] = { @@ -437,6 +458,7 @@ int main(int argc, char **argv) OPT_BOOL(0, "strict", &to_verify, "verify shared memory after creating"), OPT_BOOL(0, "detach", &detach, "detach the process"), + OPT_BOOL(0, "kill", &kill, "request that existing index helper processes exit"), OPT_END() }; @@ -451,6 +473,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 c127ed7..fdb0d7b 100755 --- a/t/t7900-index-helper.sh +++ b/t/t7900-index-helper.sh @@ -20,4 +20,16 @@ test_expect_success 'index-helper smoke test' ' test_path_is_missing .git/index-helper.path ' +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.path && + git index-helper --detach && + test -L .git/index-helper.path && + dir="$(readlink .git/index-helper.path)" && + test -S "$dir/s" && + ls -ld "$dir" | grep ^drwx...--- && + git index-helper --kill && + test_path_is_missing .git/index-helper.path +' + test_done -- 2.4.2.767.g62658d5-twtrsrc -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html