+/*----- 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);
+}
+