/* Adding the quit pipe */
kernel_pollfd[nb_fd - 1].fd = thread_quit_pipe[0];
+ kernel_pollfd[nb_fd - 1].events =
+ POLLHUP | POLLNVAL | POLLERR | POLLIN | POLLRDHUP | POLLPRI;
return nb_fd;
goto error;
} else if (ret == 0) {
/* Should not happen since timeout is infinite */
+ ERR("Return value of poll is 0 with an infinite timeout.\n"
+ "This should not have happened! Continuing...");
continue;
}
/* First fd is always the quit pipe */
(*pollfd)[0].fd = thread_quit_pipe[0];
+ (*pollfd)[0].events =
+ POLLHUP | POLLNVAL | POLLERR | POLLIN | POLLRDHUP | POLLPRI;
+
/* Apps command pipe */
(*pollfd)[1].fd = apps_cmd_pipe[0];
(*pollfd)[1].events = POLLIN;
}
}
+ if (nb_fd < 2) {
+ /*
+ * There should *always* be at least two fds in the pollfd. This safety
+ * check make sure the poll() will actually try on those two pipes at
+ * best which are the thread_quit_pipe and apps_cmd_pipe.
+ */
+ nb_fd = 2;
+ MSG("nb_fd < 2 --> Not good! Continuing...");
+ }
+
/* Destroy old pollfd */
free(old_pollfd);
*/
static void *thread_manage_apps(void *data)
{
- int i, ret, count;
+ int i, ret, current_nb_fd;
unsigned int nb_fd = 2;
int update_poll_flag = 1;
struct pollfd *pollfd = NULL;
DBG("[thread] Manage application started");
ust_cmd.sock = -1;
+ current_nb_fd = nb_fd;
while (1) {
/* See if we have a valid socket to add to pollfd */
/* The pollfd struct must be updated */
if (update_poll_flag) {
- ret = update_apps_cmd_pollfd(nb_fd, ARRAY_SIZE(pollfd), &pollfd);
+ ret = update_apps_cmd_pollfd(nb_fd, current_nb_fd, &pollfd);
if (ret < 0) {
/* malloc failed so we quit */
goto error;
}
}
- count = nb_fd;
- for (i = 2; i < count; i++) {
+ current_nb_fd = nb_fd;
+ for (i = 2; i < current_nb_fd; i++) {
/* Apps socket is closed/hungup */
switch (pollfd[i].revents) {
case POLLERR:
}
}
- if (nb_fd != count) {
+ if (nb_fd != current_nb_fd) {
update_poll_flag = 1;
}
}
/* First fd is always the quit pipe */
pollfd[0].fd = thread_quit_pipe[0];
+ pollfd[0].events =
+ POLLHUP | POLLNVAL | POLLERR | POLLIN | POLLRDHUP | POLLPRI;
/* Apps socket */
pollfd[1].fd = apps_sock;
/* First fd is always the quit pipe */
pollfd[0].fd = thread_quit_pipe[0];
+ pollfd[0].events =
+ POLLHUP | POLLNVAL | POLLERR | POLLIN | POLLRDHUP | POLLPRI;
/* Apps socket */
pollfd[1].fd = client_sock;