diff options
author | Junio C Hamano <gitster@pobox.com> | 2014-03-05 15:06:38 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-03-05 15:06:39 -0800 |
commit | 4c4ac4db2c933fbae1c6e6bcf90d9bee5f823fc7 (patch) | |
tree | b5dd07dcd50a387d8d3c0c8b8305a0f6d3e1f1e7 /setup.c | |
parent | Merge branch 'ks/combine-diff' (diff) | |
parent | gc: config option for running --auto in background (diff) | |
download | tgif-4c4ac4db2c933fbae1c6e6bcf90d9bee5f823fc7.tar.xz |
Merge branch 'nd/daemonize-gc'
Allow running "gc --auto" in the background.
* nd/daemonize-gc:
gc: config option for running --auto in background
daemon: move daemonize() to libgit.a
Diffstat (limited to 'setup.c')
-rw-r--r-- | setup.c | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -841,3 +841,27 @@ void sanitize_stdfds(void) if (fd > 2) close(fd); } + +int daemonize(void) +{ +#ifdef NO_POSIX_GOODIES + errno = ENOSYS; + return -1; +#else + switch (fork()) { + case 0: + break; + case -1: + die_errno("fork failed"); + default: + exit(0); + } + if (setsid() == -1) + die_errno("setsid failed"); + close(0); + close(1); + close(2); + sanitize_stdfds(); + return 0; +#endif +} |