From: David Turner Date: Sun, 03 Jul 2016 07:58:08 GMT Subject: [PATCH v14 16/21] index-helper: don't run if already running Message-ID: <1467532693-20017-17-git-send-email-novalis@novalis.org> In-Reply-To: <1467532693-20017-1-git-send-email-novalis@novalis.org> From: David Turner Signed-off-by: David Turner Signed-off-by: Junio C Hamano --- index-helper.c | 7 +++++++ t/t7900-index-helper.sh | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/index-helper.c b/index-helper.c index 943197e..feb09fb 100644 --- a/index-helper.c +++ b/index-helper.c @@ -412,6 +412,13 @@ int main(int argc, char **argv) return 0; } + /* check that no other copy is running */ + fd = unix_stream_connect(git_path("index-helper.sock")); + if (fd >= 0) + die(_("Already running")); + if (errno != ECONNREFUSED && errno != ENOENT) + die_errno(_("Unexpected error checking socket")); + atexit(cleanup); sigchain_push_common(cleanup_on_signal); diff --git a/t/t7900-index-helper.sh b/t/t7900-index-helper.sh index a331125..21f1358 100755 --- a/t/t7900-index-helper.sh +++ b/t/t7900-index-helper.sh @@ -31,4 +31,13 @@ test_expect_success 'index-helper creates usable path file and can be killed' ' test_path_is_missing .git/index-helper.sock ' +test_expect_success 'index-helper will not start if already running' ' + test_when_finished "git index-helper --kill" && + git index-helper --detach && + test -S .git/index-helper.sock && + test_must_fail git index-helper 2>err && + test -S .git/index-helper.sock && + grep "Already running" err +' + test_done -- 1.9.1