Internal scheduler initialization cannot return NULL anymore.
authorPekka Riikonen <priikone@silcnet.org>
Fri, 16 Feb 2007 14:38:47 +0000 (14:38 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Fri, 16 Feb 2007 14:38:47 +0000 (14:38 +0000)
lib/silcutil/silcschedule.c
lib/silcutil/silcschedule_i.h
lib/silcutil/stacktrace.c
lib/silcutil/symbian/silcsymbianscheduler.cpp
lib/silcutil/unix/silcunixnet.c
lib/silcutil/unix/silcunixschedule.c
lib/silcutil/win32/silcwin32schedule.c

index adfacd55ea9eb04ca171ee0e001c151a3ad60124..7ffcc51088be6edb0b1f22cd0d60a4b9d13f10d0 100644 (file)
@@ -325,8 +325,10 @@ SilcSchedule silc_schedule_init(int max_tasks, void *app_context)
   schedule->fd_queue =
     silc_hash_table_alloc(0, silc_hash_uint, NULL, NULL, NULL,
                          silc_schedule_fd_destructor, NULL, TRUE);
-  if (!schedule->fd_queue)
+  if (!schedule->fd_queue) {
+    silc_free(schedule);
     return NULL;
+  }
 
   silc_list_init(schedule->timeout_queue, struct SilcTaskStruct, next);
   silc_list_init(schedule->free_tasks, struct SilcTaskStruct, next);
@@ -340,6 +342,12 @@ SilcSchedule silc_schedule_init(int max_tasks, void *app_context)
 
   /* Initialize the platform specific scheduler. */
   schedule->internal = schedule_ops.init(schedule, app_context);
+  if (!schedule->internal) {
+    silc_hash_table_free(schedule->fd_queue);
+    silc_mutex_free(schedule->lock);
+    silc_free(schedule);
+    return NULL;
+  }
 
   /* Timeout freelist garbage collection */
   silc_schedule_task_add_timeout(schedule, silc_schedule_timeout_gc,
index 04976c36dbe1e7ee9f1bcd3571cb4b9930ed53db..fcb47aa48bd8863b92237b8892971c6cd675bee7 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2001 - 2006 Pekka Riikonen
+  Copyright (C) 2001 - 2007 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -86,7 +86,8 @@ typedef struct {
   /* Initializes the platform specific scheduler.  This for example initializes
      the wakeup mechanism of the scheduler.  In multi-threaded environment
      the scheduler needs to be wakenup when tasks are added or removed from
-     the task queues.  Returns context to the platform specific scheduler. */
+     the task queues.  Returns context to the platform specific scheduler.
+     If this returns NULL the scheduler initialization will fail. */
   void *(*init)(SilcSchedule schedule, void *app_context);
 
   /* Uninitializes the platform specific scheduler context. */
index 1a93192647fb7623deba80a6d136677701cbc05a..2174080cf867202275fae67a9613cf26c3ad6883 100644 (file)
@@ -203,7 +203,7 @@ void silc_st_dump(void)
       fprintf(fp, "<stacktrace>%s:%d: #blocks=%lu, bytes=%lu\n",
              stack->file, stack->line, blocks, bytes);
       for (i = 0; i < stack->depth; i++)
-       fprintf(fp, "<pc>%p\n", stack->stack[i]);
+       fprintf(fp, "\tpc=%p\n", stack->stack[i]);
     }
   }
 
index bf3ee235e0f6811afe0014c6b3b6c0dcc9a1b2ce..d8a8a1836327efbd6f8dd3f044a309c6bf2a425f 100644 (file)
@@ -4,7 +4,7 @@
 \r
   Author: Pekka Riikonen <priikone@silcnet.org>\r
 \r
-  Copyright (C) 1998 - 2006 Pekka Riikonen\r
+  Copyright (C) 1998 - 2007 Pekka Riikonen\r
 \r
   This program is free software; you can redistribute it and/or modify\r
   it under the terms of the GNU General Public License as published by\r
@@ -48,7 +48,7 @@ void *silc_schedule_internal_init(SilcSchedule schedule,
                                  void *app_context)\r
 {\r
   /* Nothing to do */\r
-  return NULL;\r
+  return (void *)1;\r
 }\r
 \r
 \r
index ba1736ddee769a219d94ead785bbb0f0c7925760..4254fab98c0b6c171e7cb0679c6d30eec55aadc4 100644 (file)
@@ -641,6 +641,8 @@ SILC_FSM_STATE(silc_net_connect_st_connected)
     return SILC_FSM_CONTINUE;
   }
 
+  SILC_LOG_DEBUG(("TCP connection established"));
+
   /** Connection created */
   silc_fsm_next(fsm, silc_net_connect_st_stream);
   SILC_FSM_CALL((conn->sop = silc_socket_tcp_stream_create(
index df080730f30cfc48965b8a972c87f0891c8ae266..9a4ae9a49a192c1f507055bed2d9d443773d7a6c 100644 (file)
@@ -338,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);
index f4a263fcbd4d712df36479066f893c75b401b568..aa2cd2542fd7d5545c8520e96ee69a8aaac1aa0d 100644 (file)
@@ -242,7 +242,7 @@ void *silc_schedule_internal_init(SilcSchedule schedule, void *app_context)
 
   return (void *)wakeup;
 #else
-  return NULL;
+  return (void *)1;
 #endif
 }