if (!iv_nreasons) sel_rmtimer(&it);
}
+/*----- The main loop -----------------------------------------------------*/
+
+/* --- @lp_init@ --- *
+ *
+ * Arguments: ---
+ *
+ * Returns: ---
+ *
+ * Use: Initializes the main loop. Most importantly, this sets up
+ * the select multiplexor that everything else hooks onto.
+ */
+
+void lp_init(void)
+{
+ rand_noisesrc(RAND_GLOBAL, &noise_source);
+ rand_seed(RAND_GLOBAL, MAXHASHSZ);
+ gettimeofday(&iv_next, 0); iv_next.tv_sec += T_INTERVAL;
+ signal(SIGPIPE, SIG_IGN);
+ sel_init(&sel);
+ sig_init(&sel);
+}
+
+/* --- @lp_run@ --- *
+ *
+ * Arguments: ---
+ *
+ * Returns: Zero on successful termination; @-1@ if things went wrong.
+ *
+ * Use: Cranks the main loop until it should be cranked no more.
+ */
+
+int lp_run(void)
+{
+ int nerr = 0;
+
+ for (;;) {
+ a_preselect();
+ if (!sel_select(&sel)) nerr = 0;
+ else if (errno != EINTR && errno != EAGAIN) {
+ a_warn("SERVER", "select-error", "?ERRNO", A_END);
+ nerr++;
+ if (nerr > 8) {
+ a_warn("ABORT", "repeated-select-errors", A_END);
+ abort();
+ }
+ }
+ }
+ return (0);
+}
+
/*----- Main code ---------------------------------------------------------*/
/* --- @main@ --- *
struct addrinfo aihint = { 0 }, *ailist;
unsigned f = 0;
int i;
- int err, selerr = 0;
+ int err;
unsigned af;
uid_t u = -1;
gid_t g = -1;
dir, strerror(errno));
}
- sel_init(&sel);
- sig_init(&sel);
- rand_noisesrc(RAND_GLOBAL, &noise_source);
- rand_seed(RAND_GLOBAL, MAXHASHSZ);
- signal(SIGPIPE, SIG_IGN);
+ lp_init();
if (!(f & f_daemon)) {
af = AF_WARN;
a_switcherr();
}
- gettimeofday(&iv_next, 0); iv_next.tv_sec += T_INTERVAL;
iv_addreason();
- for (;;) {
- a_preselect();
- if (!sel_select(&sel))
- selerr = 0;
- else if (errno != EINTR && errno != EAGAIN) {
- a_warn("SERVER", "select-error", "?ERRNO", A_END);
- selerr++;
- if (selerr > 8) {
- a_warn("ABORT", "repeated-select-errors", A_END);
- abort();
- }
- }
- }
-
+ lp_run();
return (0);
}
extern void iv_rmreason(void);
+/*----- The main loop -----------------------------------------------------*/
+
+/* --- @lp_init@ --- *
+ *
+ * Arguments: ---
+ *
+ * Returns: ---
+ *
+ * Use: Initializes the main loop. Most importantly, this sets up
+ * the select multiplexor that everything else hooks onto.
+ */
+
+extern void lp_init(void);
+
+/* --- @lp_run@ --- *
+ *
+ * Arguments: ---
+ *
+ * Returns: Zero on successful termination; @-1@ if things went wrong.
+ *
+ * Use: Cranks the main loop until it should be cranked no more.
+ */
+
+extern int lp_run(void);
+
/*----- Tunnel drivers ----------------------------------------------------*/
#ifdef TUN_LINUX