|
|
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: char *std = "-"; ! 13: char buf[512]; ! 14: FILE *CAT; ! 15: extern char *dkerror; ! 16: ! 17: #define MAXCHARS 8192 ! 18: char args[MAXCHARS]; ! 19: ! 20: char *bldargs(argv) ! 21: register char *argv[]; ! 22: { ! 23: register char *s=args, *t; ! 24: while(t= *argv++){ /* assignment = */ ! 25: while(*s = *t++) ! 26: if(s++ >= &args[MAXCHARS-1]){ ! 27: fprintf(stderr, "rx: arg list too long\n"); ! 28: exit(1); ! 29: } ! 30: *s++=' '; ! 31: } ! 32: s[-1]='\0'; ! 33: return(args); ! 34: } ! 35: ! 36: char * ! 37: basename(s) ! 38: register char *s; ! 39: { ! 40: register char *t; ! 41: extern char *rindex(); ! 42: t=rindex(s, '/'); ! 43: return(t? t+1 : s); ! 44: } ! 45: ! 46: main(argc, argv) ! 47: char **argv; ! 48: { ! 49: int filc; ! 50: int cat; ! 51: char **filv; ! 52: char *host; ! 53: ! 54: filv = &std; ! 55: filc = 1; ! 56: ! 57: cat = 1; ! 58: CAT = fdopen(cat, "w"); ! 59: host=basename(argv[0]); ! 60: if(strcmp(host, "rx")==0 || strcmp(host, "rexec")==0){ ! 61: host=argv[1]; ! 62: argv++; ! 63: } ! 64: if(host==0){ ! 65: fprintf(stderr, "usage: rx host command\n"); ! 66: exit(1); ! 67: } ! 68: if(argv[1]==0){ ! 69: execl("/usr/bin/dcon", "dcon", host, 0); ! 70: execl("/bin/dcon", "dcon", host, 0); ! 71: fprintf(stderr, "rx: cannot exec dcon\n"); ! 72: exit(1); ! 73: } ! 74: rem = tdkexec(host, bldargs(&argv[1])); ! 75: if (rem<0) { ! 76: fprintf(stderr, "rx: call to %s failed: %s\n", host, dkerror); ! 77: exit(1); ! 78: } ! 79: t = fork(); ! 80: if (t < 0) { ! 81: fprintf(stderr, "rx: can't fork\n"); ! 82: exit(1); ! 83: } ! 84: ! 85: if (t == 0) { ! 86: to_proc(filc, filv); ! 87: } else { ! 88: argv[0][0] = 'F'; ! 89: from_proc(); ! 90: } ! 91: exit(0) ; ! 92: ! 93: } ! 94: ! 95: to_proc(filc, filv) ! 96: char **filv; ! 97: { ! 98: register cc; ! 99: ! 100: while (1) { ! 101: cc = read(0, buf, sizeof buf); ! 102: if (cc <= 0) ! 103: break; ! 104: write(rem, buf, cc); ! 105: } ! 106: ! 107: /* ! 108: * flush buffer to proc, ! 109: * then send logical EOF to ! 110: * make it go away. ! 111: */ ! 112: done: ! 113: write(rem, "", 0) ; ! 114: } ! 115: ! 116: from_proc() ! 117: { ! 118: FILE *REM; ! 119: register cc; ! 120: static char buf[BUFSIZ]; ! 121: ! 122: while ((cc = read(rem, buf, sizeof buf)) > 0) { ! 123: write(1, buf, cc); ! 124: } ! 125: kill(t, 2); ! 126: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.