@matheusbsbs / matheus-bagliano / commits / 45ed5d7f4c
Fork 0

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>

Matthias Lederhofer committed Jul 13, 2006 at 12:18 UTC 45ed5d7f4cf641d1f64a83613f5a29b31268f8e8
1 file changed +17
daemon.c
+17
@@ -674,6 +674,15 @@ static void sanitize_stdfds(void)
674 close(fd);
675 }
676
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 +
686 static int serve(int port)
687 {
688 int socknum, *socklist;
@@ -689,6 +698,7 @@ int main(int argc, char **argv)
698 {
699 int port = DEFAULT_GIT_PORT;
700 int inetd_mode = 0;
701 + const char *pid_file = NULL;
702 int i;
703
704 /* Without this we cannot rely on waitpid() to tell
@@ -753,6 +763,10 @@ int main(int argc, char **argv)
763 user_path = arg + 12;
764 continue;
765 }
766 + if (!strncmp(arg, "--pid-file=", 11)) {
767 + pid_file = arg + 11;
768 + continue;
769 + }
770 if (!strcmp(arg, "--")) {
771 ok_paths = &argv[i+1];
772 break;
@@ -787,5 +801,8 @@ int main(int argc, char **argv)
801
802 sanitize_stdfds();
803
804 + if (pid_file)
805 + store_pid(pid_file);
806 +
807 return serve(port);
808 }