Unified · Split
| @@ -74,6 +74,10 @@ static char *t2s[] = { · 73 unmodified lines | |||
| 74 | [Twstat-Tversion] = "Twstat", | 74 | [Twstat-Tversion] = "Twstat", |
| 75 | }; | 75 | }; |
| 76 | 76 | ||
| 77 | static char *modes[] = { | ||
| 78 | "read", "write", "rdwr", "exec", | ||
| 79 | }; | ||
| 80 | |||
| 77 | static char *Enoauth = "authentication not required"; | 81 | static char *Enoauth = "authentication not required"; |
| 78 | static char *Eunknownfid = "unknown fid"; | 82 | static char *Eunknownfid = "unknown fid"; |
| 79 | static char *Enowstat = "wstat prohibited"; | 83 | static char *Enowstat = "wstat prohibited"; |
| @@ -136,8 +140,15 @@ canrw(int rdonly, int block) · 56 unmodified lines | |||
| 136 | FD_SET(out, &e); | 140 | FD_SET(out, &e); |
| 137 | memset(&t, 0, sizeof(t)); | 141 | memset(&t, 0, sizeof(t)); |
| 138 | t.tv_usec = 1000; | 142 | t.tv_usec = 1000; |
| 139 | if ((n = select(max(in, out) + 1, &r, &w, &e, block ? NULL : &t)) < 0 || FD_ISSET(in, &e) || FD_ISSET(out, &e)) | 143 | for (;;) { |
| 140 | return -1; | 144 | errno = 0; |
| 145 | if ((n = select(max(in, out) + 1, &r, &w, &e, block ? NULL : &t)) < 0 || FD_ISSET(in, &e) || FD_ISSET(out, &e)) { | ||
| 146 | if (errno == EINTR) | ||
| 147 | continue; | ||
| 148 | return -1; | ||
| 149 | } | ||
| 150 | break; | ||
| 151 | } | ||
| 141 | 152 | ||
| 142 | fl = 0; | 153 | fl = 0; |
| 143 | if (FD_ISSET(in, &r)) | 154 | if (FD_ISSET(in, &r)) |
| @@ -156,11 +167,15 @@ wrsend(void) · 12 unmodified lines | |||
| 156 | 167 | ||
| 157 | if (wrend == 0) | 168 | if (wrend == 0) |
| 158 | return 0; | 169 | return 0; |
| 159 | for (n = 0; n < wrend && (w = write(out, wrbuf+n, wrend-n)) > 0; n += w); | 170 | for (n = 0; n < wrend; n += w) { |
| 160 | if (w <= 0) { | 171 | errno = 0; |
| 161 | if (errno != EPIPE) /* remote end closed */ | 172 | if ((w = write(out, wrbuf+n, wrend-n)) <= 0) { |
| 162 | perror("write"); | 173 | if (errno == EINTR) |
| 163 | return -1; | 174 | continue; |
| 175 | if (errno != EPIPE) /* remote end closed */ | ||
| 176 | perror("write"); | ||
| 177 | return -1; | ||
| 178 | } | ||
| 164 | } | 179 | } |
| 165 | if (debug >= 2) | 180 | if (debug >= 2) |
| 166 | trace("<- %d bytes, %d left\n", wrend, wroff-wrend); | 181 | trace("<- %d bytes, %d left\n", wrend, wroff-wrend); |
| @@ -542,13 +557,17 @@ ctxread(C9ctx *c, uint32_t size, int *err) · 375 unmodified lines | |||
| 542 | used(c); | 557 | used(c); |
| 543 | r = 0; | 558 | r = 0; |
| 544 | *err = 0; | 559 | *err = 0; |
| 545 | for (n = 0; n < size && (r = read(in, rdbuf, size)) > 0; n += r); | 560 | for (n = 0; n < size; n += r) { |
| 546 | if (r <= 0) { | 561 | errno = 0; |
| 547 | if (r == 0) | 562 | if ((r = read(in, rdbuf, size)) <= 0) { |
| 548 | eof = 1; | 563 | if (r == EINTR) |
| 549 | else | 564 | continue; |
| 550 | *err = 1; | 565 | if (r == 0) |
| 551 | return NULL; | 566 | eof = 1; |
| 567 | else | ||
| 568 | *err = 1; | ||
| 569 | return NULL; | ||
| 570 | } | ||
| 552 | } | 571 | } |
| 553 | 572 | ||
| 554 | return rdbuf; | 573 | return rdbuf; |
| @@ -800,6 +819,37 @@ ctxt(C9ctx *c, C9t *t) · 245 unmodified lines | |||
| 800 | } | 819 | } |
| 801 | } | 820 | } |
| 802 | 821 | ||
| 822 | static void | ||
| 823 | sigdebug(int s) | ||
| 824 | { | ||
| 825 | Fid *f; | ||
| 826 | int i, n; | ||
| 827 | |||
| 828 | used(s); | ||
| 829 | n = 0; | ||
| 830 | for (i = 0; i < numfids; i++) { | ||
| 831 | f = fids[i]; | ||
| 832 | if (f == NULL) | ||
| 833 | continue; | ||
| 834 | |||
| 835 | fprintf(stderr, "fid %u ", f->fid); | ||
| 836 | |||
| 837 | if (f->dir != NULL) | ||
| 838 | fprintf(stderr, "open mode=dir "); | ||
| 839 | else if (f->fd >= 0) | ||
| 840 | fprintf(stderr, "open mode=%s%s%s ", modes[(f->mode & 0xf)], (f->mode & C9trunc) ? ",trunc" : "", (f->mode & C9rclose) ? ",rclose" : ""); | ||
| 841 | |||
| 842 | fprintf(stderr, "qid=[path=%"PRIu64" type=0x%02x version=%"PRIu32"] iounit=%d ", f->qid.path, f->qid.type, f->qid.version, f->iounit); | ||
| 843 | fprintf(stderr, " %s %s\n", f->path, f->name); | ||
| 844 | n++; | ||
| 845 | } | ||
| 846 | |||
| 847 | fprintf(stderr, "fids\t%d\n", n); | ||
| 848 | fprintf(stderr, "tags\t%d\n", numtags); | ||
| 849 | fprintf(stderr, "uids\t%d\n", numuids); | ||
| 850 | fprintf(stderr, "gids\t%d\n", numgids); | ||
| 851 | } | ||
| 852 | |||
| 803 | int | 853 | int |
| 804 | main(int argc, char **argv) | 854 | main(int argc, char **argv) |
| 805 | { | 855 | { |
| @@ -807,6 +857,7 @@ main(int argc, char **argv) · 1 unmodified line | |||
| 807 | char *err; | 857 | char *err; |
| 808 | Fid *f; | 858 | Fid *f; |
| 809 | struct parg_state ps; | 859 | struct parg_state ps; |
| 860 | struct sigaction sa; | ||
| 810 | int can, i, c, rdonly, block; | 861 | int can, i, c, rdonly, block; |
| 811 | 862 | ||
| 812 | parg_init(&ps); | 863 | parg_init(&ps); |
| @@ -876,7 +927,16 @@ main(int argc, char **argv) · 63 unmodified lines | |||
| 876 | wrbuf = calloc(1, wrbufsz); | 927 | wrbuf = calloc(1, wrbufsz); |
| 877 | wroff = wrend = 0; | 928 | wroff = wrend = 0; |
| 878 | 929 | ||
| 879 | signal(SIGPIPE, SIG_IGN); | 930 | memset(&sa, 0, sizeof(sa)); |
| 931 | sa.sa_handler = SIG_IGN; | ||
| 932 | sa.sa_flags = SA_RESTART; | ||
| 933 | sigaction(SIGPIPE, &sa, NULL); | ||
| 934 | |||
| 935 | memset(&sa, 0, sizeof(sa)); | ||
| 936 | sa.sa_handler = sigdebug; | ||
| 937 | sa.sa_flags = SA_RESTART; | ||
| 938 | sigfillset(&sa.sa_mask); | ||
| 939 | sigaction(SIGUSR1, &sa, NULL); | ||
| 880 | 940 | ||
| 881 | err = NULL; | 941 | err = NULL; |
| 882 | rdonly = block = 1; /* at first we wait until the client sends in data */ | 942 | rdonly = block = 1; /* at first we wait until the client sends in data */ |