-
- /*
- * Set up client array handler.
- */
- nclients = 0;
- clients = (client **) malloc(0);
-
- /*
- * Signal handlers
- * There should probably be a few more of these.
- */
-
- if ((((int)signal (SIGTERM, sigshut)) < 0) ||
- (((int)signal (SIGHUP, sigshut)) < 0)) {
- com_err(whoami, errno, "Unable to establish signal handler.");
- exit(1);
- }
-
- /*
- * Establish template connection.
- */
- if ((status = do_listen()) != 0) {
- com_err(whoami, status,
- "while trying to create listening connection");
- exit(1);
- }
-
- op_list = create_list_of_operations(1, listenop);
-
- com_err(whoami, 0, "started (pid %d)", getpid());
- com_err(whoami, 0, rcsid_sms_main_c);
-
- /*
- * 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;
- }