diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/csv.c | 8 | ||||
| -rw-r--r-- | lib/frr_pthread.c | 1 | ||||
| -rw-r--r-- | lib/frr_zmq.c | 6 | ||||
| -rw-r--r-- | lib/hash.c | 12 | ||||
| -rw-r--r-- | lib/prefix.c | 3 | ||||
| -rw-r--r-- | lib/ptm_lib.c | 8 | ||||
| -rw-r--r-- | lib/sigevent.c | 2 | ||||
| -rw-r--r-- | lib/thread.c | 42 |
8 files changed, 68 insertions, 14 deletions
@@ -663,8 +663,8 @@ int main() log_verbose("Mem: %d\n", get_memory_usage(getpid())); csv_init(&csv, buf, 256); - sprintf(hdr1, "%4u", 0); - sprintf(hdr2, "%4u", 1); + sprintf(hdr1, "%4d", 0); + sprintf(hdr2, "%4d", 1); log_verbose("(%zu/%zu/%d/%d)\n", strlen(hdr1), strlen(hdr2), atoi(hdr1), atoi(hdr2)); rec = csv_encode(&csv, 2, hdr1, hdr2); @@ -676,8 +676,8 @@ int main() } csv_encode(&csv, 2, "pdfadfadfadsadsaddfdfdsfdsd", "35444554545454545"); log_verbose("%s\n", buf); - sprintf(hdr1, "%4u", csv.csv_len); - sprintf(hdr2, "%4u", 1); + sprintf(hdr1, "%4d", csv.csv_len); + sprintf(hdr2, "%4d", 1); log_verbose("(%zu/%zu/%d/%d)\n", strlen(hdr1), strlen(hdr2), atoi(hdr1), atoi(hdr2)); rec = csv_encode_record(&csv, rec, 2, hdr1, hdr2); diff --git a/lib/frr_pthread.c b/lib/frr_pthread.c index 36a89168c2..00681b9db8 100644 --- a/lib/frr_pthread.c +++ b/lib/frr_pthread.c @@ -269,7 +269,6 @@ static int fpt_halt(struct frr_pthread *fpt, void **res) { thread_add_event(fpt->master, &fpt_finish, fpt, 0, NULL); pthread_join(fpt->thread, res); - fpt = NULL; return 0; } diff --git a/lib/frr_zmq.c b/lib/frr_zmq.c index 8f190a3a09..3153e697fa 100644 --- a/lib/frr_zmq.c +++ b/lib/frr_zmq.c @@ -174,9 +174,10 @@ int funcname_frrzmq_thread_add_read(struct thread_master *master, cb = *cbp; else { cb = XCALLOC(MTYPE_ZEROMQ_CB, sizeof(struct frrzmq_cb)); - cb->write.cancelled = 1; if (!cb) return -1; + + cb->write.cancelled = 1; *cbp = cb; } @@ -282,9 +283,10 @@ int funcname_frrzmq_thread_add_write(struct thread_master *master, cb = *cbp; else { cb = XCALLOC(MTYPE_ZEROMQ_CB, sizeof(struct frrzmq_cb)); - cb->read.cancelled = 1; if (!cb) return -1; + + cb->read.cancelled = 1; *cbp = cb; } diff --git a/lib/hash.c b/lib/hash.c index ee5401b236..37f6cdcc8f 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -241,15 +241,21 @@ void hash_iterate(struct hash *hash, void (*func)(struct hash_backet *, void *), unsigned int i; struct hash_backet *hb; struct hash_backet *hbnext; + uint32_t count = 0; - for (i = 0; i < hash->size; i++) + for (i = 0; i < hash->size; i++) { for (hb = hash->index[i]; hb; hb = hbnext) { /* get pointer to next hash backet here, in case (*func) * decides to delete hb by calling hash_release */ hbnext = hb->next; (*func)(hb, arg); + count++; + } + if (count == hash->count) + return; + } } void hash_walk(struct hash *hash, int (*func)(struct hash_backet *, void *), @@ -259,6 +265,7 @@ void hash_walk(struct hash *hash, int (*func)(struct hash_backet *, void *), struct hash_backet *hb; struct hash_backet *hbnext; int ret = HASHWALK_CONTINUE; + uint32_t count = 0; for (i = 0; i < hash->size; i++) { for (hb = hash->index[i]; hb; hb = hbnext) { @@ -269,7 +276,10 @@ void hash_walk(struct hash *hash, int (*func)(struct hash_backet *, void *), ret = (*func)(hb, arg); if (ret == HASHWALK_ABORT) return; + count++; } + if (count == hash->count) + return; } } diff --git a/lib/prefix.c b/lib/prefix.c index ed0774e774..b129665e7b 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -1197,6 +1197,9 @@ int str2prefix(const char *str, struct prefix *p) { int ret; + if (!str || !p) + return 0; + /* First we try to convert string to struct prefix_ipv4. */ ret = str2prefix_ipv4(str, (struct prefix_ipv4 *)p); if (ret) diff --git a/lib/ptm_lib.c b/lib/ptm_lib.c index fea5a8cc40..69fd61e2a0 100644 --- a/lib/ptm_lib.c +++ b/lib/ptm_lib.c @@ -60,10 +60,10 @@ static csv_record_t *_ptm_lib_encode_header(csv_t *csv, csv_record_t *rec, char client_buf[32]; csv_record_t *rec1; - sprintf(msglen_buf, "%4u", msglen); - sprintf(vers_buf, "%4u", version); - sprintf(type_buf, "%4u", type); - sprintf(cmdid_buf, "%4u", cmd_id); + sprintf(msglen_buf, "%4d", msglen); + sprintf(vers_buf, "%4d", version); + sprintf(type_buf, "%4d", type); + sprintf(cmdid_buf, "%4d", cmd_id); snprintf(client_buf, 17, "%16.16s", client_name); if (rec) { rec1 = csv_encode_record(csv, rec, 5, msglen_buf, vers_buf, diff --git a/lib/sigevent.c b/lib/sigevent.c index d299760fab..59eaa80370 100644 --- a/lib/sigevent.c +++ b/lib/sigevent.c @@ -119,8 +119,6 @@ int quagga_sigevent_process(void) int quagga_signal_timer(struct thread *t) { struct quagga_sigevent_master_t *sigm; - struct quagga_signal_t *sig; - int i; sigm = THREAD_ARG(t); sigm->t = NULL; diff --git a/lib/thread.c b/lib/thread.c index 18e1c92280..1c5e838772 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -296,6 +296,47 @@ DEFUN (show_thread_cpu, return CMD_SUCCESS; } +static void show_thread_poll_helper(struct vty *vty, struct thread_master *m) +{ + const char *name = m->name ? m->name : "main"; + char underline[strlen(name) + 1]; + uint32_t i; + + memset(underline, '-', sizeof(underline)); + underline[sizeof(underline) - 1] = '\0'; + + vty_out(vty, "\nShowing poll FD's for %s\n", name); + vty_out(vty, "----------------------%s\n", underline); + vty_out(vty, "Count: %u\n", (uint32_t)m->handler.pfdcount); + for (i = 0; i < m->handler.pfdcount; i++) + vty_out(vty, "\t%6d fd:%6d events:%2d revents:%2d\n", i, + m->handler.pfds[i].fd, + m->handler.pfds[i].events, + m->handler.pfds[i].revents); +} + +DEFUN (show_thread_poll, + show_thread_poll_cmd, + "show thread poll", + SHOW_STR + "Thread information\n" + "Show poll FD's and information\n") +{ + struct listnode *node; + struct thread_master *m; + + pthread_mutex_lock(&masters_mtx); + { + for (ALL_LIST_ELEMENTS_RO(masters, node, m)) { + show_thread_poll_helper(vty, m); + } + } + pthread_mutex_unlock(&masters_mtx); + + return CMD_SUCCESS; +} + + DEFUN (clear_thread_cpu, clear_thread_cpu_cmd, "clear thread cpu [FILTER]", @@ -325,6 +366,7 @@ DEFUN (clear_thread_cpu, void thread_cmd_init(void) { install_element(VIEW_NODE, &show_thread_cpu_cmd); + install_element(VIEW_NODE, &show_thread_poll_cmd); install_element(ENABLE_NODE, &clear_thread_cpu_cmd); } /* CLI end ------------------------------------------------------------------ */ |
