changeset 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 e1c8c5bcb233
children ad503b495e3e
files rvinterf/lowlevel/rvifmain.c
diffstat 1 files changed, 16 insertions(+), 0 deletions(-) [+]
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);
 		}
 	}