void taskmain(int argc, char **argv) { L = luaL_newstate(); dbg_set_log(stderr); int rc = 0; check(argc == 3, "usage: mongrel2 config.lua server_name"); //if(argc == 4) { // log_info("Using configuration module %s to load configs.", argv[3]); // rc = Config_module_load(argv[3]); // check(rc != -1, "Failed to load the config module: %s", argv[3]); //} Server_queue_init(); Server *srv = load_server(L, argv[1], argv[2], NULL); check(srv != NULL, "Aborting since can't load server."); Server_queue_push(srv); SuperPoll_get_max_fd(); // rc = clear_pid_file(srv); // check(rc == 0, "PID file failure, aborting rather than trying to start."); // rc = attempt_chroot_drop(srv); // check(rc == 0, "Major failure in chroot/droppriv, aborting."); final_setup(); taskcreate(tickertask, NULL, TICKER_TASK_STACK); struct ServerTask *srv_data = calloc(1, sizeof(struct ServerTask)); srv_data->db_file = bfromcstr(argv[1]); srv_data->server_id = bfromcstr(argv[2]); // taskcreate(reload_task, srv_data, RELOAD_TASK_STACK); rc = Server_run(); check(rc != -1, "Server had a failure and exited early."); log_info("Server run exited, goodbye."); srv = Server_queue_latest(); complete_shutdown(srv); return; error: log_err("Exiting due to error."); taskexitall(1); }
static THREAD_FUNC TapeWriteThread(void *dummy) { int status; size_t blen, remain, want, put, nrec; char *ptr; OLD_MSGQ_MSG *obuf; static char *fid = "TapeWriteThread"; blen = Params->bfact * IDA_BUFSIZ; /* IDA10 OK */ MUTEX_LOCK(&mp); ioerr = 0; MUTEX_UNLOCK(&mp); while (1) { obuf = msgq_get(&Q->obuf, OLD_MSGQ_WAITFOREVER); if (!msgq_chkmsg2(fid, obuf)) { util_log(1, "%s: corrupt message received", fid); ispd_die(MY_MOD_ID + 1); } nrec = *((size_t *) obuf->data); util_log(1, "dumping %ld records to %s", nrec, Params->odev); ptr = obuf->data + sizeof(size_t); remain = nrec * IDA_BUFSIZ; /* IDA10 OK */ while (remain > 0) { want = remain > blen ? blen : remain; nrec = want / IDA_BUFSIZ; /* IDA10 OK */ do { lock_device(); put = mtio_write(tp, ptr, want); if (put == want) { MUTEX_LOCK(&Status->lock); Status->output.nrec += nrec; status = Status->output.state; MUTEX_UNLOCK(&Status->lock); ptr += put; if (ioerr) { clear_alarm(ISP_ALARM_IOERR); ioerr = 0; } } else { if (put != 0) { if (++ioerr == 1) { set_alarm(ISP_ALARM_IOERR); util_log(1, "%s: %s", Params->odev, syserrmsg(errno) ); } MUTEX_LOCK(&Status->lock); ++Status->output.err; MUTEX_UNLOCK(&Status->lock); eject_tape(0); } } release_device(); if (put != want) { if (shutting_down()) { complete_shutdown(); THREAD_EXIT(0); } else { sleep(5); } } } while (put != want); remain -= put; } util_log(1, "tape dump completed OK"); if (shutting_down()) { complete_shutdown(); THREAD_EXIT(0); } MUTEX_LOCK(&mp); if (eject_flag) eject_tape(0); eject_flag = 0; MUTEX_UNLOCK(&mp); msgq_put(&Heap->obuf, obuf); } }
static THREAD_FUNC TapeWatchThread(void *dummy) { int boot_flag; static struct mtget info; static char *fid = "TapeWatchThread"; boot_flag = 1; util_log(2, "TAPE_WATCH thread started, tid = %d", THREAD_SELF()); set_alarm(ISP_ALARM_OFFLINE); while (1) { MUTEX_LOCK(&mp); /* if we were offline, see if a tape is now present */ if (prev_state == MTIO_OFFLINE) { if ((tp = mtio_open(Params->odev, "w")) != null) { if (mtio_status(tp, &info) != -1) { crnt_state = MTIO_ONLINE; clear_alarm(ISP_ALARM_OFFLINE); if (ioerr) { clear_alarm(ISP_ALARM_IOERR); ioerr = 0; } check_tape(boot_flag); } else { mtio_close(tp); tp = (TAPE *) NULL; } } if (tp == null && shutting_down()) { util_log(1, "shutting down w/o final flush (no tape)"); complete_shutdown(); } /* if we were on-line, make sure we still are that way */ /* THIS CODE DOES NOT WORK AND I DON'T KNOW HOW TO MAKE IT WORK! */ } else if (mtio_nop(tp) < 0 || mtio_status(tp, &info) < 0) { mtio_close(tp); tp = (TAPE *) tp; set_alarm(ISP_ALARM_OFFLINE); crnt_state = MTIO_OFFLINE; } if (crnt_state != prev_state) { MUTEX_LOCK(&Status->lock); if (crnt_state == MTIO_ONLINE) { Status->output.state = ISP_OUTPUT_ONLINE; Status->output.err = 0; Status->output.file = info.mt_fileno + 1; Status->output.nrec = 0; } else { Status->output.state = ISP_OUTPUT_OFFLINE; } MUTEX_UNLOCK(&Status->lock); } prev_state = crnt_state; boot_flag = 0; if (pending && (crnt_state == MTIO_ONLINE)) { pending = 0; SEM_POST(&sp); } MUTEX_UNLOCK(&mp); sleep(10); } }