oslProcess SAL_CALL osl_getProcess(oslProcessIdentifier Ident) { oslProcessImpl *pProcImpl; if (kill(Ident, 0) != -1) { oslProcessImpl* pChild; if (ChildListMutex == NULL) ChildListMutex = osl_createMutex(); osl_acquireMutex(ChildListMutex); pChild = ChildList; /* check if it is one of our child processes */ while (pChild != NULL) { if (Ident == (sal_uInt32) pChild->m_pid) break; pChild = pChild->m_pnext; } pProcImpl = (oslProcessImpl*) malloc(sizeof(oslProcessImpl)); pProcImpl->m_pid = Ident; pProcImpl->m_terminated = osl_createCondition(); if (pChild != NULL) { /* process is a child so insert into list */ pProcImpl->m_pnext = pChild->m_pnext; pChild->m_pnext = pProcImpl; pProcImpl->m_status = pChild->m_status; if (osl_checkCondition(pChild->m_terminated)) osl_setCondition(pProcImpl->m_terminated); } else pProcImpl->m_pnext = NULL; osl_releaseMutex(ChildListMutex); } else pProcImpl = NULL; return (pProcImpl); }
static void do_startup( void ) { #else static BOOL WINAPI _RawDllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) { (void)hinstDLL; /* avoid warnings */ (void)lpvReserved; /* avoid warnings */ switch (fdwReason) { case DLL_PROCESS_ATTACH: { #endif #if OSL_DEBUG_LEVEL < 2 /* Suppress file error messages from system like "Floppy A: not inserted" */ SetErrorMode( SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS ); #endif /* initialize global mutex */ g_Mutex = osl_createMutex(); /* initialize "current directory" mutex */ g_CurrentDirectoryMutex = osl_createMutex(); g_dwTLSTextEncodingIndex = TlsAlloc(); InitializeCriticalSection( &g_ThreadKeyListCS ); //We disable floating point exceptions. This is the usual state at program startup //but on Windows 98 and ME this is not always the case. _control87(_MCW_EM, _MCW_EM); #ifdef __MINGW32__ atexit(do_cleanup); } void do_cleanup( void ) { #else break; } case DLL_PROCESS_DETACH: #endif WSACleanup( ); TlsFree( g_dwTLSTextEncodingIndex ); DeleteCriticalSection( &g_ThreadKeyListCS ); osl_destroyMutex( g_Mutex ); osl_destroyMutex( g_CurrentDirectoryMutex ); #ifndef __MINGW32__ /* On a product build memory management finalization might cause a crash without assertion (assertions off) if heap is corrupted. But a crash report won't help here because at this point all other threads have been terminated and only ntdll is on the stack. No chance to find the reason for the corrupted heap if so. So annoying the user with a crash report is completely useless. */ #ifndef DBG_UTIL __try #endif { /* cleanup locale hashtable */ rtl_locale_fini(); /* finalize memory management */ rtl_memory_fini(); rtl_cache_fini(); rtl_arena_fini(); } #ifndef DBG_UTIL __except( EXCEPTION_EXECUTE_HANDLER ) { } #endif break; } return TRUE; #endif }
oslProcessError SAL_CALL osl_psz_executeProcess(sal_Char *pszImageName, sal_Char *pszArguments[], oslProcessOption Options, oslSecurity Security, sal_Char *pszDirectory, sal_Char *pszEnvironments[], oslProcess *pProcess, oslFileHandle *pInputWrite, oslFileHandle *pOutputRead, oslFileHandle *pErrorRead ) { int i; sal_Char path[PATH_MAX + 1]; ProcessData Data; oslThread hThread; path[0] = '\0'; memset(&Data,0,sizeof(ProcessData)); Data.m_pInputWrite = pInputWrite; Data.m_pOutputRead = pOutputRead; Data.m_pErrorRead = pErrorRead; if (pszImageName == NULL) pszImageName = pszArguments[0]; OSL_ASSERT(pszImageName != NULL); if ( pszImageName == 0 ) { return osl_Process_E_NotFound; } if ((Options & osl_Process_SEARCHPATH) && (osl_searchPath_impl(pszImageName, NULL, '\0', path, sizeof(path)) == osl_Process_E_None)) pszImageName = path; Data.m_pszArgs[0] = strdup(pszImageName); Data.m_pszArgs[1] = 0; if ( pszArguments != 0 ) { for (i = 0; ((i + 2) < MAX_ARGS) && (pszArguments[i] != NULL); i++) Data.m_pszArgs[i+1] = strdup(pszArguments[i]); Data.m_pszArgs[i+2] = NULL; } Data.m_options = Options; Data.m_pszDir = (pszDirectory != NULL) ? strdup(pszDirectory) : NULL; if (pszEnvironments != NULL) { for (i = 0; ((i + 1) < MAX_ENVS) && (pszEnvironments[i] != NULL); i++) Data.m_pszEnv[i] = strdup(pszEnvironments[i]); Data.m_pszEnv[i+1] = NULL; } else Data.m_pszEnv[0] = NULL; if (Security != NULL) { Data.m_uid = ((oslSecurityImpl*)Security)->m_pPasswd.pw_uid; Data.m_gid = ((oslSecurityImpl*)Security)->m_pPasswd.pw_gid; Data.m_name = ((oslSecurityImpl*)Security)->m_pPasswd.pw_name; } else Data.m_uid = (uid_t)-1; Data.m_pProcImpl = (oslProcessImpl*) malloc(sizeof(oslProcessImpl)); Data.m_pProcImpl->m_pid = 0; Data.m_pProcImpl->m_terminated = osl_createCondition(); Data.m_pProcImpl->m_pnext = NULL; if (ChildListMutex == NULL) ChildListMutex = osl_createMutex(); Data.m_started = osl_createCondition(); hThread = osl_createThread(ChildStatusProc, &Data); osl_waitCondition(Data.m_started, NULL); osl_destroyCondition(Data.m_started); for (i = 0; Data.m_pszArgs[i] != NULL; i++) free((void *)Data.m_pszArgs[i]); for (i = 0; Data.m_pszEnv[i] != NULL; i++) free((void *)Data.m_pszEnv[i]); if ( Data.m_pszDir != 0 ) { free((void *)Data.m_pszDir); } osl_destroyThread(hThread); if (Data.m_pProcImpl->m_pid != 0) { *pProcess = Data.m_pProcImpl; if (Options & osl_Process_WAIT) osl_joinProcess(*pProcess); return osl_Process_E_None; } osl_destroyCondition(Data.m_pProcImpl->m_terminated); free(Data.m_pProcImpl); return osl_Process_E_Unknown; }