Internal scheduler initialization cannot return NULL anymore.
[silc.git] / lib / silcutil / unix / silcunixschedule.c
index 14fd31efd6c764ca0434b2bb8cb74f55c57f2bd1..9a4ae9a49a192c1f507055bed2d9d443773d7a6c 100644 (file)
@@ -267,31 +267,42 @@ SilcBool silc_schedule_internal_schedule_fd(SilcSchedule schedule,
   struct epoll_event event;
 
   if (!internal)
-    return FALSE;
+    return TRUE;
+
+  SILC_LOG_DEBUG(("Scheduling fd %lu, mask %x", task->fd, event_mask));
 
   event.events = 0;
-  if (task->events & SILC_TASK_READ)
+  if (event_mask & SILC_TASK_READ)
     event.events |= (EPOLLIN | EPOLLPRI);
-  if (task->events & SILC_TASK_WRITE)
+  if (event_mask & SILC_TASK_WRITE)
     event.events |= EPOLLOUT;
 
   /* Zero mask unschedules task */
   if (silc_unlikely(!event.events)) {
-    epoll_ctl(internal->epfd, EPOLL_CTL_DEL, task->fd, &event);
+    if (epoll_ctl(internal->epfd, EPOLL_CTL_DEL, task->fd, &event)) {
+      SILC_LOG_DEBUG(("epoll_ctl (DEL): %s", strerror(errno)));
+      return FALSE;
+    }
     return TRUE;
   }
 
   /* Schedule the task */
   if (silc_unlikely(!task->scheduled)) {
     event.data.ptr = task;
-    epoll_ctl(internal->epfd, EPOLL_CTL_ADD, task->fd, &event);
+    if (epoll_ctl(internal->epfd, EPOLL_CTL_ADD, task->fd, &event)) {
+      SILC_LOG_DEBUG(("epoll_ctl (ADD): %s", strerror(errno)));
+      return FALSE;
+    }
     task->scheduled = TRUE;
     return TRUE;
   }
 
   /* Schedule for specific mask */
   event.data.ptr = task;
-  epoll_ctl(internal->epfd, EPOLL_CTL_MOD, task->fd, &event);
+  if (epoll_ctl(internal->epfd, EPOLL_CTL_MOD, task->fd, &event)) {
+    SILC_LOG_DEBUG(("epoll_ctl (MOD): %s", strerror(errno)));
+    return FALSE;
+  }
 #endif /* HAVE_EPOLL_WAIT */
   return TRUE;
 }
@@ -327,8 +338,10 @@ void *silc_schedule_internal_init(SilcSchedule schedule,
 
 #if defined(HAVE_EPOLL_WAIT)
   internal->epfd = epoll_create(4);
-  if (internal->epfd < 0)
+  if (internal->epfd < 0) {
+    SILC_LOG_ERROR(("epoll_create() failed: %s", strerror(errno)));
     return NULL;
+  }
   internal->fds = silc_calloc(4, sizeof(*internal->fds));
   if (!internal->fds) {
     close(internal->epfd);