/**************************************************************************** * main: ****************************************************************************/ int main( int argc, char **argv ) { x264_param_t param; cli_opt_t opt; int ret; #ifdef PTW32_STATIC_LIB pthread_win32_process_attach_np(); pthread_win32_thread_attach_np(); #endif #ifdef _WIN32 _setmode(_fileno(stdin), _O_BINARY); _setmode(_fileno(stdout), _O_BINARY); #endif x264_param_default( ¶m ); /* Parse command line */ if( Parse( argc, argv, ¶m, &opt ) < 0 ) return -1; /* Control-C handler */ signal( SIGINT, SigIntHandler ); ret = Encode( ¶m, &opt ); #ifdef PTW32_STATIC_LIB pthread_win32_thread_detach_np(); pthread_win32_process_detach_np(); #endif return ret; }
value external_exit (void) { /* Revert console system menu */ #if defined(__MINGW32__) if (myHWND != NULL) { HMENU hmenu = GetSystemMenu(myHWND, FALSE); MENUITEMINFO CloseItem; CloseItem.cbSize = sizeof(MENUITEMINFO); CloseItem.fMask = MIIM_ID; CloseItem.wID = SC_CLOSE; SetMenuItemInfo(hmenu, SC_MINIMIZE+1, FALSE, &CloseItem); EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_ENABLED); DrawMenuBar(myHWND); } #endif /* defined(__MINGW32__) */ #if defined(HAVE_PTHREAD) && defined(PTW32_STATIC_LIB) pthread_win32_process_detach_np(); #endif #if defined(HAVE_CRYPTOPP) /* crypto_exit(); */ #endif return Val_unit; }
BOOL WINAPI DllMain(HINSTANCE hinst_dll, DWORD reason, LPVOID reserved) { switch (reason) { case DLL_PROCESS_ATTACH: timeBeginPeriod(1); #ifdef PTW32_STATIC_LIB pthread_win32_process_attach_np(); #endif break; case DLL_PROCESS_DETACH: timeEndPeriod(1); #ifdef PTW32_STATIC_LIB pthread_win32_process_detach_np(); #endif break; case DLL_THREAD_ATTACH: #ifdef PTW32_STATIC_LIB pthread_win32_thread_attach_np(); #endif break; case DLL_THREAD_DETACH: #ifdef PTW32_STATIC_LIB pthread_win32_thread_detach_np(); #endif break; } UNUSED_PARAMETER(hinst_dll); UNUSED_PARAMETER(reserved); return true; }
/***************************************************************************** * CloseEncoder: x264 encoder destruction *****************************************************************************/ static void Close( vlc_object_t *p_this ) { encoder_t *p_enc = (encoder_t *)p_this; encoder_sys_t *p_sys = p_enc->p_sys; free( p_sys->psz_stat_name ); if( p_sys->h ) x264_encoder_close( p_sys->h ); #ifdef PTW32_STATIC_LIB vlc_value_t lock, count; var_Get( p_enc->p_libvlc, "pthread_win32_mutex", &lock ); vlc_mutex_lock( lock.p_address ); var_Get( p_enc->p_libvlc, "pthread_win32_count", &count ); count.i_int--; var_Set( p_enc->p_libvlc, "pthread_win32_count", count ); if( count.i_int == 0 ) { pthread_win32_thread_detach_np(); pthread_win32_process_detach_np(); msg_Dbg( p_enc, "pthread-win32 deinitialized" ); } vlc_mutex_unlock( lock.p_address ); #endif free( p_sys->p_buffer ); free( p_sys ); }
/* Callback for our DLL so we can initialize pthread */ BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) { #if PTW32_STATIC_LIB switch( fdwReason ) { case DLL_PROCESS_ATTACH: pthread_win32_process_attach_np(); case DLL_THREAD_ATTACH: pthread_win32_thread_attach_np(); break; case DLL_THREAD_DETACH: pthread_win32_thread_detach_np(); break; case DLL_PROCESS_DETACH: pthread_win32_thread_detach_np(); pthread_win32_process_detach_np(); break; } #endif return TRUE; }
int main( int _argc, char * * _argv ) { if( _argc < 3 ) { fprintf( stderr, "not enough arguments\n" ); return -1; } #ifdef LMMS_BUILD_WIN32 // (non-portable) initialization of statically linked pthread library pthread_win32_process_attach_np(); pthread_win32_thread_attach_np(); #endif RemoteZynAddSubFx * remoteZASF = new RemoteZynAddSubFx( atoi( _argv[1] ), atoi( _argv[2] ) ); remoteZASF->run(); delete remoteZASF; #ifdef LMMS_BUILD_WIN32 pthread_win32_thread_detach_np(); pthread_win32_process_detach_np(); #endif return 0; }
BOOL APIENTRY DllMain(HMODULE hm, DWORD why, LPVOID rsrv) { WSADATA wsa; switch (why) { case DLL_PROCESS_ATTACH: if(WSAStartup(MAKEWORD(2,2), &wsa)) return FALSE; fix_paths(); return pthread_win32_process_attach_np(); break; case DLL_THREAD_ATTACH: return pthread_win32_thread_attach_np (); break; case DLL_THREAD_DETACH: return pthread_win32_thread_detach_np (); break; case DLL_PROCESS_DETACH: WSACleanup(); pthread_win32_thread_detach_np (); return pthread_win32_process_detach_np (); break; } }
/* * Dear c++: Please don't mangle this name. -thanks */ extern "C" #endif /* __cplusplus */ BOOL WINAPI DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved) { BOOL result = PTW32_TRUE; switch (fdwReason) { case DLL_PROCESS_ATTACH: result = pthread_win32_process_attach_np (); break; case DLL_THREAD_ATTACH: /* * A thread is being created */ result = pthread_win32_thread_attach_np (); break; case DLL_THREAD_DETACH: /* * A thread is exiting cleanly */ result = pthread_win32_thread_detach_np (); break; case DLL_PROCESS_DETACH: (void) pthread_win32_thread_detach_np (); result = pthread_win32_process_detach_np (); break; } return (result); } /* DllMain */
static void x264_threading_destroy( void ) { #if PTW32_STATIC_LIB pthread_win32_thread_detach_np(); pthread_win32_process_detach_np(); #else x264_win32_threading_destroy(); #endif }
threadbase::~threadbase() { INSTANCES--; #ifndef USEOPENTH if (INSTANCES==1) pthread_mutex_destroy(&iomutex); #ifdef PTW32_STATIC_LIB if (INSTANCES==0) pthread_win32_process_detach_np(); #endif #endif }
threadpool::~threadpool() { /* We previously sent the termination message to all of the sub-threads here. * However, their terminating caused wacky problems with the malloc library. * So we just leave them floating around now. Doesn't matter much, because * the main process will die soon enough. */ kill_all_workers(); /* Release our resources */ pthread_cond_destroy(&TOMAIN); pthread_cond_destroy(&TOWORKER); #ifdef WIN32 pthread_win32_process_detach_np(); pthread_win32_thread_detach_np(); #endif }
//FILE* ff ; int main_bak( int argc, char **argv ) { x264_param_t param; cli_opt_t opt; int ret; //ff = fopen("ff_org.264", "wb"); initDebugLog("debug_org.log"); DEBUG_LOG(INF, "main begin"); #ifdef PTW32_STATIC_LIB pthread_win32_process_attach_np(); pthread_win32_thread_attach_np(); #endif #ifdef _WIN32 _setmode(_fileno(stdin), _O_BINARY); _setmode(_fileno(stdout), _O_BINARY); #endif /* 初始化输入参数结构体,设置为默认值 */ x264_param_default( ¶m ); /* 解析命令行,设置param(包括函数指针),并保存到opt的文件中。打开输出的文件.Parse command line */ if( Parse( argc, argv, ¶m, &opt ) < 0 ) return -1; /* 是否响应Ctrl+C终端。Control-C handler */ signal( SIGINT, SigIntHandler ); /* 编码主控函数,编码输入输出文件分别是opt中的hin和hout */ ret = Encode( ¶m, &opt ); #ifdef PTW32_STATIC_LIB pthread_win32_thread_detach_np(); pthread_win32_process_detach_np(); #endif DEBUG_LOG(INF, "main end"); return ret; }
int main(int argc, char * argv[]) { /* * This should always succeed unless the system has no * resources (memory) left. */ pthread_t self; #if defined(PTW32_STATIC_LIB) && !(defined(_MSC_VER) || defined(__MINGW32__)) pthread_win32_process_attach_np(); #endif self = pthread_self(); assert(self.p != NULL); #if defined(PTW32_STATIC_LIB) && !(defined(_MSC_VER) || defined(__MINGW32__)) pthread_win32_process_detach_np(); #endif return 0; }
/** The AGC main function from here the Command Line is parsed, the Simulator is initialized and subsequently executed. */ int main (int argc, char *argv[]) { #ifdef PTW32_STATIC_LIB // You wouldn't need this if I had compiled pthreads_w32 as a DLL. pthread_win32_process_attach_np (); #endif /* Delclare Options and parse the command line */ Options_t *Options = CliParseArguments(argc, argv); /* Initialize the Simulator and debugger if enabled * if the initialization fails or Options is NULL then the simulator will * return a non zero value and subsequently bail and exit the program */ if (SimInitialize(Options) == SIM_E_OK) SimExecute(); #ifdef PTW32_STATIC_LIB // You wouldn't need this if I had compiled pthreads_w32 as a DLL. pthread_win32_process_detach_np (); #endif return (0); }
BOOL WINAPI DllMain(HINSTANCE hinst_dll, DWORD reason, LPVOID reserved) { switch (reason) { case DLL_PROCESS_ATTACH: pthread_win32_process_attach_np(); break; case DLL_PROCESS_DETACH: pthread_win32_process_detach_np(); break; case DLL_THREAD_ATTACH: pthread_win32_thread_attach_np(); break; case DLL_THREAD_DETACH: pthread_win32_thread_detach_np(); break; } return true; }
threadpool::~threadpool() { /* We previously sent the termination message to all of the sub-threads here. * However, their terminating caused wacky problems with the malloc library. * So we just leave them floating around now. Doesn't matter much, because * the main process will die soon enough. */ #if 0 for(int i=0;i<num_threads;i++){ this->schedule_work(0); } #endif /* Release our resources */ fs.close_all(); pthread_mutex_destroy(&M); pthread_cond_destroy(&TOMAIN); pthread_cond_destroy(&TOWORKER); #ifdef WIN32 pthread_win32_process_detach_np(); pthread_win32_thread_detach_np(); #endif }
int main(int argc, char* argv[]) { setlinebuf(stdout); #ifdef _WIN32 #ifdef SC_WIN32_STATIC_PTHREADS // initialize statically linked pthreads library pthread_win32_process_attach_np(); #endif // initialize winsock WSAData wsaData; int nCode; if ((nCode = WSAStartup(MAKEWORD(1, 1), &wsaData)) != 0) { scprintf( "WSAStartup() failed with error code %d.\n", nCode ); return 1; } #endif int udpPortNum = -1; int tcpPortNum = -1; WorldOptions options = kDefaultWorldOptions; for (int i=1; i<argc;) { if (argv[i][0] != '-' || argv[i][1] == 0 || strchr("utaioczblndpmwZrNSDIOMHvRUhPL", argv[i][1]) == 0) { scprintf("ERROR: Invalid option %s\n", argv[i]); Usage(); } int j = i; switch (argv[j][1]) { case 'u' : checkNumArgs(2); udpPortNum = atoi(argv[j+1]); break; case 't' : checkNumArgs(2); tcpPortNum = atoi(argv[j+1]); break; case 'a' : checkNumArgs(2); options.mNumAudioBusChannels = atoi(argv[j+1]); break; case 'i' : checkNumArgs(2); options.mNumInputBusChannels = atoi(argv[j+1]); break; case 'o' : checkNumArgs(2); options.mNumOutputBusChannels = atoi(argv[j+1]); break; case 'c' : checkNumArgs(2); options.mNumControlBusChannels = atoi(argv[j+1]); break; case 'z' : checkNumArgs(2); options.mBufLength = NEXTPOWEROFTWO(atoi(argv[j+1])); break; case 'Z' : checkNumArgs(2); options.mPreferredHardwareBufferFrameSize = NEXTPOWEROFTWO(atoi(argv[j+1])); break; case 'b' : checkNumArgs(2); options.mNumBuffers = NEXTPOWEROFTWO(atoi(argv[j+1])); break; case 'l' : checkNumArgs(2); options.mMaxLogins = NEXTPOWEROFTWO(atoi(argv[j+1])); break; case 'n' : checkNumArgs(2); options.mMaxNodes = NEXTPOWEROFTWO(atoi(argv[j+1])); break; case 'd' : checkNumArgs(2); options.mMaxGraphDefs = NEXTPOWEROFTWO(atoi(argv[j+1])); break; case 'p' : checkNumArgs(2); options.mPassword = argv[j+1]; break; case 'm' : checkNumArgs(2); options.mRealTimeMemorySize = atoi(argv[j+1]); break; case 'w' : checkNumArgs(2); options.mMaxWireBufs = atoi(argv[j+1]); break; case 'r' : checkNumArgs(2); options.mNumRGens = atoi(argv[j+1]); break; case 'S' : checkNumArgs(2); options.mPreferredSampleRate = (uint32)atof(argv[j+1]); break; case 'D' : checkNumArgs(2); options.mLoadGraphDefs = atoi(argv[j+1]); break; case 'N' : #ifdef NO_LIBSNDFILE scprintf("NRT mode not supported: scsynth compiled without libsndfile\n"); exit(0); #endif // -N cmd-filename input-filename output-filename sample-rate header-format sample-format checkNumArgs(7); options.mRealTime = false; options.mNonRealTimeCmdFilename = strcmp(argv[j+1], "_") ? argv[j+1] : 0; options.mNonRealTimeInputFilename = strcmp(argv[j+2], "_") ? argv[j+2] : 0; options.mNonRealTimeOutputFilename = argv[j+3]; options.mPreferredSampleRate = (uint32)atof(argv[j+4]); options.mNonRealTimeOutputHeaderFormat = argv[j+5]; options.mNonRealTimeOutputSampleFormat = argv[j+6]; break; #ifdef __APPLE__ case 'I' : checkNumArgs(2); options.mInputStreamsEnabled = argv[j+1]; break; case 'O' : checkNumArgs(2); options.mOutputStreamsEnabled = argv[j+1]; break; case 'M': #endif case 'H' : checkNumArgs(2); options.mInDeviceName = argv[j+1]; #ifdef __APPLE__ if (i+1>argc || argv[j+2][0]=='-') { options.mOutDeviceName = options.mInDeviceName; } else { // If there's a second argument then the user wants separate I/O devices options.mOutDeviceName = argv[j+2]; ++i; } #else options.mOutDeviceName = options.mInDeviceName; // Non-Mac platforms always use same device #endif break; case 'L' : checkNumArgs(1); #if (_POSIX_MEMLOCK - 0) >= 200112L options.mMemoryLocking = true; #else options.mMemoryLocking = false; #endif break; case 'v' : checkNumArgs(2); options.mVerbosity = atoi(argv[j+1]); break; case 'R' : checkNumArgs(2); options.mRendezvous = atoi(argv[j+1]) > 0; break; case 'U' : checkNumArgs(2); options.mUGensPluginPath = argv[j+1]; break; case 'P' : checkNumArgs(2); options.mRestrictedPath = argv[j+1]; break; case 'h': default: Usage(); } } if (udpPortNum == -1 && tcpPortNum == -1 && options.mRealTime) { scprintf("ERROR: There must be a -u and/or a -t options, or -N for nonrealtime.\n"); Usage(); } if (options.mNumInputBusChannels + options.mNumOutputBusChannels > options.mNumAudioBusChannels) { scprintf("ERROR: number of audio bus channels < inputs + outputs.\n"); Usage(); } struct World *world = World_New(&options); if (!world) return 1; if (!options.mRealTime) { #ifdef NO_LIBSNDFILE return 1; #else int exitCode = 0; try { World_NonRealTimeSynthesis(world, &options); } catch (std::exception& exc) { scprintf("%s\n", exc.what()); exitCode = 1; } return exitCode; #endif } if (udpPortNum >= 0) { if (!World_OpenUDP(world, udpPortNum)) { World_Cleanup(world); return 1; } } if (tcpPortNum >= 0) { if (!World_OpenTCP(world, tcpPortNum, options.mMaxLogins, 8)) { World_Cleanup(world); return 1; } } if(options.mVerbosity >=0){ #ifdef NDEBUG scprintf("SuperCollider 3 server ready.\n"); #else scprintf("SuperCollider 3 server ready (debug build).\n"); #endif } fflush(stdout); World_WaitForQuit(world); #ifdef _WIN32 // clean up winsock WSACleanup(); #ifdef SC_WIN32_STATIC_PTHREADS // clean up statically linked pthreads pthread_win32_process_detach_np(); #endif // SC_WIN32_STATIC_PTHREADS #endif // _WIN32 return 0; }
int main(int argc, char **argv) { const struct optstruct *opt; #ifndef C_WINDOWS struct passwd *user = NULL; #endif time_t currtime; const char *dbdir, *cfgfile; char *pua_cats = NULL, *pt; int ret, tcpsock = 0, localsock = 0, i, min_port, max_port; unsigned int sigs = 0; int lsockets[2], nlsockets = 0; unsigned int dboptions = 0; #ifdef C_LINUX struct stat sb; #endif #ifdef C_WINDOWS if(!pthread_win32_process_attach_np()) { mprintf("!Can't start the win32 pthreads layer\n"); return 1; } #endif if((opts = optparse(NULL, argc, argv, 1, OPT_CLAMD, 0, NULL)) == NULL) { mprintf("!Can't parse command line options\n"); return 1; } if(optget(opts, "help")->enabled) { help(); optfree(opts); return 0; } if(optget(opts, "debug")->enabled) { #if defined(C_LINUX) /* [email protected]: create a dump if needed */ struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = RLIM_INFINITY; if(setrlimit(RLIMIT_CORE, &rlim) < 0) perror("setrlimit"); #endif debug_mode = 1; } /* parse the config file */ cfgfile = optget(opts, "config-file")->strarg; pt = strdup(cfgfile); if((opts = optparse(cfgfile, 0, NULL, 1, OPT_CLAMD, 0, opts)) == NULL) { fprintf(stderr, "ERROR: Can't open/parse the config file %s\n", pt); free(pt); return 1; } free(pt); if(optget(opts, "version")->enabled) { print_version(optget(opts, "DatabaseDirectory")->strarg); optfree(opts); return 0; } umask(0); /* drop privileges */ #if (!defined(C_OS2)) && (!defined(C_WINDOWS)) if(geteuid() == 0 && (opt = optget(opts, "User"))->enabled) { if((user = getpwnam(opt->strarg)) == NULL) { fprintf(stderr, "ERROR: Can't get information about user %s.\n", opt->strarg); optfree(opts); return 1; } if(optget(opts, "AllowSupplementaryGroups")->enabled) { #ifdef HAVE_INITGROUPS if(initgroups(opt->strarg, user->pw_gid)) { fprintf(stderr, "ERROR: initgroups() failed.\n"); optfree(opts); return 1; } #else mprintf("!AllowSupplementaryGroups: initgroups() is not available, please disable AllowSupplementaryGroups in %s\n", cfgfile); optfree(opts); return 1; #endif } else { #ifdef HAVE_SETGROUPS if(setgroups(1, &user->pw_gid)) { fprintf(stderr, "ERROR: setgroups() failed.\n"); optfree(opts); return 1; } #endif } if(setgid(user->pw_gid)) { fprintf(stderr, "ERROR: setgid(%d) failed.\n", (int) user->pw_gid); optfree(opts); return 1; } if(setuid(user->pw_uid)) { fprintf(stderr, "ERROR: setuid(%d) failed.\n", (int) user->pw_uid); optfree(opts); return 1; } } #endif /* initialize logger */ logg_lock = !optget(opts, "LogFileUnlock")->enabled; logg_time = optget(opts, "LogTime")->enabled; logok = optget(opts, "LogClean")->enabled; logg_size = optget(opts, "LogFileMaxSize")->numarg; logg_verbose = mprintf_verbose = optget(opts, "LogVerbose")->enabled; mprintf_send_timeout = optget(opts, "SendBufTimeout")->numarg; do { /* logger initialized */ if((opt = optget(opts, "LogFile"))->enabled) { char timestr[32]; logg_file = opt->strarg; if(strlen(logg_file) < 2 || (logg_file[0] != '/' && logg_file[0] != '\\' && logg_file[1] != ':')) { fprintf(stderr, "ERROR: LogFile requires full path.\n"); ret = 1; break; } time(&currtime); if(logg("#+++ Started at %s", cli_ctime(&currtime, timestr, sizeof(timestr)))) { fprintf(stderr, "ERROR: Can't initialize the internal logger\n"); ret = 1; break; } } else logg_file = NULL; if((ret = cl_init(CL_INIT_DEFAULT))) { logg("!Can't initialize libclamav: %s\n", cl_strerror(ret)); ret = 1; break; } if(optget(opts, "Debug")->enabled) /* enable debug messages in libclamav */ { cl_debug(); logg_verbose = 2; } #if defined(USE_SYSLOG) && !defined(C_AIX) if(optget(opts, "LogSyslog")->enabled) { int fac = LOG_LOCAL6; opt = optget(opts, "LogFacility"); if((fac = logg_facility(opt->strarg)) == -1) { logg("!LogFacility: %s: No such facility.\n", opt->strarg); ret = 1; break; } openlog("clamd", LOG_PID, fac); logg_syslog = 1; } #endif #ifdef C_LINUX procdev = 0; if(stat("/proc", &sb) != -1 && !sb.st_size) procdev = sb.st_dev; #endif /* check socket type */ if(optget(opts, "TCPSocket")->enabled) tcpsock = 1; if(optget(opts, "LocalSocket")->enabled) localsock = 1; if(!tcpsock && !localsock) { logg("!Please define server type (local and/or TCP).\n"); ret = 1; break; } logg("#clamd daemon %s (OS: "TARGET_OS_TYPE", ARCH: "TARGET_ARCH_TYPE", CPU: "TARGET_CPU_TYPE")\n", get_version()); #ifndef C_WINDOWS if(user) logg("#Running as user %s (UID %u, GID %u)\n", user->pw_name, user->pw_uid, user->pw_gid); #endif if(logg_size) logg("#Log file size limited to %d bytes.\n", logg_size); else logg("#Log file size limit disabled.\n"); min_port = optget(opts, "StreamMinPort")->numarg; max_port = optget(opts, "StreamMaxPort")->numarg; if (min_port < 1024 || min_port > max_port || max_port > 65535) { logg("!Invalid StreamMinPort/StreamMaxPort: %d, %d\n", min_port, max_port); ret = 1; break; } if(!(engine = cl_engine_new())) { logg("!Can't initialize antivirus engine\n"); ret = 1; break; } /* load the database(s) */ dbdir = optget(opts, "DatabaseDirectory")->strarg; logg("#Reading databases from %s\n", dbdir); if(optget(opts, "DetectPUA")->enabled) { dboptions |= CL_DB_PUA; if((opt = optget(opts, "ExcludePUA"))->enabled) { dboptions |= CL_DB_PUA_EXCLUDE; i = 0; logg("#Excluded PUA categories:"); while(opt) { if(!(pua_cats = realloc(pua_cats, i + strlen(opt->strarg) + 3))) { logg("!Can't allocate memory for pua_cats\n"); cl_engine_free(engine); ret = 1; break; } logg("# %s", opt->strarg); sprintf(pua_cats + i, ".%s", opt->strarg); i += strlen(opt->strarg) + 1; pua_cats[i] = 0; opt = opt->nextarg; } if (ret) break; logg("#\n"); pua_cats[i] = '.'; pua_cats[i + 1] = 0; } if((opt = optget(opts, "IncludePUA"))->enabled) { if(pua_cats) { logg("!ExcludePUA and IncludePUA cannot be used at the same time\n"); free(pua_cats); ret = 1; break; } dboptions |= CL_DB_PUA_INCLUDE; i = 0; logg("#Included PUA categories:"); while(opt) { if(!(pua_cats = realloc(pua_cats, i + strlen(opt->strarg) + 3))) { logg("!Can't allocate memory for pua_cats\n"); ret = 1; break; } logg("# %s", opt->strarg); sprintf(pua_cats + i, ".%s", opt->strarg); i += strlen(opt->strarg) + 1; pua_cats[i] = 0; opt = opt->nextarg; } if (ret) break; logg("#\n"); pua_cats[i] = '.'; pua_cats[i + 1] = 0; } if(pua_cats) { if((ret = cl_engine_set_str(engine, CL_ENGINE_PUA_CATEGORIES, pua_cats))) { logg("!cli_engine_set_str(CL_ENGINE_PUA_CATEGORIES) failed: %s\n", cl_strerror(ret)); free(pua_cats); ret = 1; break; } free(pua_cats); } } else { logg("#Not loading PUA signatures.\n"); } /* set the temporary dir */ if((opt = optget(opts, "TemporaryDirectory"))->enabled) { if((ret = cl_engine_set_str(engine, CL_ENGINE_TMPDIR, opt->strarg))) { logg("!cli_engine_set_str(CL_ENGINE_TMPDIR) failed: %s\n", cl_strerror(ret)); ret = 1; break; } } if(optget(opts, "LeaveTemporaryFiles")->enabled) cl_engine_set_num(engine, CL_ENGINE_KEEPTMP, 1); if(optget(opts, "PhishingSignatures")->enabled) dboptions |= CL_DB_PHISHING; else logg("#Not loading phishing signatures.\n"); if(optget(opts,"PhishingScanURLs")->enabled) dboptions |= CL_DB_PHISHING_URLS; else logg("#Disabling URL based phishing detection.\n"); if(optget(opts,"DevACOnly")->enabled) { logg("#Only using the A-C matcher.\n"); cl_engine_set_num(engine, CL_ENGINE_AC_ONLY, 1); } if((opt = optget(opts, "DevACDepth"))->enabled) { cl_engine_set_num(engine, CL_ENGINE_AC_MAXDEPTH, opt->numarg); logg("#Max A-C depth set to %u\n", (unsigned int) opt->numarg); } if((ret = cl_load(dbdir, engine, &sigs, dboptions))) { logg("!%s\n", cl_strerror(ret)); ret = 1; break; } logg("#Loaded %u signatures.\n", sigs); if((ret = cl_engine_compile(engine)) != 0) { logg("!Database initialization error: %s\n", cl_strerror(ret)); ret = 1; break; } if(tcpsock) { #ifdef C_WINDOWS WSADATA wsaData; if(WSAStartup(MAKEWORD(2,2), &wsaData) != NO_ERROR) { logg("!Error at WSAStartup(): %d\n", WSAGetLastError()); ret = 1; break; } #endif if ((lsockets[nlsockets] = tcpserver(opts)) == -1) { ret = 1; break; } nlsockets++; } if(localsock) { if ((lsockets[nlsockets] = localserver(opts)) == -1) { ret = 1; break; } nlsockets++; } /* fork into background */ if(!optget(opts, "Foreground")->enabled) { #ifdef C_BSD /* workaround for OpenBSD bug, see https://wwws.clamav.net/bugzilla/show_bug.cgi?id=885 */ for(ret=0;ret<nlsockets;ret++) { fcntl(lsockets[ret], F_SETFL, fcntl(lsockets[ret], F_GETFL) | O_NONBLOCK); } #endif if(daemonize() == -1) { logg("!daemonize() failed\n"); ret = 1; break; } #ifdef C_BSD for(ret=0;ret<nlsockets;ret++) { fcntl(lsockets[ret], F_SETFL, fcntl(lsockets[ret], F_GETFL) & ~O_NONBLOCK); } #endif if(!debug_mode) if(chdir("/") == -1) logg("^Can't change current working directory to root\n"); } else foreground = 1; ret = recvloop_th(lsockets, nlsockets, engine, dboptions, opts); } while (0); logg("*Closing the main socket%s.\n", (nlsockets > 1) ? "s" : ""); for (i = 0; i < nlsockets; i++) { closesocket(lsockets[i]); } #ifndef C_OS2 if(nlsockets && localsock) { opt = optget(opts, "LocalSocket"); if(unlink(opt->strarg) == -1) logg("!Can't unlink the socket file %s\n", opt->strarg); else logg("Socket file removed.\n"); } #endif #ifdef C_WINDOWS if(tcpsock) WSACleanup(); if(!pthread_win32_process_detach_np()) { logg("!Can't stop the win32 pthreads layer\n"); logg_close(); optfree(opts); return 1; } #endif logg_close(); optfree(opts); return ret; }
static void __attribute__((destructor)) x42_fini() { pthread_win32_process_detach_np(); }
int main(int argc, char **argv) { int ds, dms, ret; double mb; struct timeval t1, t2; #ifndef C_WINDOWS struct timezone tz; sigset_t sigset; #endif struct optstruct *opt; const char *pt; #if defined(C_WINDOWS) && defined(CL_THREAD_SAFE) if(!pthread_win32_process_attach_np()) { mprintf("!Can't start the win32 pthreads layer\n"); return 72; } #endif #if !defined(C_WINDOWS) && !defined(C_BEOS) sigemptyset(&sigset); sigaddset(&sigset, SIGXFSZ); sigprocmask(SIG_SETMASK, &sigset, NULL); #endif opt = opt_parse(argc, argv, clamscan_shortopt, clamscan_longopt, NULL, clamscan_deprecated); if(!opt) { mprintf("!Can't parse the command line\n"); return 40; } if(opt_check(opt, "verbose")) { mprintf_verbose = 1; logg_verbose = 1; } if(opt_check(opt, "quiet")) mprintf_quiet = 1; if(opt_check(opt, "stdout")) mprintf_stdout = 1; if(opt_check(opt, "debug")) { #if defined(C_LINUX) /* [email protected]: create a dump if needed */ struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = RLIM_INFINITY; if(setrlimit(RLIMIT_CORE, &rlim) < 0) perror("setrlimit"); #endif cl_debug(); /* enable debug messages */ } if(opt_check(opt, "version")) { print_version(opt_arg(opt, "database")); opt_free(opt); return 0; } if(opt_check(opt, "help")) { opt_free(opt); help(); return 0; } if(opt_check(opt, "recursive")) recursion = 1; if(opt_check(opt, "infected")) printinfected = 1; if(opt_check(opt, "bell")) bell = 1; if(opt_check(opt, "tempdir")) cl_settempdir(opt_arg(opt, "tempdir"), 0); if(opt_check(opt, "leave-temps")) cl_settempdir(NULL, 1); /* initialize logger */ if(opt_check(opt, "log")) { logg_file = opt_arg(opt, "log"); if(logg("#\n-------------------------------------------------------------------------------\n\n")) { mprintf("!Problem with internal logger.\n"); opt_free(opt); return 62; } } else logg_file = NULL; /* validate some numerical options */ if(opt_check(opt, "max-scansize")) { pt = opt_arg(opt, "max-scansize"); if(!strchr(pt, 'M') && !strchr(pt, 'm')) { if(!cli_isnumber(pt)) { logg("!--max-scansize requires a natural number\n"); opt_free(opt); return 40; } } } if(opt_check(opt, "max-filesize")) { pt = opt_arg(opt, "max-filesize"); if(!strchr(pt, 'M') && !strchr(pt, 'm')) { if(!cli_isnumber(pt)) { logg("!--max-filesize requires a natural number\n"); opt_free(opt); return 40; } } } if(opt_check(opt, "max-files")) { if(!cli_isnumber(opt_arg(opt, "max-files"))) { logg("!--max-files requires a natural number\n"); opt_free(opt); return 40; } } if(opt_check(opt, "max-recursion")) { if(!cli_isnumber(opt_arg(opt, "max-recursion"))) { logg("!--max-recursion requires a natural number\n"); opt_free(opt); return 40; } } if(opt_check(opt, "max-mail-recursion")) { if(!cli_isnumber(opt_arg(opt, "max-mail-recursion"))) { logg("!--max-mail-recursion requires a natural number\n"); opt_free(opt); return 40; } } if(opt_check(opt, "max-dir-recursion")) { if(!cli_isnumber(opt_arg(opt, "max-dir-recursion"))) { logg("!--max-dir-recursion requires a natural number\n"); opt_free(opt); return 40; } } if(opt_check(opt, "max-ratio")) { if(!cli_isnumber(opt_arg(opt, "max-ratio"))) { logg("!--max-ratio requires a natural number\n"); opt_free(opt); return 40; } } memset(&info, 0, sizeof(struct s_info)); #ifdef _WIN32 SetConsoleCtrlHandler((PHANDLER_ROUTINE) clamscan_ctrl_handler, TRUE); #endif #ifdef C_WINDOWS _set_fmode(_O_BINARY); #ifdef CL_DEBUG { _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); } #endif gettimeofday(&t1, NULL); #else gettimeofday(&t1, &tz); #endif ret = scanmanager(opt); if(!opt_check(opt, "disable-summary") && !opt_check(opt, "no-summary")) { #ifdef C_WINDOWS gettimeofday(&t2, NULL); #else gettimeofday(&t2, &tz); #endif ds = t2.tv_sec - t1.tv_sec; dms = t2.tv_usec - t1.tv_usec; ds -= (dms < 0) ? (1):(0); dms += (dms < 0) ? (1000000):(0); logg("\n----------- SCAN SUMMARY -----------\n"); logg("Known viruses: %u\n", info.sigs); logg("Engine version: %s\n", get_version()); logg("Scanned directories: %u\n", info.dirs); logg("Scanned files: %u\n", info.files); logg("Infected files: %u\n", info.ifiles); if(info.notremoved) { logg("Not removed: %u\n", info.notremoved); } if(info.notmoved) { logg("Not %s: %u\n", opt_check(opt, "copy") ? "moved" : "copied", info.notmoved); } mb = info.blocks * (CL_COUNT_PRECISION / 1024) / 1024.0; logg("Data scanned: %2.2lf MB\n", mb); logg("Time: %u.%3.3u sec (%u m %u s)\n", ds, dms/1000, ds/60, ds%60); } opt_free(opt); #if defined(C_WINDOWS) && defined(CL_THREAD_SAFE) if(!pthread_win32_process_detach_np()) { logg("!Can't stop the win32 pthreads layer\n"); return 72; } #endif return ret; }
static void detach_ptw32(void) { pthread_win32_thread_detach_np(); pthread_win32_process_detach_np(); }
int main(int argc, char **argv) { int ret; atexit(&exit_handler); TEST_WRAPPER(test_sequence2); pthread_win32_process_detach_np(); // ptw32_processTerminate(); pthread_win32_process_attach_np(); // ptw32_processInitialize(); /* fails when run down below; does not fail when run at start of run - turns out to be due to the thread reuse logic kicking in and the test code not anticipating that --> introduction of test sequence2.c above to showcase the fix for this, including augmentation of pthread_win32_process_attach_np() to prevent crashes. */ TEST_WRAPPER(test_reuse1); pthread_win32_process_detach_np(); // ptw32_processTerminate(); pthread_win32_process_attach_np(); // ptw32_processInitialize(); TEST_WRAPPER(test_sequence1); /* fails when run down below; does not fail when run at start of run - same issue as test reuse1 */ pthread_win32_process_detach_np(); // ptw32_processTerminate(); pthread_win32_process_attach_np(); // ptw32_processInitialize(); TEST_WRAPPER(test_cancel7); TEST_WRAPPER(test_cancel8); TEST_WRAPPER(test_cleanup1); TEST_WRAPPER(test_condvar7); TEST_WRAPPER(test_condvar9); TEST_WRAPPER(test_exception1); TEST_WRAPPER(test_loadfree); TEST_WRAPPER(test_sequence1); TEST_WRAPPER(test_barrier1); TEST_WRAPPER(test_barrier2); TEST_WRAPPER(test_barrier3); TEST_WRAPPER(test_barrier4); TEST_WRAPPER(test_barrier5); TEST_WRAPPER(test_barrier6); TEST_WRAPPER(test_benchtest1); TEST_WRAPPER(test_benchtest2); TEST_WRAPPER(test_benchtest3); TEST_WRAPPER(test_benchtest4); TEST_WRAPPER(test_benchtest5); TEST_WRAPPER(test_cancel1); TEST_WRAPPER(test_cancel2); TEST_WRAPPER(test_cancel3); TEST_WRAPPER(test_cancel4); TEST_WRAPPER(test_cancel5); TEST_WRAPPER(test_cancel6a); TEST_WRAPPER(test_cancel6d); // TEST_WRAPPER(test_cancel7); // TEST_WRAPPER(test_cancel8); TEST_WRAPPER(test_cancel9); TEST_WRAPPER(test_cleanup0); // TEST_WRAPPER(test_cleanup1); TEST_WRAPPER(test_cleanup2); TEST_WRAPPER(test_cleanup3); TEST_WRAPPER(test_condvar1); TEST_WRAPPER(test_condvar1_1); TEST_WRAPPER(test_condvar1_2); TEST_WRAPPER(test_condvar2); TEST_WRAPPER(test_condvar2_1); TEST_WRAPPER(test_condvar3); TEST_WRAPPER(test_condvar3_1); TEST_WRAPPER(test_condvar3_2); TEST_WRAPPER(test_condvar3_3); TEST_WRAPPER(test_condvar4); TEST_WRAPPER(test_condvar5); TEST_WRAPPER(test_condvar6); // TEST_WRAPPER(test_condvar7); TEST_WRAPPER(test_condvar8); // TEST_WRAPPER(test_condvar9); TEST_WRAPPER(test_context1); TEST_WRAPPER(test_count1); TEST_WRAPPER(test_create1); TEST_WRAPPER(test_create2); TEST_WRAPPER(test_create3); TEST_WRAPPER(test_delay1); TEST_WRAPPER(test_delay2); TEST_WRAPPER(test_detach1); TEST_WRAPPER(test_equal1); TEST_WRAPPER(test_errno1); // TEST_WRAPPER(test_exception1); TEST_WRAPPER(test_exception3); TEST_WRAPPER(test_exception3_0); TEST_WRAPPER(test_exit2); TEST_WRAPPER(test_exit3); TEST_WRAPPER(test_exit4); TEST_WRAPPER(test_exit5); TEST_WRAPPER(test_eyal1); TEST_WRAPPER(test_inherit1); TEST_WRAPPER(test_join0); TEST_WRAPPER(test_join1); TEST_WRAPPER(test_join2); TEST_WRAPPER(test_join3); TEST_WRAPPER(test_join4); TEST_WRAPPER(test_kill1); // TEST_WRAPPER(test_loadfree); TEST_WRAPPER(test_mutex1); TEST_WRAPPER(test_mutex1e); TEST_WRAPPER(test_mutex1n); TEST_WRAPPER(test_mutex1r); TEST_WRAPPER(test_mutex2); TEST_WRAPPER(test_mutex2e); TEST_WRAPPER(test_mutex2r); TEST_WRAPPER(test_mutex3); TEST_WRAPPER(test_mutex3e); TEST_WRAPPER(test_mutex3r); TEST_WRAPPER(test_mutex4); TEST_WRAPPER(test_mutex5); TEST_WRAPPER(test_mutex6); TEST_WRAPPER(test_mutex6e); TEST_WRAPPER(test_mutex6es); TEST_WRAPPER(test_mutex6n); TEST_WRAPPER(test_mutex6r); TEST_WRAPPER(test_mutex6rs); TEST_WRAPPER(test_mutex6s); TEST_WRAPPER(test_mutex7); TEST_WRAPPER(test_mutex7e); TEST_WRAPPER(test_mutex7n); TEST_WRAPPER(test_mutex7r); TEST_WRAPPER(test_mutex8); TEST_WRAPPER(test_mutex8e); TEST_WRAPPER(test_mutex8n); TEST_WRAPPER(test_mutex8r); TEST_WRAPPER(test_once1); TEST_WRAPPER(test_once2); TEST_WRAPPER(test_once3); TEST_WRAPPER(test_once4); TEST_WRAPPER_W_ARGV(test_openmp1); TEST_WRAPPER(test_priority1); TEST_WRAPPER(test_priority2); /* TEST_WRAPPER(test_reuse1); -- fails when run here; does not fail when run at start of run :-S */ TEST_WRAPPER(test_reuse2); TEST_WRAPPER(test_robust1); TEST_WRAPPER(test_robust2); TEST_WRAPPER(test_robust3); TEST_WRAPPER(test_robust4); TEST_WRAPPER(test_robust5); TEST_WRAPPER(test_rwlock1); TEST_WRAPPER(test_rwlock2); TEST_WRAPPER(test_rwlock2_t); TEST_WRAPPER(test_rwlock3); TEST_WRAPPER(test_rwlock3_t); TEST_WRAPPER(test_rwlock4); TEST_WRAPPER(test_rwlock4_t); TEST_WRAPPER(test_rwlock5); TEST_WRAPPER(test_rwlock5_t); TEST_WRAPPER(test_rwlock6); TEST_WRAPPER(test_rwlock6_t); TEST_WRAPPER(test_rwlock6_t2); TEST_WRAPPER(test_rwlock7); TEST_WRAPPER(test_rwlock8); TEST_WRAPPER(test_self1); TEST_WRAPPER(test_self2); TEST_WRAPPER(test_semaphore1); TEST_WRAPPER(test_semaphore2); TEST_WRAPPER(test_semaphore3); TEST_WRAPPER(test_semaphore4); TEST_WRAPPER(test_semaphore4t); TEST_WRAPPER(test_semaphore5); // TEST_WRAPPER(test_sequence1); TEST_WRAPPER(test_sizes); TEST_WRAPPER(test_spin1); TEST_WRAPPER(test_spin2); TEST_WRAPPER(test_spin3); TEST_WRAPPER(test_spin4); TEST_WRAPPER(test_stress1); TEST_WRAPPER(test_tryentercs); TEST_WRAPPER(test_tryentercs2); TEST_WRAPPER(test_tsd1); TEST_WRAPPER(test_tsd2); TEST_WRAPPER(test_valid1); TEST_WRAPPER(test_valid2); TEST_WRAPPER_W_ARGV(test_create3a); TEST_WRAPPER_W_ARGV(test_exception2); /* test_exit1 should be the VERY LAST test of the bunch as it will exit the application before it returns! */ TEST_WRAPPER(test_exit1); printf("Should never get here!\n"); return EXIT_FAILURE; }
int main(int argc, char* argv[]) { char *albumdir = 0, *musicfilename, *file_path = 0; int i, area_idx; sacd_reader_t *sacd_reader; #ifdef PTW32_STATIC_LIB pthread_win32_process_attach_np(); pthread_win32_thread_attach_np(); #endif init(); if (parse_options(argc, argv)) { setlocale(LC_ALL, ""); if (fwide(stdout, 1) < 0) { fprintf(stderr, "ERROR: Output not set to wide.\n"); } // default to 2 channel if (opts.two_channel == 0 && opts.multi_channel == 0) { opts.two_channel = 1; } sacd_reader = sacd_open(opts.input_device); if (sacd_reader) { handle = scarletbook_open(sacd_reader, 0); if (handle) { if (opts.print) { scarletbook_print(handle); } if (opts.output_dsf || opts.output_iso || opts.output_dsdiff || opts.output_dsdiff_em || opts.export_cue_sheet) { output = scarletbook_output_create(handle, handle_status_update_track_callback, handle_status_update_progress_callback, safe_fwprintf); // select the channel area area_idx = ((has_multi_channel(handle) && opts.multi_channel) || !has_two_channel(handle)) ? handle->mulch_area_idx : handle->twoch_area_idx; albumdir = (strlen(opts.output_file) > 0 ? strdup(opts.output_file) : get_album_dir(handle)); if (opts.output_iso) { uint32_t total_sectors = sacd_get_total_sectors(sacd_reader); #ifdef SECTOR_LIMIT #define FAT32_SECTOR_LIMIT 2090000 uint32_t sector_size = FAT32_SECTOR_LIMIT; uint32_t sector_offset = 0; if (total_sectors > FAT32_SECTOR_LIMIT) { musicfilename = (char *) malloc(512); file_path = make_filename(0, 0, albumdir, "iso"); for (i = 1; total_sectors != 0; i++) { sector_size = min(total_sectors, FAT32_SECTOR_LIMIT); snprintf(musicfilename, 512, "%s.%03d", file_path, i); scarletbook_output_enqueue_raw_sectors(output, sector_offset, sector_size, musicfilename, "iso"); sector_offset += sector_size; total_sectors -= sector_size; } free(musicfilename); } else #endif { get_unique_filename(&albumdir, "iso"); file_path = make_filename(0, 0, albumdir, "iso"); scarletbook_output_enqueue_raw_sectors(output, 0, total_sectors, file_path, "iso"); } } else if (opts.output_dsdiff_em) { get_unique_filename(&albumdir, "dff"); file_path = make_filename(0, 0, albumdir, "dff"); scarletbook_output_enqueue_track(output, area_idx, 0, file_path, "dsdiff_edit_master", (opts.convert_dst ? 1 : handle->area[area_idx].area_toc->frame_format != FRAME_FORMAT_DST)); } else if (opts.output_dsf || opts.output_dsdiff) { // create the output folder get_unique_dir(0, &albumdir); recursive_mkdir(albumdir, 0774); // fill the queue with items to rip for (i = 0; i < handle->area[area_idx].area_toc->track_count; i++) { if (opts.select_tracks && opts.selected_tracks[i] == 0) continue; musicfilename = get_music_filename(handle, area_idx, i, opts.output_file); if (opts.output_dsf) { file_path = make_filename(0, albumdir, musicfilename, "dsf"); scarletbook_output_enqueue_track(output, area_idx, i, file_path, "dsf", 1 /* always decode to DSD */); } else if (opts.output_dsdiff) { file_path = make_filename(0, albumdir, musicfilename, "dff"); scarletbook_output_enqueue_track(output, area_idx, i, file_path, "dsdiff", (opts.convert_dst ? 1 : handle->area[area_idx].area_toc->frame_format != FRAME_FORMAT_DST)); } free(musicfilename); free(file_path); file_path = 0; } } if (opts.export_cue_sheet) { char *cue_file_path = make_filename(0, 0, albumdir, "cue"); #ifdef _WIN32 wchar_t *wide_filename = (wchar_t *) charset_convert(cue_file_path, strlen(cue_file_path), "UTF-8", sizeof(wchar_t) == 2 ? "UCS-2-INTERNAL" : "UCS-4-INTERNAL"); #else wchar_t *wide_filename = (wchar_t *) charset_convert(cue_file_path, strlen(cue_file_path), "UTF-8", "WCHAR_T"); #endif fwprintf(stdout, L"Exporting CUE sheet [%ls]\n", wide_filename); if (!file_path) file_path = make_filename(0, 0, albumdir, "dff"); write_cue_sheet(handle, file_path, area_idx, cue_file_path); free(cue_file_path); free(wide_filename); } free(file_path); started_processing = time(0); scarletbook_output_start(output); scarletbook_output_destroy(output); fprintf(stdout, "\rWe are done.. \n"); } scarletbook_close(handle); free(albumdir); } } sacd_close(sacd_reader); #ifndef _WIN32 freopen(0, "w", stdout); #endif if (fwide(stdout, -1) >= 0) { fprintf(stderr, "ERROR: Output not set to byte oriented.\n"); } } free_lock(g_fwprintf_lock); destroy_logging(); #ifdef PTW32_STATIC_LIB pthread_win32_process_detach_np(); pthread_win32_thread_detach_np(); #endif printf("\n"); return 0; }
int main(int argc, char **argv) { int ds, dms, ret; double mb, rmb; struct timeval t1, t2; #ifndef C_WINDOWS struct timezone tz; sigset_t sigset; #endif struct optstruct *opts; const struct optstruct *opt; #if defined(C_WINDOWS) && defined(CL_THREAD_SAFE) if(!pthread_win32_process_attach_np()) { mprintf("!Can't start the win32 pthreads layer\n"); return 72; } #endif #if !defined(C_WINDOWS) && !defined(C_BEOS) sigemptyset(&sigset); sigaddset(&sigset, SIGXFSZ); sigprocmask(SIG_SETMASK, &sigset, NULL); #endif if((opts = optparse(NULL, argc, argv, 1, OPT_CLAMSCAN, 0, NULL)) == NULL) { mprintf("!Can't parse command line options\n"); return 40; } if(optget(opts, "verbose")->enabled) { mprintf_verbose = 1; logg_verbose = 1; } if(optget(opts, "quiet")->enabled) mprintf_quiet = 1; if(optget(opts, "stdout")->enabled) mprintf_stdout = 1; if(optget(opts, "debug")->enabled) { #if defined(C_LINUX) /* [email protected]: create a dump if needed */ struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = RLIM_INFINITY; if(setrlimit(RLIMIT_CORE, &rlim) < 0) perror("setrlimit"); #endif cl_debug(); /* enable debug messages */ } if(optget(opts, "version")->enabled) { print_version(optget(opts, "database")->strarg); optfree(opts); return 0; } if(optget(opts, "help")->enabled) { optfree(opts); help(); return 0; } if(optget(opts, "recursive")->enabled) recursion = 1; if(optget(opts, "infected")->enabled) printinfected = 1; if(optget(opts, "bell")->enabled) bell = 1; /* initialize logger */ if((opt = optget(opts, "log"))->enabled) { logg_file = opt->strarg; if(logg("#\n-------------------------------------------------------------------------------\n\n")) { mprintf("!Problem with internal logger.\n"); optfree(opts); return 62; } } else logg_file = NULL; if(actsetup(opts)) { optfree(opts); logg_close(); exit(2); } memset(&info, 0, sizeof(struct s_info)); #ifdef C_WINDOWS _set_fmode(_O_BINARY); #ifdef CL_DEBUG { _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); } #endif gettimeofday(&t1, NULL); #else gettimeofday(&t1, &tz); #endif ret = scanmanager(opts); if(!optget(opts, "no-summary")->enabled) { #ifdef C_WINDOWS gettimeofday(&t2, NULL); #else gettimeofday(&t2, &tz); #endif ds = t2.tv_sec - t1.tv_sec; dms = t2.tv_usec - t1.tv_usec; ds -= (dms < 0) ? (1):(0); dms += (dms < 0) ? (1000000):(0); logg("\n----------- SCAN SUMMARY -----------\n"); logg("Known viruses: %u\n", info.sigs); logg("Engine version: %s\n", get_version()); logg("Scanned directories: %u\n", info.dirs); logg("Scanned files: %u\n", info.files); logg("Infected files: %u\n", info.ifiles); if(notremoved) { logg("Not removed: %u\n", notremoved); } if(notmoved) { logg("Not %s: %u\n", optget(opts, "copy")->enabled ? "moved" : "copied", notmoved); } mb = info.blocks * (CL_COUNT_PRECISION / 1024) / 1024.0; logg("Data scanned: %2.2lf MB\n", mb); rmb = info.rblocks * (CL_COUNT_PRECISION / 1024) / 1024.0; logg("Data read: %2.2lf MB (ratio %.2f:1)\n", rmb, info.rblocks ? (double)info.blocks/(double)info.rblocks : 0); logg("Time: %u.%3.3u sec (%u m %u s)\n", ds, dms/1000, ds/60, ds%60); } optfree(opts); #if defined(C_WINDOWS) && defined(CL_THREAD_SAFE) if(!pthread_win32_process_detach_np()) { logg("!Can't stop the win32 pthreads layer\n"); return 72; } #endif return ret; }
static int on_process_exit(void) { pthread_win32_thread_detach_np (); pthread_win32_process_detach_np (); return 0; }
static void on_process_exit(void) { pthread_win32_thread_detach_np (); pthread_win32_process_detach_np (); }
int main (int argc, char **argv) { int rv = 0; inst = & _plugin; #ifdef __APPLE__ rtk_osx_api_init(); #endif #ifdef _WIN32 pthread_win32_process_attach_np(); #endif #if (defined _WIN32 && defined RTK_STATIC_INIT) glib_init_static(); gobject_init_ctor(); #endif struct { int argc; char **argv; } rtkargv; rtkargv.argc = argc; rtkargv.argv = argv; const LV2_Feature external_lv_feature = { LV2_EXTERNAL_UI_URI, &extui_host}; const LV2_Feature external_kx_feature = { LV2_EXTERNAL_UI_URI__KX__Host, &extui_host}; const LV2_Feature robtk_argv = { "http://gareus.org/oss/lv2/robtk#argv", &rtkargv}; // TODO add argv[] as feature const LV2_Feature* ui_features[] = { &external_lv_feature, &external_kx_feature, &robtk_argv, NULL }; extui_host.plugin_human_id = inst->plugin_human_id; plugin_gui = inst->lv2ui_descriptor(inst->gui_descriptor_id); if (plugin_gui) { /* init plugin GUI */ extui_host.ui_closed = on_external_ui_closed; gui_instance = plugin_gui->instantiate(plugin_gui, "URI TODO", NULL, NULL, NULL, (void **)&extui, ui_features); } if (!gui_instance || !extui) { fprintf(stderr, "Error: GUI was not initialized.\n"); rv |= 2; goto out; } #ifndef _WIN32 signal (SIGHUP, catchsig); signal (SIGINT, catchsig); #endif { LV2_EXTERNAL_UI_SHOW(extui); #ifdef __APPLE__ CFRunLoopRef runLoop = CFRunLoopGetCurrent(); CFRunLoopTimerContext context = {0, NULL, NULL, NULL, NULL}; CFRunLoopTimerRef timer = CFRunLoopTimerCreate(kCFAllocatorDefault, 0, 1.0/UI_UPDATE_FPS, 0, 0, &osx_loop, &context); CFRunLoopAddTimer(runLoop, timer, kCFRunLoopCommonModes); rtk_osx_api_run(); #else main_loop(); #endif LV2_EXTERNAL_UI_HIDE(extui); } out: cleanup(0); #ifdef _WIN32 pthread_win32_process_detach_np(); #endif #if (defined _WIN32 && defined RTK_STATIC_INIT) glib_cleanup_static(); #endif return(rv); }