Skip to content

Commit 45ed5d7

Browse files
matledJunio C Hamano
authored andcommitted
daemon: new option --pid-file=<path> to store the pid
Signed-off-by: Matthias Lederhofer <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5f490ce commit 45ed5d7

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

daemon.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,15 @@ static void sanitize_stdfds(void)
674674
close(fd);
675675
}
676676

677+
static void store_pid(const char *path)
678+
{
679+
FILE *f = fopen(path, "w");
680+
if (!f)
681+
die("cannot open pid file %s: %s", path, strerror(errno));
682+
fprintf(f, "%d\n", getpid());
683+
fclose(f);
684+
}
685+
677686
static int serve(int port)
678687
{
679688
int socknum, *socklist;
@@ -689,6 +698,7 @@ int main(int argc, char **argv)
689698
{
690699
int port = DEFAULT_GIT_PORT;
691700
int inetd_mode = 0;
701+
const char *pid_file = NULL;
692702
int i;
693703

694704
/* Without this we cannot rely on waitpid() to tell
@@ -753,6 +763,10 @@ int main(int argc, char **argv)
753763
user_path = arg + 12;
754764
continue;
755765
}
766+
if (!strncmp(arg, "--pid-file=", 11)) {
767+
pid_file = arg + 11;
768+
continue;
769+
}
756770
if (!strcmp(arg, "--")) {
757771
ok_paths = &argv[i+1];
758772
break;
@@ -787,5 +801,8 @@ int main(int argc, char **argv)
787801

788802
sanitize_stdfds();
789803

804+
if (pid_file)
805+
store_pid(pid_file);
806+
790807
return serve(port);
791808
}

0 commit comments

Comments
 (0)