summaryrefslogtreecommitdiff
path: root/setup.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2014-03-05 15:06:38 -0800
committerLibravatar Junio C Hamano <gitster@pobox.com>2014-03-05 15:06:39 -0800
commit4c4ac4db2c933fbae1c6e6bcf90d9bee5f823fc7 (patch)
treeb5dd07dcd50a387d8d3c0c8b8305a0f6d3e1f1e7 /setup.c
parentMerge branch 'ks/combine-diff' (diff)
parentgc: config option for running --auto in background (diff)
downloadtgif-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.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/setup.c b/setup.c
index cffb6d605e..613e3b3c13 100644
--- a/setup.c
+++ b/setup.c
@@ -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
+}