|
|
1.1 root 1: #include <stdio.h>
2: #include <dk.h>
3: #include <string.h>
4: #include <sys/types.h>
5:
6: /*
7: * program to run a command
8: * on another cpu on Datakit
9: */
10:
11: #define MAXCHARS 8192
12: char args[MAXCHARS];
13: char buf[4096];
14: extern char *dkerror;
15: char *bldargs(), *malloc();
16: extern errno;
17: fd_set rbits, bits;
18:
19: #define MAXEOF 10
20:
21: main(argc, argv)
22: char **argv;
23: {
24: char *host;
25: char *service = "exec";
26: char *cp;
27: register int rem, n;
28: register int neof;
29:
30: host = argv[0];
31: if (strrchr(host, '/'))
32: host = strrchr(host, '/')+1;
33: if(strcmp(host, "rx")==0 || strcmp(host, "rexec")==0){
34: host = argv[1];
35: argv++;
36: argc--;
37: }
38: if (cp = strchr(host, '.')) {
39: service = cp+1;
40: cp = malloc(strlen(host)+1);
41: strcpy(cp, host);
42: host = cp;
43: *strchr(host, '.') = '\0';
44: }
45: else if(argc<=1){
46: execl("/usr/bin/dcon", "dcon", host, 0);
47: execl("/bin/dcon", "dcon", host, 0);
48: fprintf(stderr, "rx: cannot exec dcon\n");
49: exit(1);
50: }
51: rem = _tdkexec(host, bldargs(argc-1, &argv[1]), service);
52: if (rem<0) {
53: fprintf(stderr, "rx: call to %s failed: %s\n", host, dkerror);
54: exit(1);
55: }
56: FD_SET(0, bits);
57: FD_SET(rem, bits);
58: neof = 0;
59: for (;;) {
60: rbits = bits;
61: if (select(rem+1, &rbits, (fd_set *)NULL, 20000) < 0)
62: exit(1);
63: if (FD_ISSET(0, rbits)) {
64: n = read(0, buf, sizeof(buf));
65: if (n > 0) {
66: if (write(rem, buf, n) != n)
67: exit(1);
68: neof = 0;
69: }
70: else {
71: if (++neof >= MAXEOF)
72: FD_CLR(0, bits);
73: write(rem, buf, 0);
74: }
75: }
76: if (FD_ISSET(rem, rbits)) {
77: n = read(rem, buf, sizeof(buf));
78: if (n <= 0)
79: exit(0);
80: if (write(1, buf, n) != n)
81: exit(1);
82: }
83: }
84: }
85:
86: char *
87: bldargs(argc, argv)
88: register char **argv;
89: {
90: register char *s = args, *t;
91:
92: while(argc--) {
93: *s++ = ' ';
94: t = *argv++;
95: while(*s = *t++) {
96: if(s++ >= &args[MAXCHARS-2]){
97: fprintf(stderr, "rx: arg list too long\n");
98: exit(1);
99: }
100: }
101: }
102: *s = '\0';
103: return(args+1);
104: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.