Index: kstat.c =================================================================== RCS file: /cvs/src/usr.bin/kstat/kstat.c,v retrieving revision 1.11 diff -u -p -r1.11 kstat.c --- kstat.c 10 Jul 2022 19:51:37 -0000 1.11 +++ kstat.c 11 Apr 2023 03:15:46 -0000 @@ -482,10 +482,9 @@ kstat_list(struct kstat_tree *kt, int fd ksreq->ks_version = version; ksreq->ks_id = ++id; - ksreq->ks_datalen = len = 64; /* magic */ - ksreq->ks_data = malloc(len); - if (ksreq->ks_data == NULL) - err(1, "data alloc"); + /* some kstat reads are slow, so avoid them for now */ + ksreq->ks_datalen = 0; + ksreq->ks_data = NULL; if (ioctl(fd, KSTATIOC_NFIND_ID, ksreq) == -1) { if (errno == ENOENT) { @@ -504,13 +503,7 @@ kstat_list(struct kstat_tree *kt, int fd continue; } - if (RBT_INSERT(kstat_tree, kt, kse) != NULL) - errx(1, "duplicate kstat entry"); - - if (kse->serrno != 0) - continue; - - while (ksreq->ks_datalen > len) { + do { len = ksreq->ks_datalen; ksreq->ks_data = realloc(ksreq->ks_data, len); if (ksreq->ks_data == NULL) @@ -518,7 +511,10 @@ kstat_list(struct kstat_tree *kt, int fd if (ioctl(fd, KSTATIOC_FIND_ID, ksreq) == -1) err(1, "find id %llu", ksreq->ks_id); - } + } while (ksreq->ks_datalen > len); + + if (RBT_INSERT(kstat_tree, kt, kse) != NULL) + errx(1, "duplicate kstat entry"); } }