diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2016-07-03 03:57:58 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-07-06 11:22:40 -0700 |
commit | 1a63c9ca18689c047a11036ae0faa42d69e45668 (patch) | |
tree | a756bd28f9f506dba16526053ff5172e6aec4a3a | |
parent | 32711ca2cd7ae5d6d165d3b77cfe1094178adc20 (diff) | |
download | git-1a63c9ca18689c047a11036ae0faa42d69e45668.tar.gz |
daemonize(): set a flag before exiting the main process
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>
Signed-off-by: David Turner <dturner@twopensource.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | builtin/gc.c | 2 | ||||
-rw-r--r-- | cache.h | 2 | ||||
-rw-r--r-- | daemon.c | 2 | ||||
-rw-r--r-- | setup.c | 4 |
4 files changed, 6 insertions, 4 deletions
diff --git a/builtin/gc.c b/builtin/gc.c index c583aad6ec..37180deca0 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -385,7 +385,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix) * failure to daemonize is ok, we'll continue * in foreground */ - daemonized = !daemonize(); + daemonized = !daemonize(NULL); } } else add_repack_all_option(); @@ -539,7 +539,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) @@ -1365,7 +1365,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(); @@ -1017,7 +1017,7 @@ void sanitize_stdfds(void) close(fd); } -int daemonize(void) +int daemonize(int *daemonized) { #ifdef NO_POSIX_GOODIES errno = ENOSYS; @@ -1029,6 +1029,8 @@ int daemonize(void) case -1: die_errno("fork failed"); default: + if (daemonized) + *daemonized = 1; exit(0); } if (setsid() == -1) |