When playing with filters its easy to forget to register
stdout, etc...

Here is a patch to add a timeout and give a little helpful info as
opposed to just hanging in an unusable state.
Index: lka_filter.c
===================================================================
RCS file: /cvs/src/usr.sbin/smtpd/lka_filter.c,v
retrieving revision 1.62
diff -u -p -u -r1.62 lka_filter.c
--- lka_filter.c        24 Apr 2020 11:34:07 -0000      1.62
+++ lka_filter.c        2 May 2020 15:37:56 -0000
@@ -66,6 +66,7 @@ static void   filter_result_disconnect(uin
 static void    filter_session_io(struct io *, int, void *);
 void           lka_filter_process_response(const char *, const char *);
 
+static void    lka_proc_timeout(int, short, void *);
 
 struct filter_session {
        uint64_t        id;
@@ -180,6 +181,7 @@ struct processor_instance {
        char                    *name;
        struct io               *io;
        struct io               *errfd;
+       struct event             tmo;
        int                      ready;
        uint32_t                 subsystems;
 };
@@ -213,10 +215,13 @@ lka_proc_config(struct processor_instanc
        io_printf(pi->io, "config
 }
 
+#define TIMEOUT 10
+
 void
 lka_proc_forked(const char *name, uint32_t subsystems, int fd)
 {
        struct processor_instance       *processor;
+       struct timeval timeout = { TIMEOUT, 0 };
 
        if (!processors_inited) {
                dict_init(&processors);
@@ -232,6 +237,10 @@ lka_proc_forked(const char *name, uint32
 
        io_set_fd(processor->io, fd);
        io_set_callback(processor->io, processor_io, processor->name);
+
+       evtimer_set(&processor->tmo, lka_proc_timeout, processor);
+       evtimer_add(&processor->tmo, &timeout);
+
        dict_xset(&processors, name, processor);
 }
 
@@ -269,6 +278,7 @@ processor_register(const char *name, con
        processor = dict_xget(&processors, name);
 
        if (strcmp(line, "register
+               evtimer_del(&processor->tmo);
                processor->ready = 1;
                return;
        }
@@ -1741,4 +1751,12 @@ lka_report_proc(const char *name, const 
        sp = ep + 1;
 
        lka_report_filter_report(reqid, name, 0, direction, &tv, sp);
+}
+
+static void
+lka_proc_timeout(int fd, short events, void *arg)
+{
+       struct processor_instance *processor = arg;
+
+       fatalx("%s: failed to register", processor->name);
 }

Reply via email to