diff options
author | Matthias Lederhofer <matled@gmx.net> | 2006-07-13 12:18:08 +0200 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2006-07-13 21:50:41 -0700 |
commit | 45ed5d7f4cf641d1f64a83613f5a29b31268f8e8 (patch) | |
tree | b63c5a2908de5243f04188bf073535354186924a /daemon.c | |
parent | 5f490ce03c16411b737374c12ed377c74af1ca9d (diff) | |
download | git-45ed5d7f4cf641d1f64a83613f5a29b31268f8e8.tar.gz |
daemon: new option --pid-file=<path> to store the pid
Signed-off-by: Matthias Lederhofer <matled@gmx.net>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'daemon.c')
-rw-r--r-- | daemon.c | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -674,6 +674,15 @@ static void sanitize_stdfds(void) close(fd); } +static void store_pid(const char *path) +{ + FILE *f = fopen(path, "w"); + if (!f) + die("cannot open pid file %s: %s", path, strerror(errno)); + fprintf(f, "%d\n", getpid()); + fclose(f); +} + static int serve(int port) { int socknum, *socklist; @@ -689,6 +698,7 @@ int main(int argc, char **argv) { int port = DEFAULT_GIT_PORT; int inetd_mode = 0; + const char *pid_file = NULL; int i; /* Without this we cannot rely on waitpid() to tell @@ -753,6 +763,10 @@ int main(int argc, char **argv) user_path = arg + 12; continue; } + if (!strncmp(arg, "--pid-file=", 11)) { + pid_file = arg + 11; + continue; + } if (!strcmp(arg, "--")) { ok_paths = &argv[i+1]; break; @@ -787,5 +801,8 @@ int main(int argc, char **argv) sanitize_stdfds(); + if (pid_file) + store_pid(pid_file); + return serve(port); } |