- flags = (long) fcntl(housepipe[1], F_GETFL);
- flags |= O_NONBLOCK;
- fcntl(housepipe[1], F_SETFL, flags);
-
- while(1) {
- do {
- did_something = 0;
- tv.tv_sec = HOUSEKEEPING_WAKEUP;
- tv.tv_usec = 0;
- FD_ZERO(&readfds);
- FD_SET(housepipe[0], &readfds);
- select(housepipe[0] + 1, &readfds, NULL, NULL, &tv);
- if (FD_ISSET(housepipe[0], &readfds)) {
- did_something = 1;
- }
-
- if (did_something) {
- read(housepipe[0], house_cmd, 256);
- }
- else {
- memset(house_cmd, 0, 256);
- strcpy(house_cmd, "MINUTE");
- }
-
- extract(cmd, house_cmd, 0);
- cdb_begin_transaction();
-
- /* Do whatever this cmd requires */
-
- /* Once-every-minute housekeeper */
- if (!strcmp(cmd, "MINUTE")) {
- terminate_idle_sessions();
- }
-
- /* Scheduled shutdown housekeeper */
- else if (!strcmp(cmd, "SCHED_SHUTDOWN")) {
- check_sched_shutdown();
- }
-
- /* Unknown */
- else {
- lprintf(7, "Unknown housekeeping command\n");
- }
-
- cdb_end_transaction();
-
- } while (did_something);
- }