- * \param msg a \p NULL terminated buffer
- */
-void stat_client_write(char *msg, int itemnum)
-{
- struct stat_client *sc, *tmp;
-// char *buf;
- ssize_t len;
- struct timeval tv = {0 , 0};
-
- if (!initialized)
- return;
-// buf = make_message("%s\n", msg);
- len = strlen(msg);
- 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);
- do
- ret = select(fd + 1, NULL, &wfds, NULL, &tv);
- while (ret < 0 && errno == EINTR);
- if (ret) {
- ret = write(fd, msg, len);
- PARA_DEBUG_LOG("dumped %s to fd %d, ret = %d\n", msg, fd, ret);
- if (ret == len )
- continue;
- }
- /* write error or fd not ready for writing */
- close(fd);
- del_close_on_fork_list(fd);
- num_clients--;
- PARA_INFO_LOG("deleting client on fd %d\n", fd);
- list_del(&sc->node);
- free(sc);
- dump_stat_client_list();
- }
-// free(buf);
- PARA_DEBUG_LOG("%d client(s)\n", num_clients);
-}
-
-/**
- * send empty status list
- *
- * Send to each connected client the full status item list
- * with empty values.
- */
-void dump_empty_status(void)
-{
- int i;
-
- if (!initialized)
- return;
- FOR_EACH_STAT_ITEM(i) {
- char *tmp = make_message("%s:\n", status_item_list[i]);
- stat_client_write(tmp, i);
- free(tmp);
- }
-}
-
-/**
- * check if string is a known status item.
- *
- * \param item buffer containing the text to check
- *
- * \return If \a item is a valid status item, the number of that status item is
- * returned. Otherwise, this function returns \p -E_UNKNOWN_STAT_ITEM.
- */
-int stat_item_valid(const char *item)
-{
- int i;
- if (!item || !*item)
- return -E_UNKNOWN_STAT_ITEM;
- FOR_EACH_STAT_ITEM(i)
- if (!strcmp(status_item_list[i], item))
- return i;
- return -E_UNKNOWN_STAT_ITEM;
-}
-
-/**
- * check if line starts with known status item.
- *
- * \param line buffer containing the line
- *
- * \return If the beginning of \a line matches any paraslash status item and is
- * followed by a colon, the number of that status item is returned. Otherwise,
- * this function returns \p -E_UNKNOWN_STAT_ITEM.
- */
-int stat_line_valid(const char *line)
-{
- int i;
- size_t line_len;
-
- if (!line || !*line)
- return -E_UNKNOWN_STAT_ITEM;
- line_len = strlen(line);
- FOR_EACH_STAT_ITEM(i) {
- const char *s = status_item_list[i];
- size_t item_len = strlen(s);
-
- if (line_len > item_len && line[item_len] == ':' &&
- !strncmp(line, s, item_len))
- return i;
- }
- return -E_UNKNOWN_STAT_ITEM;
-}
-
-/**
- * call a custom function for each complete line
- *
- * \param buf the buffer containing data seperated by newlines
- * \param n the number of bytes in \a buf
- * \param line_handler the custom function
- *
- * If \a line_handler is \p NULL, return number of complete lines in buf.
- * Otherwise, call \a line_handler for each complete line. The rest of the
- * buffer (last chunk containing incomplete line is moved to the beginning of
- * the buffer.