diff rvinterf/lowlevel/rvifmain.c @ 761:32031c18cc25

rvinterf -b: write pid to /tmp/rvinterf.pid
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 02 Dec 2020 19:49:23 +0000
parents d43dc6dfb44c
children a1065c17429c
line wrap: on
line diff
--- a/rvinterf/lowlevel/rvifmain.c	Sat Nov 28 00:32:41 2020 +0000
+++ b/rvinterf/lowlevel/rvifmain.c	Wed Dec 02 19:49:23 2020 +0000
@@ -40,6 +40,21 @@
 	"Received keepalive query, responding with keepalive answer";
 static u_char keepalive_answer[2] = {RVT_KEEPALIVE_HEADER, 'A'};
 
+write_pid_file(pid)
+{
+	static char pid_filename[] = "/tmp/rvinterf.pid";
+	FILE *of;
+
+	of = fopen(pid_filename, "w");
+	if (!of) {
+		fprintf(stderr, "warning: unable to write %s\n", pid_filename);
+		return(-1);
+	}
+	fprintf(of, "%d\n", pid);
+	fclose(of);
+	return(0);
+}
+
 main(argc, argv)
 	char **argv;
 {
@@ -121,6 +136,7 @@
 		}
 		if (c) {
 			printf("rvinterf forked into background (pid %d)\n", c);
+			write_pid_file(c);
 			exit(0);
 		}
 	}