git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v3 7/9] daemonize(): set a flag before exiting the main process
Date: Mon, 28 Jul 2014 19:03:13 +0700	[thread overview]
Message-ID: <1406548995-28549-8-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1406548995-28549-1-git-send-email-pclouds@gmail.com>

This allows signal handlers and atexit functions to realize this
situation and not clean up.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/gc.c | 2 +-
 cache.h      | 2 +-
 daemon.c     | 2 +-
 setup.c      | 4 +++-
 4 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/builtin/gc.c b/builtin/gc.c
index 8d219d8..f120b4f 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -341,7 +341,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
 			 * failure to daemonize is ok, we'll continue
 			 * in foreground
 			 */
-			daemonize();
+			daemonize(NULL);
 		}
 	} else
 		add_repack_all_option();
diff --git a/cache.h b/cache.h
index 0f515e5..f568c8a 100644
--- a/cache.h
+++ b/cache.h
@@ -467,7 +467,7 @@ extern int set_git_dir_init(const char *git_dir, const char *real_git_dir, int);
 extern int init_db(const char *template_dir, unsigned int flags);
 
 extern void sanitize_stdfds(void);
-extern int daemonize(void);
+extern int daemonize(int *);
 
 #define alloc_nr(x) (((x)+16)*3/2)
 
diff --git a/daemon.c b/daemon.c
index e6b51ed..cfdf0f6 100644
--- a/daemon.c
+++ b/daemon.c
@@ -1306,7 +1306,7 @@ int main(int argc, char **argv)
 		return execute();
 
 	if (detach) {
-		if (daemonize())
+		if (daemonize(NULL))
 			die("--detach not supported on this platform");
 	} else
 		sanitize_stdfds();
diff --git a/setup.c b/setup.c
index 0a22f8b..b509395 100644
--- a/setup.c
+++ b/setup.c
@@ -842,7 +842,7 @@ void sanitize_stdfds(void)
 		close(fd);
 }
 
-int daemonize(void)
+int daemonize(int *daemonized)
 {
 #ifdef NO_POSIX_GOODIES
 	errno = ENOSYS;
@@ -854,6 +854,8 @@ int daemonize(void)
 		case -1:
 			die_errno("fork failed");
 		default:
+			if (daemonized)
+				*daemonized = 1;
 			exit(0);
 	}
 	if (setsid() == -1)
-- 
2.1.0.rc0.66.gb9187ad

  parent reply	other threads:[~2014-07-28 12:04 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-28 12:03 [PATCH v3 0/9] Speed up cache loading time Nguyễn Thái Ngọc Duy
2014-07-28 12:03 ` [PATCH v3 1/9] trace.c: add GIT_TRACE_PACK_STATS for pack usage statistics Nguyễn Thái Ngọc Duy
2014-07-28 12:03 ` [PATCH v3 2/9] read-cache.c: fix constness of verify_hdr() Nguyễn Thái Ngọc Duy
2014-07-28 12:03 ` [PATCH v3 3/9] read-cache: allow to keep mmap'd memory after reading Nguyễn Thái Ngọc Duy
2014-07-28 12:03 ` [PATCH v3 4/9] index-helper: new daemon for caching index and related stuff Nguyễn Thái Ngọc Duy
2014-07-30  8:08   ` Eric Sunshine
2014-07-30 10:39     ` Duy Nguyen
2014-07-31  2:41   ` David Turner
2014-07-28 12:03 ` [PATCH v3 5/9] trace.c: add GIT_TRACE_INDEX_STATS for index statistics Nguyễn Thái Ngọc Duy
2014-07-28 12:03 ` [PATCH v3 6/9] index-helper: add --strict Nguyễn Thái Ngọc Duy
2014-07-28 12:03 ` Nguyễn Thái Ngọc Duy [this message]
2014-07-28 12:03 ` [PATCH v3 8/9] index-helper: add --detach Nguyễn Thái Ngọc Duy
2014-07-28 12:03 ` [PATCH v3 9/9] index-helper: add Windows support Nguyễn Thái Ngọc Duy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1406548995-28549-8-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).