int waste_main_exit () { if (!g_exit) //emergency break! { // exit log_printf(ds_Console,"cleaning up"); SaveDbToDisk(); delete g_listen; delete g_dns; if (g_newdatabase != g_database) delete g_newdatabase; delete g_database; }; int x; for (x = 0; x < g_recvs.GetSize(); x ++) delete g_recvs.Get(x); for (x = 0; x < g_sends.GetSize(); x ++) delete g_sends.Get(x); for (x = 0; x < g_new_net.GetSize(); x ++) delete g_new_net.Get(x); for (x = 0; x < g_uploads.GetSize(); x ++) free(g_uploads.Get(x)); if (g_aclist) free(g_aclist); KillPkList(); #ifdef _DEFINE_WXUI for (x = 0; x < SEARCHCACHE_NUMITEMS; x ++) delete g_searchcache[x]; KillDirgetlist(); KillSearchhistory(); #endif delete g_mql; delete g_config; memset(&g_key,0,sizeof(g_key)); #ifdef _WIN32 WSACleanup(); #endif log_UpdatePath(NULL); return 0; }
int main(int argc, char **argv) { g_log_level=ds_Console; _logfile=stderr; bool daemonise = false; const char *profile = NULL; const char *logpath = NULL; const char *pid = NULL; { bool dohelp = true; int i; for (i = 1; i < argc; i++) { if (!strcmp(argv[i],"-i")) { log_printf(ds_Console,"Interactive!"); daemonise = false; dohelp = false; } else if (!strcmp(argv[i],"-L")) { char *szLI2; szLI2=(char*)malloc(sK0[3]); safe_strncpy(szLI2,(char*)sK1[3],sK0[3]); dpi(szLI2,4); RelpaceCr(szLI2); fprintf(_logfile,"\n\n%s\n",szLI2); memset(szLI2,0,sK0[3]);free(szLI2); return 1; } else if (!strcmp(argv[i],"-d")) { daemonise = true; if (++i < argc) { logpath = argv[i]; dohelp = false; } else break; } else if (!strcmp(argv[i],"-p")) { if (++i < argc) { profile = argv[i]; dohelp = false; } else break; } else if (!strcmp(argv[i],"-P")) { if (++i < argc) { pid = argv[i]; FILE *pidfile = fopen(pid,"w"); if (pidfile != NULL) { fprintf(pidfile, "%i\n", (int)getpid() ); fclose(pidfile); } dohelp = false; } else break; } else break; } if (dohelp) { char *szCR2; szCR2=(char*)malloc(sK0[1]); safe_strncpy(szCR2,(char*)sK1[1],sK0[1]); dpi(szCR2,2); RelpaceCr(szCR2); log_printf(ds_Console, "%s\n" "%s\n" "\n" "Usage: wastesrv [-p <profile>] [-L] [-i] [-P <PID file>| [-d <logfile>]\n" "\t -L print license\n" "\t -p profile to use (default)\n" "\t -i interactive mode\n" "\t -P PID file to write PID in\n" "\t -d daemon mode (on *nix this will put wastesrv in the background)\n" "\n" "\twastesrv.ini must to be present on Windows\n" "\tthe config is default.pr0 to default.pr4\n", g_nameverstr, szCR2 ); memset(szCR2,0,sK0[1]);free(szCR2); return 1; } } if (daemonise) { assert(logpath); log_printf(ds_Console,"Forking DAEMON!"); log_UpdatePath(logpath, true); #ifndef _WIN32 daemon(1,0); #endif log_printf(ds_Console,"DAEMON!"); } if (!profile) profile = "default"; // TODO: gvdl should take a directory argument SetProgramDirectory(argv[0]); installsighandler(); log_printf(ds_Console,"%s starting up...%s.pr0",g_nameverstr, profile); MYSRAND(); if (!g_exit) //emergency break! { strcat(g_config_prefix, profile); #ifdef _WIN32 WSADATA wsaData; if (WSAStartup(MAKEWORD(2, 0), &wsaData)) { memset(&g_key,0,sizeof(g_key)); MessageBox(NULL,"Error initializing Winsock\n",APP_NAME " Error",0); return 1; } #endif UnifiedReadConfig(); InitialLoadDb(); PrepareDownloadDirectory(); if (!g_key.bits) { reloadKey( g_config->ReadInt(CONFIG_storepass,CONFIG_storepass_DEFAULT), (char *) g_config->ReadString(CONFIG_keypass,CONFIG_keypass_DEFAULT)); }; InitializeNetworkparts(); //main_AddNodes(); LoadNetQ(); // run loop while (!g_exit) { DoMainLoop(); Sleep(33); }; // exit log_printf(ds_Console,"cleaning up"); SaveDbToDisk(); delete g_listen; delete g_dns; if (g_newdatabase != g_database) delete g_newdatabase; delete g_database; }; SaveNetQ(); int x; for (x = 0; x < g_recvs.GetSize(); x ++) delete g_recvs.Get(x); for (x = 0; x < g_sends.GetSize(); x ++) delete g_sends.Get(x); for (x = 0; x < g_new_net.GetSize(); x ++) delete g_new_net.Get(x); for (x = 0; x < g_uploads.GetSize(); x ++) free(g_uploads.Get(x)); if (g_aclist) free(g_aclist); KillPkList(); delete g_mql; delete g_config; memset(&g_key,0,sizeof(g_key)); #ifdef _WIN32 WSACleanup(); #endif log_UpdatePath(NULL); return 0; }