git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 8/9] index-helper: add --detach

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Jul 28, 2014, 12:03 UTC
Message-ID
<1406548995-28549-9-git-send-email-pclouds@gmail.com>
In-Reply-To
<1406548995-28549-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Documentation/git-index-helper.txt |  3 +++
 index-helper.c                     | 10 ++++++++--
 2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-index-helper.txt b/Documentation/git-index-helper.txt
index 406856d..d8fbdab 100644
--- a/Documentation/git-index-helper.txt
+++ b/Documentation/git-index-helper.txt
@@ -31,6 +31,9 @@ OPTIONS
 	for reading an index, but because it will happen in the
 	background, it's not noticable. `--strict` is enabled by default.
 
+--detach::
+	Detach from the shell.
+
 NOTES
 -----
 On UNIX-like systems, $GIT_DIR/index-helper.pid contains the process
diff --git a/index-helper.c b/index-helper.c
index c82d307..4262678 100644
--- a/index-helper.c
+++ b/index-helper.c
@@ -13,7 +13,7 @@ struct index_shm {
 
 static struct index_shm shm_index;
 static struct index_shm shm_base_index;
-static int to_verify = 1;
+static int daemonized, to_verify = 1;
 
 static void free_index_shm(struct index_shm *is)
 {
@@ -32,6 +32,8 @@ static void cleanup_shm(void)
 
 static void cleanup(void)
 {
+	if (daemonized)
+		return;
 	unlink(git_path("index-helper.pid"));
 	cleanup_shm();
 }
@@ -164,12 +166,13 @@ int main(int argc, char **argv)
 	static struct lock_file lock;
 	struct strbuf sb = STRBUF_INIT;
 	const char *prefix;
-	int fd, idle_in_minutes = 10;
+	int fd, idle_in_minutes = 10, detach = 0;
 	struct option options[] = {
 		OPT_INTEGER(0, "exit-after", &idle_in_minutes,
 			    N_("exit if not used after some minutes")),
 		OPT_BOOL(0, "strict", &to_verify,
 			 "verify shared memory after creating"),
+		OPT_BOOL(0, "detach", &detach, "detach the process"),
 		OPT_END()
 	};
 
@@ -196,6 +199,9 @@ int main(int argc, char **argv)
 	atexit(cleanup);
 	sigchain_push_common(cleanup_on_signal);
 
+	if (detach && daemonize(&daemonized))
+		die_errno("unable to detach");
+
 	if (!idle_in_minutes)
 		idle_in_minutes = 0xffffffff / 60;
 	loop(sb.buf, idle_in_minutes * 60);
-- 
2.1.0.rc0.66.gb9187ad
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 12 of 13 in “Speed up cache loading time”
  1. 0/9 Speed up cache loading timeNguyễn Thái Ngọc Duy, Jul 28, 2014
  2. 1/9 trace.c: add GIT_TRACE_PACK_STATS for pack usage statisticsNguyễn Thái Ngọc Duy, Jul 28, 2014
  3. 2/9 read-cache.c: fix constness of verify_hdr()Nguyễn Thái Ngọc Duy, Jul 28, 2014
  4. 3/9 read-cache: allow to keep mmap'd memory after readingNguyễn Thái Ngọc Duy, Jul 28, 2014
  5. 4/9 index-helper: new daemon for caching index and related stuffNguyễn Thái Ngọc Duy, Jul 28, 2014
  6. Eric SunshineJul 30, 2014
  7. Duy NguyenJul 30, 2014
  8. David TurnerJul 31, 2014
  9. 5/9 trace.c: add GIT_TRACE_INDEX_STATS for index statisticsNguyễn Thái Ngọc Duy, Jul 28, 2014
  10. 6/9 index-helper: add --strictNguyễn Thái Ngọc Duy, Jul 28, 2014
  11. 7/9 daemonize(): set a flag before exiting the main processNguyễn Thái Ngọc Duy, Jul 28, 2014
  12. 8/9 index-helper: add --detachNguyễn Thái Ngọc Duy, Jul 28, 2014
  13. 9/9 index-helper: add Windows supportNguyễn Thái Ngọc Duy, Jul 28, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.