comparison rvinterf/etmsync/launchrvif.c @ 0:e7502631a0f9

initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 Jun 2016 00:13:35 +0000
parents
children 3fb0c7ad27f3
comparison
equal deleted inserted replaced
-1:000000000000 0:e7502631a0f9
1 /*
2 * This module implements the optional "behind the scenes" invokation
3 * of rvinterf from fc-fsio etc.
4 */
5
6 #include <sys/types.h>
7 #include <sys/socket.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include "exitcodes.h"
12
13 static char rvinterf_pathname[] = "/usr/local/bin/rvinterf";
14
15 extern int sock;
16
17 char *rvinterf_ttyport, *rvinterf_Bopt, *rvinterf_lopt, *rvinterf_wopt;
18
19 launch_rvinterf()
20 {
21 int sp[2], rc;
22 char *rvif_argv[11], Sarg[16], **ap;
23
24 rc = socketpair(AF_UNIX, SOCK_STREAM, 0, sp);
25 if (rc < 0) {
26 perror("socketpair");
27 exit(ERROR_UNIX);
28 }
29 sock = sp[0];
30 sprintf(Sarg, "-S%d", sp[1]);
31 ap = rvif_argv;
32 *ap++ = "rvinterf";
33 *ap++ = Sarg;
34 *ap++ = "-n";
35 if (rvinterf_Bopt) {
36 *ap++ = "-B";
37 *ap++ = rvinterf_Bopt;
38 }
39 if (rvinterf_lopt) {
40 *ap++ = "-l";
41 *ap++ = rvinterf_lopt;
42 }
43 if (rvinterf_wopt) {
44 *ap++ = "-w";
45 *ap++ = rvinterf_wopt;
46 }
47 *ap++ = rvinterf_ttyport;
48 *ap = 0;
49 rc = vfork();
50 if (rc < 0) {
51 perror("vfork for launching rvinterf");
52 exit(ERROR_UNIX);
53 }
54 if (!rc) {
55 /* we are in the child - do the exec */
56 close(sp[0]);
57 execv(rvinterf_pathname, rvif_argv);
58 perror(rvinterf_pathname);
59 _exit(1);
60 }
61 close(sp[1]);
62 return 0;
63 }