annotate rvinterf/etm/launchrvif.c @ 197:fa7174faa9aa

fc-tmsh: option to invoke rvinterf "behind the scenes"
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 15 Dec 2013 07:31:52 +0000
parents
children 2847b6cbd915
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
197
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This module implements the optional "behind the scenes" invokation
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * of rvinterf from fc-tmsh.
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 */
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <sys/types.h>
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <sys/socket.h>
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <stdio.h>
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <stdlib.h>
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <unistd.h>
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 static char rvinterf_pathname[] = "/usr/local/bin/rvinterf";
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 extern int sock;
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 char *rvinterf_lopt, *rvinterf_wopt;
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 launch_rvinterf(ttyport)
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 char *ttyport;
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 {
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 int sp[2], rc;
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 char *rvif_argv[9], Sarg[16], **ap;
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 rc = socketpair(AF_UNIX, SOCK_STREAM, 0, sp);
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 if (rc < 0) {
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 perror("socketpair");
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 exit(1);
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 }
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 sock = sp[0];
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 sprintf(Sarg, "-S%d", sp[1]);
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 ap = rvif_argv;
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 *ap++ = "rvinterf";
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 *ap++ = Sarg;
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 *ap++ = "-n";
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 if (rvinterf_lopt) {
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 *ap++ = "-l";
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 *ap++ = rvinterf_lopt;
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 }
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 if (rvinterf_wopt) {
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 *ap++ = "-w";
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 *ap++ = rvinterf_wopt;
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 }
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 *ap++ = ttyport;
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 *ap = 0;
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 rc = vfork();
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 if (rc < 0) {
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 perror("vfork for launching rvinterf");
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 exit(1);
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 }
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 if (!rc) {
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 /* we are in the child - do the exec */
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 close(sp[0]);
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 execv(rvinterf_pathname, rvif_argv);
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 perror(rvinterf_pathname);
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 _exit(1);
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 }
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 close(sp[1]);
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 return 0;
fa7174faa9aa fc-tmsh: option to invoke rvinterf "behind the scenes"
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 }