diff rvinterf/libasync/launchrvif.c @ 335:40b8557b9d04

rvinterf suite: libasync factored out of fc-tmsh
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Tue, 22 Apr 2014 06:51:09 +0000
parents rvinterf/tmsh/launchrvif.c@c146f38d2b5f
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/libasync/launchrvif.c	Tue Apr 22 06:51:09 2014 +0000
@@ -0,0 +1,63 @@
+/*
+ * This module implements the optional "behind the scenes" invokation
+ * of rvinterf from fc-tmsh.
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+static char rvinterf_pathname[] = "/usr/local/bin/rvinterf";
+
+extern int sock;
+
+char *rvinterf_Bopt, *rvinterf_lopt, *rvinterf_wopt;
+
+launch_rvinterf(ttyport)
+	char *ttyport;
+{
+	int sp[2], rc;
+	char *rvif_argv[11], Sarg[16], **ap;
+
+	rc = socketpair(AF_UNIX, SOCK_STREAM, 0, sp);
+	if (rc < 0) {
+		perror("socketpair");
+		exit(1);
+	}
+	sock = sp[0];
+	sprintf(Sarg, "-S%d", sp[1]);
+	ap = rvif_argv;
+	*ap++ = "rvinterf";
+	*ap++ = Sarg;
+	*ap++ = "-n";
+	if (rvinterf_Bopt) {
+		*ap++ = "-B";
+		*ap++ = rvinterf_Bopt;
+	}
+	if (rvinterf_lopt) {
+		*ap++ = "-l";
+		*ap++ = rvinterf_lopt;
+	}
+	if (rvinterf_wopt) {
+		*ap++ = "-w";
+		*ap++ = rvinterf_wopt;
+	}
+	*ap++ = ttyport;
+	*ap = 0;
+	rc = vfork();
+	if (rc < 0) {
+		perror("vfork for launching rvinterf");
+		exit(1);
+	}
+	if (!rc) {
+		/* we are in the child - do the exec */
+		close(sp[0]);
+		execv(rvinterf_pathname, rvif_argv);
+		perror(rvinterf_pathname);
+		_exit(1);
+	}
+	close(sp[1]);
+	return 0;
+}