summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 45ed5d7)
raw | patch | inline | side by side (parent: 45ed5d7)
author | Matthias Lederhofer <matled@gmx.net> | |
Thu, 13 Jul 2006 16:47:13 +0000 (18:47 +0200) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Fri, 14 Jul 2006 04:50:46 +0000 (21:50 -0700) |
Signed-off-by: Matthias Lederhofer <matled@gmx.net>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Junio C Hamano <junkio@cox.net>
daemon.c | patch | blob | history |
diff --git a/daemon.c b/daemon.c
index cdc42668633ec5a7b93544cca3fc92298d8556f4..e4ec676301c965e0b0ec81995f4e1fb77363c373 100644 (file)
--- a/daemon.c
+++ b/daemon.c
close(fd);
}
+static void daemonize(void)
+{
+ switch (fork()) {
+ case 0:
+ break;
+ case -1:
+ die("fork failed: %s", strerror(errno));
+ default:
+ exit(0);
+ }
+ if (setsid() == -1)
+ die("setsid failed: %s", strerror(errno));
+ close(0);
+ close(1);
+ close(2);
+ sanitize_stdfds();
+}
+
static void store_pid(const char *path)
{
FILE *f = fopen(path, "w");
int port = DEFAULT_GIT_PORT;
int inetd_mode = 0;
const char *pid_file = NULL;
+ int detach = 0;
int i;
/* Without this we cannot rely on waitpid() to tell
pid_file = arg + 11;
continue;
}
+ if (!strcmp(arg, "--detach")) {
+ detach = 1;
+ log_syslog = 1;
+ continue;
+ }
if (!strcmp(arg, "--")) {
ok_paths = &argv[i+1];
break;
return execute(peer);
}
- sanitize_stdfds();
+ if (detach)
+ daemonize();
+ else
+ sanitize_stdfds();
if (pid_file)
store_pid(pid_file);