|
|
1.1 root 1: #include <stdio.h>
2: #include <dk.h>
3:
4: /*
5: * program to run a command
6: * on another cpu on Datakit
7: */
8:
9: int rem; /* remote file descriptor */
10: int psize; /* packet size */
11: int t;
12:
13: char *std = "-";
14:
15: char buf[512];
16: FILE *CAT;
17:
18: #define MAXCHARS 8192
19: char args[MAXCHARS];
20:
21: char *bldargs(argv)
22: register char *argv[];
23: {
24: register char *s=args, *t;
25: while(t= *argv++){ /* assignment = */
26: while(*s = *t++)
27: if(s++ >= &args[MAXCHARS-1]){
28: fprintf(stderr, "rx: arg list too long\n");
29: exit(1);
30: }
31: *s++=' ';
32: }
33: s[-1]='\0';
34: return(args);
35: }
36:
37: char *
38: basename(s)
39: register char *s;
40: {
41: register char *t;
42: extern char *rindex();
43: t=rindex(s, '/');
44: return(t? t+1 : s);
45: }
46:
47: main(argc, argv)
48: char **argv;
49: {
50: int filc;
51: int cat;
52: char **filv;
53: char *host;
54:
55: filv = &std;
56: filc = 1;
57:
58: cat = 1;
59: CAT = fdopen(cat, "w");
60: host=basename(argv[0]);
61: if(strcmp(host, "rxtty")==0 || strcmp(host, "rexec")==0){
62: host=argv[1];
63: argv++;
64: }
65: if(host==0){
66: fprintf(stderr, "usage: rx host command\n");
67: exit(1);
68: }
69: if(argv[1]==0){
70: execl("/usr/bin/dcon", host, "-x", host, 0);
71: execl("/bin/dcon", host, "-x", host, 0);
72: fprintf(stderr, "rx: cannot exec dcon\n");
73: exit(1);
74: }
75: rem = ttyexec(host, bldargs(&argv[1]));
76: if (rem<0) {
77: fprintf(stderr, "rx: call to %s failed\n", host);
78: exit(1);
79: }
80: t = fork();
81: if (t < 0) {
82: fprintf(stderr, "rx: can't fork\n");
83: exit(1);
84: }
85:
86: if (t == 0) {
87: to_proc(filc, filv);
88: } else {
89: argv[0][0] = 'F';
90: from_proc();
91: }
92: exit(0) ;
93:
94: }
95:
96: to_proc(filc, filv)
97: char **filv;
98: {
99: register cc;
100:
101: while (1) {
102: cc = read(0, buf, sizeof buf);
103: if (cc <= 0)
104: break;
105: write(rem, buf, cc);
106: }
107:
108: /*
109: * flush buffer to proc,
110: * then send logical EOF to
111: * make it go away.
112: */
113: done:
114: write(rem, "", 0) ;
115: }
116:
117: from_proc()
118: {
119: FILE *REM;
120: register cc;
121: static char buf[BUFSIZ];
122:
123: while ((cc = read(rem, buf, sizeof buf)) > 0) {
124: write(1, buf, cc);
125: }
126: kill(t, 2);
127: }
128:
129: #include <sys/ioctl.h>
130:
131: tdkexec(hname, cmd)
132: char *hname, *cmd;
133: {
134: return(_tdkexec(hname, cmd, "exec"));
135: }
136:
137: ttyexec(hname, cmd)
138: char *hname, *cmd ;
139: {
140: return (_tdkexec(hname, cmd, "ttyexec")) ;
141: }
142:
143: mesgexec(hname, cmd)
144: char *hname, *cmd;
145: {
146: return(_tdkexec(hname, cmd, "mesgexec"));
147: }
148:
149: _tdkexec(hname, cmd, service)
150: char *hname, *cmd;
151: char * service ;
152: {
153: int rem, v;
154: extern int pk_ld, dkp_ld, tty_ld, dt_ld ;
155: char dialstr[64] ;
156: char cmdname[32] ;
157: register char *cp1, *cp2 ;
158:
159: strcpy(dialstr, hname) ;
160: strcat(dialstr, ".") ;
161: strcat(dialstr, service) ;
162: cp1 = cmdname ; cp2 = cmd ;
163: while (*cp2 && (*cp2 != ' ')) {
164: if (*cp2 == '/')
165: cp1 = cmdname ;
166: else
167: *cp1++ = *cp2 ;
168: cp2++ ;
169: }
170: *cp1 = '\0' ;
171: /****
172: strcat(dialstr, ".") ;
173: strcat(dialstr, cmdname) ;
174: ****/
175: rem = tdkdial(dialstr, 2) ;
176: if (rem < 0) {
177: fprintf(stderr, "can't rexec\n");
178: return(-1);
179: }
180: v = dkproto(rem, dkp_ld);
181: if (v < 0) {
182: printf("can't start protocol\n");
183: close(rem);
184: return(-1);
185: }
186: if (tdklogin(rem) < 0)
187: return -1 ;
188: write(rem, cmd, strlen(cmd));
189: write(rem, "\n", 1) ;
190: return(rem);
191: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.