Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2014-03-06 03:06:38 +0400
committerJunio C Hamano <gitster@pobox.com>2014-03-06 03:06:39 +0400
commit4c4ac4db2c933fbae1c6e6bcf90d9bee5f823fc7 (patch)
treeb5dd07dcd50a387d8d3c0c8b8305a0f6d3e1f1e7 /setup.c
parent6376463c37e0371a411013b90b2e8fc0f7d27dfa (diff)
parent9f673f9477c63433aa0774c11b9e42979721f4d6 (diff)
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
+}