- struct stat_client *new_client;
-
- if (num_clients >= MAX_STAT_CLIENTS) {
- PARA_ERROR_LOG("maximal number of stat clients (%d) exceeded\n",
- MAX_STAT_CLIENTS);
- return -E_TOO_MANY_CLIENTS;
- }
- if (!initialized) {
- INIT_LIST_HEAD(&client_list);
- initialized = 1;
- }
- PARA_INFO_LOG("adding client on fd %d\n", fd);
- new_client = para_malloc(sizeof(struct stat_client));
- new_client->fd = fd;
- new_client->item_mask = mask;
- para_list_add(&new_client->node, &client_list);
- dump_stat_client_list();
- num_clients++;
- return 1;
-}
-/**
- * write a message to all connected status clients
- *
- * \param msg a \p NULL terminated buffer
- * \param itemnum The number of the status item of \a msg
- *
- * On write errors, remove the status client from the client list and close its
- * file descriptor.
- */
-void stat_client_write(const char *msg, int itemnum)
-{
- struct stat_client *sc, *tmp;
- size_t len = strlen(msg);
- struct timeval tv = {0 , 0};
-
- if (!initialized || !len)
- return;
- list_for_each_entry_safe(sc, tmp, &client_list, node) {
- int fd = sc->fd, ret;
- fd_set wfds;
-
- if (!((1 << itemnum) & sc->item_mask))
- continue;
- FD_ZERO(&wfds);
- FD_SET(fd, &wfds);
-// PARA_DEBUG_LOG("%s: p=%lx\n", __func__, (long)p);
- ret = para_select(fd + 1, NULL, &wfds, &tv);
- if (ret > 0) {
- ret = write(fd, msg, len);
- PARA_DEBUG_LOG("dumped %s to fd %d, ret = %d\n", msg, fd, ret);
- if (ret == len )
+ char *buf = item_buf;
+ int len = num_bytes;
+
+ for (;;) {
+ int i, ret, item_len, item_num = 0;
+ if (len < MIN_STAT_ITEM_LEN)
+ break;
+ ret = read_size_header(buf);
+ if (ret < 0)
+ return ret;
+ item_len = ret;
+ if (item_len > len - 5) /* item not complete */
+ break;
+ for (i = 0; i < 2; i++) {
+ unsigned char c = buf[5 + i];
+ item_num <<= 4;
+ if (c >= '0' && c <= '9') {
+ item_num += c - '0';