Subject: [PATCH 5/5] index-helper: add --detach

From: Nguyễn Thái Ngọc Duy <[email-masked]>
Date: Tue, 10 Jun 2014 20:24:25 +0700

Signed-off-by: Nguyễn Thái Ngọc Duy <[email-masked]>
---
 Documentation/git-index-helper.txt | 4 +++-
 index-helper.c                     | 6 +++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-index-helper.txt b/Documentation/git-index-helper.txt
index afeb334..303cda0 100644
--- a/Documentation/git-index-helper.txt
+++ b/Documentation/git-index-helper.txt
@@ -8,7 +8,7 @@ git-index-helper - A simple cache server for speeding up index file access
 SYNOPSIS
 --------
 [verse]
-'git index-helper
+'git index-helper [--detach]
 
 DESCRIPTION
 -----------
@@ -18,6 +18,8 @@ shared memory support (e.g. Linux or Windows)
 
 OPTIONS
 -------
+--detach::
+	Detach from the shell.
 
 GIT
 ---
diff --git a/index-helper.c b/index-helper.c
index f92326a..9420591 100644
--- a/index-helper.c
+++ b/index-helper.c
@@ -159,8 +159,9 @@ int main(int argc, char **argv)
 	static struct lock_file lock;
 	struct strbuf sb = STRBUF_INIT;
 	const char *prefix;
-	int fd;
+	int fd, detach = 0;
 	struct option options[] = {
+		OPT_BOOL(0, "detach", &detach, "detach the process"),
 		OPT_END()
 	};
 
@@ -188,6 +189,9 @@ int main(int argc, char **argv)
 	sigchain_push(SIGQUIT, cleanup_on_signal);
 	sigchain_push(SIGPIPE, cleanup_on_signal);
 
+	if (detach && daemonize(&daemonized))
+		die_errno("unable to detach");
+
 	loop(sb.buf, 600);
 	strbuf_release(&sb);
 	return 0;
-- 
1.9.1.346.ga2b5940