From: David Turner Date: Sat, 19 Mar 2016 01:04:47 GMT Subject: [PATCH v2 14/17] index-helper: don't run if already running Message-ID: <1458349490-1704-15-git-send-email-dturner@twopensource.com> In-Reply-To: <1458349490-1704-1-git-send-email-dturner@twopensource.com> Signed-off-by: David Turner --- 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 ffa3c2a..7362abb 100644 --- a/index-helper.c +++ b/index-helper.c @@ -400,6 +400,13 @@ int main(int argc, char **argv) return 0; } + /* check that no other copy is running */ + fd = open(pipe_path.buf, O_RDONLY | O_NONBLOCK); + if (fd > 0) + die(_("Already running")); + if (errno != ENXIO && errno != ENOENT) + die_errno(_("Unexpected error checking pipe")); + atexit(cleanup); sigchain_push_common(cleanup_on_signal); diff --git a/t/t7900-index-helper.sh b/t/t7900-index-helper.sh index 14b5a6c..ce0cc27 100755 --- a/t/t7900-index-helper.sh +++ b/t/t7900-index-helper.sh @@ -24,4 +24,13 @@ test_expect_success 'index-helper creates usable pipe file and can be killed' ' test_path_is_missing .git/index-helper.pipe ' +test_expect_success 'index-helper will not start if already running' ' + test_when_finished "git index-helper --kill" && + git index-helper --detach && + test -p .git/index-helper.pipe && + test_must_fail git index-helper 2>err && + test -p .git/index-helper.pipe && + grep "Already running" err +' + test_done -- 2.4.2.767.g62658d5-twtrsrc