comparison rvinterf/etmsync/launchrvif.c @ 275:cedf09b6b5ac

started laying the foundation for fc-fsio host utility
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 23 Feb 2014 20:27:15 +0000
parents
children 909f00c15f27
comparison
equal deleted inserted replaced
274:e3f17ff16915 275:cedf09b6b5ac
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
12 static char rvinterf_pathname[] = "/usr/local/bin/rvinterf";
13
14 extern int sock;
15
16 char *rvinterf_ttyport, *rvinterf_Bopt, *rvinterf_lopt, *rvinterf_wopt;
17
18 launch_rvinterf()
19 {
20 int sp[2], rc;
21 char *rvif_argv[11], Sarg[16], **ap;
22
23 rc = socketpair(AF_UNIX, SOCK_STREAM, 0, sp);
24 if (rc < 0) {
25 perror("socketpair");
26 exit(1);
27 }
28 sock = sp[0];
29 sprintf(Sarg, "-S%d", sp[1]);
30 ap = rvif_argv;
31 *ap++ = "rvinterf";
32 *ap++ = Sarg;
33 *ap++ = "-n";
34 if (rvinterf_Bopt) {
35 *ap++ = "-B";
36 *ap++ = rvinterf_Bopt;
37 }
38 if (rvinterf_lopt) {
39 *ap++ = "-l";
40 *ap++ = rvinterf_lopt;
41 }
42 if (rvinterf_wopt) {
43 *ap++ = "-w";
44 *ap++ = rvinterf_wopt;
45 }
46 *ap++ = rvinterf_ttyport;
47 *ap = 0;
48 rc = vfork();
49 if (rc < 0) {
50 perror("vfork for launching rvinterf");
51 exit(1);
52 }
53 if (!rc) {
54 /* we are in the child - do the exec */
55 close(sp[0]);
56 execv(rvinterf_pathname, rvif_argv);
57 perror(rvinterf_pathname);
58 _exit(1);
59 }
60 close(sp[1]);
61 return 0;
62 }