/* We need this on windows to make sure the main thread of MFC applications * calls os_osInit(). */ BOOL WINAPI DllMain( HINSTANCE hinstDLL, /* handle to DLL module */ DWORD fdwReason, /* reason for calling function */ LPVOID lpReserved ) /* reserved */ { /* Perform actions based on the reason for calling.*/ switch( fdwReason ) { case DLL_PROCESS_ATTACH: /* Initialize once for each new process. * Return FALSE to fail DLL load. */ os_osInit(); break; case DLL_THREAD_ATTACH: /* Do thread-specific initialization. */ break; case DLL_THREAD_DETACH: /* Do thread-specific cleanup. */ break; case DLL_PROCESS_DETACH: /* Perform any necessary cleanup. */ os_osExit(); break; } return TRUE; /* Successful DLL_PROCESS_ATTACH.*/ }
int main( int argc, char* argv[]) { c_base base; int fileIndex = 1; c_bool scopedNames = FALSE; char osServiceName[SERVICE_NAME_MAX]; int id = os_procIdToInteger (os_procIdSelf()); if (argc < 2) { printf("Usage: %s [-m] <filename>\n", argv[0]); return -1; } snprintf(osServiceName, SERVICE_NAME_MAX, "%s%d", SERVICE_NAME_PREFIX, id); if (os_serviceStart(osServiceName) != os_resultSuccess) { printf("Failed to start mutex service\n"); return -2; } os_osInit(); if (strcmp(argv[1], "-m") == 0) { scopedNames =TRUE; fileIndex++; } base = c_create("preprocessor",NULL,0, 0); c_odlinit(c_module(base)); c_odlparse(argv[fileIndex]); c_gen_C(c_module(base), scopedNames); if (os_serviceStop() != os_resultSuccess) { printf("Failed to stop mutex service\n"); return -3; } return 0; }
os__osInit( void) { os_osInit(); }
u_result u_userInitialise( void) { u_user u; u_result rm = U_RESULT_OK; os_mutexAttr mutexAttr; os_uint32 initCount; void* initUser; os_result osResult; os_signalHandlerExitRequestCallback exitRequestCallback; os_signalHandlerExceptionCallback exceptionCallback; initCount = pa_increment(&_ospl_userInitCount); /* If initCount == 0 then an overflow has occurred. * This can only realistically happen when u_userDetach() * is called more often than u_userInitialize(). */ assert(initCount != 0); os_osInit(); if (initCount == 1) { /* Will start allocating the object, so it should currently be empty. */ assert(user == NULL); /* Use indirection, as user != NULL is a precondition for user-layer * functions, so make sure it only holds true when the user-layer is * initialized. */ initUser = os_malloc(sizeof(C_STRUCT(u_user))); if (initUser == NULL) { /* Initialization failed, so decrement the initialization counter. */ pa_decrement(&_ospl_userInitCount); os_osExit(); OS_REPORT(OS_ERROR, "u_userInitialise", 0, "Allocation of user admin failed: out of memory."); rm = U_RESULT_OUT_OF_MEMORY; } else { u = u_user(initUser); os_mutexAttrInit(&mutexAttr); mutexAttr.scopeAttr = OS_SCOPE_PRIVATE; os_mutexInit(&u->mutex,&mutexAttr); osResult = os_signalHandlerNew(); if(osResult != os_resultSuccess) { /* Initialization did not succeed, undo increment and return error */ initCount = pa_decrement(&_ospl_userInitCount); OS_REPORT(OS_ERROR, "u_userInitialise", 0, "Failed to create the signal handler. No proper signal handling can be performed."); rm = U_RESULT_INTERNAL_ERROR; } else { exitRequestCallback = os_signalHandlerSetExitRequestCallback(u__userExitRequestCallbackWrapper); if(exitRequestCallback && exitRequestCallback != u__userExitRequestCallbackWrapper) { initCount = pa_decrement(&_ospl_userInitCount); OS_REPORT(OS_ERROR, "u_userInitialise", 0, "Replaced an exit request callback on the signal handler while this was not expected."); rm = U_RESULT_INTERNAL_ERROR; } if(rm == U_RESULT_OK){ exceptionCallback = os_signalHandlerSetExceptionCallback(u__userExceptionCallbackWrapper); if(exceptionCallback && exceptionCallback != u__userExceptionCallbackWrapper) { initCount = pa_decrement(&_ospl_userInitCount); OS_REPORT(OS_ERROR, "u_userInitialise", 0, "Replaced an exception callback on the signal handler while this was not expected."); rm = U_RESULT_INTERNAL_ERROR; } } if(rm == U_RESULT_OK) { u->domainCount = 0; u->protectCount = 0; u->detachThreadId = OS_THREAD_ID_NONE; /* This will mark the user-layer initialized */ user = initUser; } } } } else { if(user == NULL){ os_time sleep = {0, 100000}; /* 100ms */ /* Another thread is currently initializing the user-layer. Since * user != NULL is a precondition for calls after u_userInitialise(), * a sleep is performed, to ensure that (if succeeded) successive * user-layer calls will also actually pass.*/ os_nanoSleep(sleep); } if(user == NULL){ /* Initialization did not succeed, undo increment and return error */ initCount = pa_decrement(&_ospl_userInitCount); OS_REPORT_1(OS_ERROR,"u_userInitialise",0, "Internal error: User-layer should be initialized " "(initCount = %d), but user == NULL (waited 100ms).", initCount); rm = U_RESULT_INTERNAL_ERROR; } } return rm; }
int main( int argc, char *argv[]) { int opt; int retCode = OSPL_EXIT_CODE_OK; char *uri = NULL; char *command = NULL; char start_command[2048]; cf_element domain = NULL; cfgprs_status r; os_boolean blocking = OS_FALSE; os_boolean blockingDefined = OS_FALSE; os_time serviceTerminatePeriod; char *vg_cmd = NULL; ospl_setsignals(); os_osInit(); os_procAtExit(os_osExit); uri = os_getenv ("OSPL_URI"); vg_cmd = os_getenv("VG_SPLICED"); if (!vg_cmd) { vg_cmd = ""; } while ((opt = getopt (argc, argv, "hvafd:")) != -1) { switch (opt) { case 'h': print_usage (argv[0]); exit (OSPL_EXIT_CODE_OK); break; case 'v': printf ("OpenSplice version : %s\n", VERSION); exit (OSPL_EXIT_CODE_OK); break; case 'd': if (domain_name) { print_usage (argv[0]); exit (OSPL_EXIT_CODE_UNRECOVERABLE_ERROR); } domain_name = optarg; break; case 'a': if (domain_name) { print_usage (argv[0]); exit (OSPL_EXIT_CODE_UNRECOVERABLE_ERROR); } uri = NULL; domain_name = "*"; break; case 'f': if(blockingDefined) { print_usage (argv[0]); exit (OSPL_EXIT_CODE_UNRECOVERABLE_ERROR); } blocking = OS_TRUE; blockingDefined = OS_TRUE; break; case '?': print_usage (argv[0]); exit (OSPL_EXIT_CODE_UNRECOVERABLE_ERROR); break; default: break; } } if ((argc-optind) > 3) { print_usage (argv[0]); exit(OSPL_EXIT_CODE_UNRECOVERABLE_ERROR); } command = argv[optind]; if (command && argv[optind+1]) { uri = argv[optind+1]; } if (uri && (strlen(uri) > 0)) { r = cfg_parse_ospl (uri, &platformConfig); if (r == CFGPRS_OK) { domain_name = findDomain (platformConfig, &domain); if (domain_name == NULL) { printf ("The domain name could not be determined from the configuration\n"); exit (OSPL_EXIT_CODE_UNRECOVERABLE_ERROR); } } else { if (r == CFGPRS_NO_INPUT) { printf ("Error: Cannot open URI \"%s\". Exiting now...\n", uri); } else { printf ("Errors are detected in the configuration. Exiting now...\n"); } exit (OSPL_EXIT_CODE_UNRECOVERABLE_ERROR); } } if ((command == NULL) || (strcmp (command, "stop") == 0)) { if (domain_name == NULL) { domain_name = "The default Domain"; } findServiceTerminatePeriod(domain, &serviceTerminatePeriod); retCode = findSpliceSystemAndRemove (domain_name, serviceTerminatePeriod); } else if (strcmp (command, "start") == 0) { #ifdef OS_LINUX_DEFS_H check_for_LD_ASSUME_KERNEL (); #endif if (domain_name == NULL) { domain_name = "The default Domain"; } if (!spliceSystemRunning (domain_name)) { if(!blocking) { printf ("\nStarting up domain \"%s\" .", domain_name); } else { printf ("\nStarting up domain \"%s\" and blocking.", domain_name); } if (uri) { if(!blocking) { snprintf (start_command, sizeof(start_command), "%s spliced \"%s\" &", vg_cmd, uri); } else { snprintf (start_command, sizeof(start_command), "%s spliced \"%s\"", vg_cmd, uri); } } else { if(!blocking) { snprintf (start_command, sizeof(start_command), "%s spliced &", vg_cmd); } else { snprintf (start_command, sizeof(start_command), "%s spliced", vg_cmd); } } printf (" Ready\n"); /* Display locations of info and error files */ os_reportDisplayLogLocations(); retCode = WEXITSTATUS(system (start_command)); if(!blocking) { sleep (2); /* take time to first show the license message from spliced */ } } else { printf ("Splice System with domain name \"%s\" is found running, ignoring command\n", domain_name); } } else if (strcmp (command, "list") == 0) { retCode = findSpliceSystemAndShow (domain_name); } else { print_usage (argv[0]); exit (OSPL_EXIT_CODE_UNRECOVERABLE_ERROR); } return retCode; }