@@ -75,7 +75,10 @@ module_ret_code modules_ctx_loop_events(const char *ctx_name, const int max_even
7575 if (p -> fd == mod -> pubsub_fd [0 ]) {
7676 /* Received on pubsub interface */
7777 * (bool * )& msg .is_pubsub = true;
78- read (p -> fd , (void * * )& msg .pubsub_msg , sizeof (pubsub_msg_t * ));
78+ if (read (p -> fd , (void * * )& msg .pubsub_msg , sizeof (pubsub_msg_t * )) != sizeof (pubsub_msg_t * )) {
79+ MODULE_DEBUG ("Failed to read message for %s: %s\n" , mod -> name , strerror (errno ));
80+ * ((pubsub_msg_t * * )& msg .pubsub_msg ) = NULL ;
81+ }
7982 } else {
8083 /* Received from FD */
8184 * (bool * )& msg .is_pubsub = false;
@@ -84,17 +87,19 @@ module_ret_code modules_ctx_loop_events(const char *ctx_name, const int max_even
8487 * (fd_msg_t * * )& msg .fd_msg = & fd_msg ;
8588 }
8689
87- /* If module is using some different receive function, honor it. */
88- recv_cb cb = stack_peek (mod -> recvs );
89- if (!cb ) {
90- /* Fallback to module default receive */
91- cb = mod -> hook .recv ;
92- }
93- cb (& msg , mod -> userdata );
94-
95- /* Properly free pubsub msg */
96- if (p -> fd == mod -> pubsub_fd [0 ]) {
97- destroy_pubsub_msg ((pubsub_msg_t * )msg .pubsub_msg );
90+ if (!msg .is_pubsub || msg .pubsub_msg ) {
91+ /* If module is using some different receive function, honor it. */
92+ recv_cb cb = stack_peek (mod -> recvs );
93+ if (!cb ) {
94+ /* Fallback to module default receive */
95+ cb = mod -> hook .recv ;
96+ }
97+ cb (& msg , mod -> userdata );
98+
99+ /* Properly free pubsub msg */
100+ if (msg .is_pubsub ) {
101+ destroy_pubsub_msg ((pubsub_msg_t * )msg .pubsub_msg );
102+ }
98103 }
99104 } else {
100105 /* Forward error to below handling code */
0 commit comments