--- multiplexer/en300468ts.c 2010/09/29 21:29:33 1.14 +++ multiplexer/en300468ts.c 2010/09/29 21:30:28 1.15 @@ -1610,7 +1610,6 @@ static void maketab(char typ, long pid, memset(&t->descrnum[0], 0, sizeof(t->descrnum[0])); memset(&t->u, 0, sizeof(t->u)); t->u.a.fd = fd; - t->next = newtab; newtab = t; } } @@ -2171,79 +2170,71 @@ static void argloop(int f0) pst = &st->next; } } - if ((n > 0) && (nst >= 0)) { - pst = &newtab; - do { - st = *pst; - if ((r = pollfd_rev(nst))) { - if (r & (POLLNVAL | POLLERR)) { - fprintf(stderr, "poll error: %x\n", r); - *pst = st->next; - close(st->u.a.fd); - free(st->tab); - free(st); - } else { - i = st->u.a.ibuf; - r = read(st->u.a.fd, &st->u.a.buf[i], sizeof(st->u.a.buf) - i - 1); - if (r <= 0) { - fprintf(stderr, "read error(%d): %d\n", errno, st->u.a.fd); - *pst = st->next; - close(st->u.a.fd); - free(st->tab); - free(st); + if ((n > 0) && (nst >= 0) && (r = pollfd_rev(nst))) { + if (r & (POLLNVAL | POLLERR)) { + fprintf(stderr, "poll error: %x\n", r); + close(newtab->u.a.fd); + free(newtab->tab); + free(newtab); + newtab = NULL; + } else { + i = newtab->u.a.ibuf; + r = read(newtab->u.a.fd, &newtab->u.a.buf[i], sizeof(newtab->u.a.buf) - i - 1); + if (r <= 0) { + fprintf(stderr, "read error(%d): %d\n", errno, newtab->u.a.fd); + close(newtab->u.a.fd); + free(newtab->tab); + free(newtab); + newtab = NULL; + } else { + int j = 0; + i += r; + while ((r = siline(newtab, &newtab->u.a.buf[j], i)) >= 0) { + j += r; + i -= r; + } + switch (r) { + case -ENOBUFS: + close(newtab->u.a.fd); +#ifdef DEBUG + fprintf(stderr, "done, itab=%d\n", newtab->u.a.itab); + for (i = 0; i < newtab->u.a.itab; i++) { + fprintf(stderr, "%lu,", newtab->tab[i]); + } + fprintf(stderr, "\n"); +#endif + i = newtab->pid - TABLE_PID_FIRST; + if ((tabbuf[i] == NULL) + && ((tabbuf[i] = malloc(TABBUF_SIZE)) == NULL)) { + fprintf(stderr, "malloc failed for table buffer pid=%02lx\n", + newtab->pid); + free(newtab->tab); + free(newtab); + newtab = NULL; } else { - int j = 0; - i += r; - while ((r = siline(st, &st->u.a.buf[j], i)) >= 0) { - j += r; - i -= r; - } - switch (r) { - case -ENOBUFS: - *pst = st->next; - close(st->u.a.fd); -#ifdef DEBUG - fprintf(stderr, "done, itab=%d\n", st->u.a.itab); - for (i = 0; i < st->u.a.itab; i++) { - fprintf(stderr, "%lu,", st->tab[i]); - } - fprintf(stderr, "\n"); -#endif - i = st->pid - TABLE_PID_FIRST; - if ((tabbuf[i] == NULL) - && ((tabbuf[i] = malloc(TABBUF_SIZE)) == NULL)) { - fprintf(stderr, "malloc failed for table buffer pid=%02lx\n", - st->pid); - free(st->tab); - free(st); - } - st->next = runtab; - runtab = st; - st->u.s.next = tv; - break; - case -EAGAIN: - if (i > 0) { - memmove(&st->u.a.buf[0], &st->u.a.buf[j], i); - } - st->u.a.ibuf = i; - pst = &st->next; - break; - default: - fprintf(stderr, "eval error: %d\n", r); - *pst = st->next; - close(st->u.a.fd); - free(st->tab); - free(st); - break; - } + newtab->u.s.next = tv; + newtab->next = runtab; + runtab = newtab; + newtab = NULL; + } + break; + case -EAGAIN: + if (i > 0) { + memmove(&newtab->u.a.buf[0], &newtab->u.a.buf[j], i); } + newtab->u.a.ibuf = i; + break; + default: + fprintf(stderr, "eval error: %d\n", r); + close(newtab->u.a.fd); + free(newtab->tab); + free(newtab); + newtab = NULL; + break; } - n -= 1; - } else { - pst = &st->next; } - nst += 1; - } while ((*pst != NULL) && (n > 0)); + } + n -= 1; } if ((n > 0) && (n0 >= 0) && (r = pollfd_rev(n0))) { if (r & (POLLNVAL | POLLERR)) {