Annotation of researchv9/ipc/src/bin/rx.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.