main(int argc, char *argv[]) { if (TestAndLock()) { fprintf(stderr, "Another unwind running or abandoned, please check\n"); exit(EXIT_FAILURE); } ParseArgs(argc, argv); InitSignals(); InitLog(); if (chdir(CodaUserDir)) { RemoveLock(); Die("Could not cd into %s", CodaUserDir); } if (InitDB(DataBaseName)) { RemoveLock(); fprintf(stderr, "Could not connect to database %s", DataBaseName); exit(EXIT_FAILURE); } LogMsg(100, LogLevel, LogFile, "Enter ProcessEachUser"); ProcessEachUser(); RemoveLock(); Log_Done(); }
static void ParseArgs(int argc, char *argv[]) { for (int i = 1; i < argc; i++) { if (STREQ(argv[i], "-db")) { /* database */ DataBaseName = argv[++i]; continue; } if (STREQ(argv[i], "-wd")) { /* working directory */ WorkingDir = argv[++i]; continue; } else if (STREQ(argv[i], "-d")) { /* log level */ LogLevel = atoi(argv[++i]); continue; } else if (STREQ(argv[i], "-R")) { /* remove */ removeOnDone = mtrue; continue; } else if (STREQ(argv[i], "-r")) { /* don't remove */ removeOnDone = mfalse; continue; } else if (STREQ(argv[i], "-L")) { /* log */ doLog = mtrue; continue; } else if (STREQ(argv[i], "-l")) { /* don't log */ doLog = mfalse; continue; } printf("usage: myunwind [-db database] [-wd workingDir]\n"); printf(" [-d logLevel] [-R | -r] [-L | -l]\n"); RemoveLock(); exit(EXIT_FAILURE); } }
void App::Exit() { if (testing) { char* testmsg = "This is a test message :-)"; LoginPanel->Message(testmsg); sleep(3); } else { delete LoginPanel; StopServer(); RemoveLock(); } exit(OK_EXIT); }
// Redirect stdout and stderr to log file void App::OpenLog() { FILE *log = fopen (cfg.getOption("logfile").c_str(),"a"); if (!log) { cerr << APPNAME << ": Could not accesss log file: " << cfg.getOption("logfile") << endl; RemoveLock(); exit(ERR_EXIT); } fclose(log); freopen (cfg.getOption("logfile").c_str(),"a",stdout); setvbuf(stdout, NULL, _IOLBF, BUFSIZ); freopen (cfg.getOption("logfile").c_str(),"a",stderr); setvbuf(stderr, NULL, _IONBF, BUFSIZ); }
main (int argc, char *argv[]) { if (TestAndLock()) { fprintf(stderr, "Another unwind running or abandoned, please check\n"); exit(-1); } ParseArgs(argc, argv); InitSignals(); InitLog(); if (chdir(WorkingDir)) { RemoveLock(); Die("Could not cd into %s",WorkingDir); } if (InitDB(DataBaseName)) { RemoveLock(); fprintf(stderr,"Could not connect to database %s",DataBaseName); exit(-1); } GetFilesAndSpool(); RemoveLock(); Log_Done(); }
void App::Halt() { // Stop alarm clock alarm(0); // Write message LoginPanel->Message((char*)cfg.getOption("shutdown_msg").c_str()); sleep(3); // Stop server and halt StopServer(); RemoveLock(); system(cfg.getOption("halt_cmd").c_str()); exit(OK_EXIT); }
bool FileRecord::RemoveLock(const std::string& lock_id) { std::list<std::pair<std::string,std::string> > ids; return RemoveLock(lock_id,ids); }
static void ReleaseCriticalSection() { RemoveLock("CF_CRITICAL_SECTION"); }