Просмотр исходного кода

ncd: modules: expect all methods to be called even when the base statement is not up, instead of asserting. This
will be possible in the future, and may be now due to a bug in ncd.c.

ambrop7 14 лет назад
Родитель
Сommit
abaa48811f

+ 2 - 2
ncd/modules/event_template.c

@@ -183,7 +183,7 @@ void event_template_dequeue (event_template *o, int *out_is_empty)
     }
 }
 
-void event_template_assert_enabled (event_template *o)
+int event_template_is_enabled (event_template *o)
 {
-    ASSERT(o->enabled)
+    return o->enabled;
 }

+ 1 - 1
ncd/modules/event_template.h

@@ -59,6 +59,6 @@ void event_template_die (event_template *o);
 int event_template_getvar (event_template *o, const char *name, NCDValue *out);
 void event_template_queue (event_template *o, BStringMap map, int *out_was_empty);
 void event_template_dequeue (event_template *o, int *out_is_empty);
-void event_template_assert_enabled (event_template *o);
+int event_template_is_enabled (event_template *o);
 
 #endif

+ 5 - 1
ncd/modules/net_iptables.c

@@ -498,7 +498,11 @@ static void unlock_func_new (NCDModuleInst *i)
         goto fail1;
     }
     
-    ASSERT(lock->state == LOCK_STATE_LOCKED)
+    // make sure lock is locked
+    if (lock->state != LOCK_STATE_LOCKED) {
+        BLog(BLOG_ERROR, "lock is not locked");
+        goto fail1;
+    }
     
     // set lock
     o->lock = lock;

+ 7 - 2
ncd/modules/net_watch_interfaces.c

@@ -249,7 +249,7 @@ static void remove_device (struct instance *o, struct device *device)
 
 static void next_event (struct instance *o)
 {
-    event_template_assert_enabled(&o->templ);
+    ASSERT(event_template_is_enabled(&o->templ))
     
     // order template to finish the current event
     int is_empty;
@@ -461,7 +461,12 @@ static void nextevent_func_new (NCDModuleInst *i)
     
     // get method object
     struct instance *mo = i->method_object->inst_user;
-    event_template_assert_enabled(&mo->templ);
+    
+    // make sure we are currently reporting an event
+    if (!event_template_is_enabled(&mo->templ)) {
+        ModuleLog(o->i, BLOG_ERROR, "not reporting an event");
+        goto fail1;
+    }
     
     // signal up.
     // Do it before finishing the event so our process does not advance any further if

+ 7 - 1
ncd/modules/sys_evdev.c

@@ -57,6 +57,7 @@
 #include <linux/input.h>
 
 #include <misc/nonblocking.h>
+#include <misc/debug.h>
 
 #include <ncd/NCDModule.h>
 
@@ -333,7 +334,12 @@ static void nextevent_func_new (NCDModuleInst *i)
     
     // get method object
     struct instance *mo = i->method_object->inst_user;
-    ASSERT(mo->processing)
+    
+    // make sure we are currently reporting an event
+    if (!mo->processing) {
+        ModuleLog(o->i, BLOG_ERROR, "not reporting an event");
+        goto fail1;
+    }
     
     // signal up.
     // Do it before finishing the event so our process does not advance any further if

+ 6 - 1
ncd/modules/sys_watch_directory.c

@@ -406,7 +406,12 @@ static void nextevent_func_new (NCDModuleInst *i)
     
     // get method object
     struct instance *mo = i->method_object->inst_user;
-    ASSERT(mo->processing)
+    
+    // make sure we are currently reporting an event
+    if (!mo->processing) {
+        ModuleLog(o->i, BLOG_ERROR, "not reporting an event");
+        goto fail1;
+    }
     
     // signal up.
     // Do it before finishing the event so our process does not advance any further if

+ 7 - 2
ncd/modules/sys_watch_input.c

@@ -265,7 +265,7 @@ static void remove_device (struct instance *o, struct device *device)
 
 static void next_event (struct instance *o)
 {
-    event_template_assert_enabled(&o->templ);
+    ASSERT(event_template_is_enabled(&o->templ))
     
     // order template to finish the current event
     int is_empty;
@@ -440,7 +440,12 @@ static void nextevent_func_new (NCDModuleInst *i)
     
     // get method object
     struct instance *mo = i->method_object->inst_user;
-    event_template_assert_enabled(&mo->templ);
+    
+    // make sure we are currently reporting an event
+    if (!event_template_is_enabled(&mo->templ)) {
+        ModuleLog(o->i, BLOG_ERROR, "not reporting an event");
+        goto fail1;
+    }
     
     // signal up.
     // Do it before finishing the event so our process does not advance any further if

+ 7 - 2
ncd/modules/sys_watch_usb.c

@@ -250,7 +250,7 @@ static void remove_device (struct instance *o, struct device *device)
 
 static void next_event (struct instance *o)
 {
-    event_template_assert_enabled(&o->templ);
+    ASSERT(event_template_is_enabled(&o->templ))
     
     // order template to finish the current event
     int is_empty;
@@ -408,7 +408,12 @@ static void nextevent_func_new (NCDModuleInst *i)
     
     // get method object
     struct instance *mo = i->method_object->inst_user;
-    event_template_assert_enabled(&mo->templ);
+    
+    // make sure we are currently reporting an event
+    if (!event_template_is_enabled(&mo->templ)) {
+        ModuleLog(o->i, BLOG_ERROR, "not reporting an event");
+        goto fail1;
+    }
     
     // signal up.
     // Do it before finishing the event so our process does not advance any further if