-
- op_list = create_list_of_operations(1, listenop);
-
- com_err(whoami, 0, "started (pid %d)", getpid());
- com_err(whoami, 0, rcsid_sms_main_c);
- send_zgram("SMS", "server started");
-
- /*
- * Run until shut down.
- */
- while(!takedown) {
- register int i;
- /*
- * Block until something happens.
- */
-#ifdef notdef
- com_err(whoami, 0, "tick");
-#endif notdef
- errno = 0;
- status = op_select_any(op_list, 0,
- (fd_set *)NULL, (fd_set *)NULL,
- (fd_set *)NULL, (struct timeval *)NULL);
-
- if (status == -1) {
- com_err(whoami, errno, " error from op_select");
- continue;
- } else if (status != -2) {
- com_err(whoami, 0, " wrong return from op_select_any");
- continue;
- }
- if (takedown) break;
- time(&now);
-#ifdef notdef
- fprintf(stderr, " tick\n");
-#endif notdef
- /*
- * Handle any new connections; this comes first so
- * errno isn't tromped on.
- */
- if (OP_DONE(listenop)) {
- if (OP_STATUS(listenop) == OP_CANCELLED) {
- if (errno == EWOULDBLOCK) {
- do_reset_listen();
- } else {
- com_err(whoami, errno,
- " error on listen");
- exit(1);
- }
- } else if ((status = new_connection()) != 0) {
- com_err(whoami, errno,
- " Error on listening operation.");
- /*
- * Sleep here to prevent hosing?
- */
- }
- }
- /*
- * Handle any existing connections.
- */
- tardy = now - 30*60;
-
- for (i=0; i<nclients; i++) {
- cur_client = clients[i];
- if (OP_DONE(clients[i]->pending_op)) {
- cur_client->last_time_used = now;
- do_client(cur_client);
- } else if (clients[i]->last_time_used < tardy) {
- com_err(whoami, 0, "Shutting down connection due to inactivity");
- shutdown(cur_client->con->in.fd, 0);
- }
- cur_client = NULL;
- if (takedown) break;
+ else if (dormant == GROGGY)
+ {
+ mr_open_database();
+ com_err(whoami, 0, "database open");
+ mr_setup_signals();
+ send_zgram("MOIRA", "database open again");
+ dormant = AWAKE;
+ }
+
+ errno = 0;
+ status = op_select_any(op_list, 0, NULL, NULL, NULL, NULL);
+ if (status == -1)
+ {
+ if (errno != EINTR)
+ com_err(whoami, errno, " error from op_select");
+ if (!inc_running || now - inc_started > INC_TIMEOUT)
+ next_incremental();
+ continue;
+ }
+ else if (status != -2)
+ {
+ com_err(whoami, 0, " wrong return from op_select_any");
+ continue;
+ }
+ if (takedown)
+ break;
+ time(&now);
+ if (!inc_running || now - inc_started > INC_TIMEOUT)
+ next_incremental();
+
+ /*
+ * Handle any new connections; this comes first so
+ * errno isn't tromped on.
+ */
+ if (OP_DONE(listenop))
+ {
+ if (OP_STATUS(listenop) == OP_CANCELLED)
+ {
+ if (errno == EWOULDBLOCK)
+ do_reset_listen();
+ else
+ {
+ static int count = 0;
+ com_err(whoami, errno, " error (%d) on listen", count);
+ if (count++ > 10)
+ exit(1);