Skip to content

Commit

Permalink
daemon: new option --pid-file=<path> to store the pid
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Lederhofer <matled@gmx.net>
Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Matthias Lederhofer authored and Junio C Hamano committed Jul 14, 2006
1 parent 5f490ce commit 45ed5d7
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -787,5 +801,8 @@ int main(int argc, char **argv)

sanitize_stdfds();

if (pid_file)
store_pid(pid_file);

return serve(port);
}

0 comments on commit 45ed5d7

Please sign in to comment.