//-------------------------------------------------------------------------------------------------- le_result_t le_sem_WaitWithTimeOut ( le_sem_Ref_t semaphorePtr, ///< [IN] Pointer to the semaphore. le_clk_Time_t timeToWait ///< [IN] Time to wait ) { // TODO: Implement this. // if (semaphorePtr->isTraceable) // { // } // else { struct timespec timeOut; int result; // Prepare the timer le_clk_Time_t currentUtcTime = le_clk_GetAbsoluteTime(); le_clk_Time_t wakeUpTime = le_clk_Add(currentUtcTime,timeToWait); timeOut.tv_sec = wakeUpTime.sec; timeOut.tv_nsec = wakeUpTime.usec; // Retrieve reference thread sem_ThreadRec_t* perThreadRecPtr = thread_GetSemaphoreRecPtr(); // Save into waiting list ListOfSemaphoresChgCnt++; perThreadRecPtr->waitingOnSemaphore = semaphorePtr; AddToWaitingList(semaphorePtr, perThreadRecPtr); result = sem_timedwait(&semaphorePtr->semaphore,&timeOut); // Remove from waiting list RemoveFromWaitingList(semaphorePtr, perThreadRecPtr); ListOfSemaphoresChgCnt++; perThreadRecPtr->waitingOnSemaphore = NULL; if (result != 0) { if ( errno == ETIMEDOUT ) { return LE_TIMEOUT; } else { LE_FATAL("Thread '%s' failed to wait on semaphore '%s'. Error code %d (%m).", le_thread_GetMyName(), semaphorePtr->nameStr, result); } } } return LE_OK; }
//-------------------------------------------------------------------------------------------------- le_result_t le_clk_GetLocalDateTimeString ( const char* formatSpecStrPtr, ///< [IN] Format specifier string, using conversion /// specifiers defined for strftime(). char* destStrPtr, ///< [OUT] Destination for the formatted date/time string size_t destSize, ///< [IN] Size of the destination buffer in bytes. size_t* numBytesPtr ///< [OUT] Number of bytes copied, not including NULL-terminator. /// This parameter can be set to NULL if the number of /// bytes copied is not needed. ) { le_clk_Time_t absTime; // Get the time broken down into local year, month, day, and so on. absTime = le_clk_GetAbsoluteTime(); return le_clk_ConvertToLocalTimeString(absTime,formatSpecStrPtr,destStrPtr,destSize,numBytesPtr); }
//-------------------------------------------------------------------------------------------------- static proc_FaultAction_t GetFaultAction ( proc_Ref_t procRef ///< [IN] The process reference. ) { if (procRef->cmdKill) { // The cmdKill flag was set which means the process died because we killed it so // it was not a fault. Reset the cmdKill flag so that if this process is restarted // faults will still be caught. procRef->cmdKill = false; return PROC_FAULT_ACTION_NO_FAULT; } // Record the fault time. procRef->faultTime = (le_clk_GetAbsoluteTime()).sec; // Read the process's fault action from the config tree. le_cfg_IteratorRef_t procCfg = le_cfg_CreateReadTxn(procRef->cfgPathRoot); char faultActionStr[LIMIT_MAX_FAULT_ACTION_NAME_BYTES]; le_result_t result = le_cfg_GetString(procCfg, CFG_NODE_FAULT_ACTION, faultActionStr, sizeof(faultActionStr), ""); le_cfg_CancelTxn(procCfg); // Set the fault action based on the fault action string. if (result != LE_OK) { LE_CRIT("Fault action string for process '%s' is too long. Assume fault action is 'ignore'.", procRef->name); return PROC_FAULT_ACTION_IGNORE; } if (strcmp(faultActionStr, RESTART_STR) == 0) { return PROC_FAULT_ACTION_RESTART; } if (strcmp(faultActionStr, RESTART_APP_STR) == 0) { return PROC_FAULT_ACTION_RESTART_APP; } if (strcmp(faultActionStr, STOP_APP_STR) == 0) { return PROC_FAULT_ACTION_STOP_APP; } if (strcmp(faultActionStr, REBOOT_STR) == 0) { return PROC_FAULT_ACTION_REBOOT; } if (strcmp(faultActionStr, IGNORE_STR) == 0) { return PROC_FAULT_ACTION_IGNORE; } LE_WARN("Unrecognized fault action for process '%s'. Assume fault action is 'ignore'.", procRef->name); return PROC_FAULT_ACTION_IGNORE; }
//-------------------------------------------------------------------------------------------------- le_result_t secSocket_AddCertificate ( secSocket_Ctx_t* ctxPtr, ///< [INOUT] Secure socket context pointer const uint8_t* certificatePtr, ///< [IN] Certificate Pointer size_t certificateLen ///< [IN] Certificate Length ) { X509_STORE *store = NULL; X509 *cert = NULL; BIO *bio = NULL; le_result_t status = LE_FAULT; le_clk_Time_t currentTime; // Check input parameters if ((!ctxPtr) || (!certificatePtr) || (!certificateLen)) { return LE_BAD_PARAMETER; } OpensslCtx_t* contextPtr = GetContext(ctxPtr); if (!contextPtr) { return LE_BAD_PARAMETER; } LE_INFO("Certificate: %p Len:%zu", certificatePtr, certificateLen); // Get a BIO abstraction pointer bio = BIO_new_mem_buf((void*)certificatePtr, certificateLen); if (!bio) { LE_ERROR("Unable to allocate BIO pointer"); goto end; } // Read the DER formatted certificate from memory into an X509 structure cert = d2i_X509(NULL, &certificatePtr, certificateLen); if (!cert) { LE_ERROR("Unable to read certificate"); goto end; } // Check certificate validity currentTime = le_clk_GetAbsoluteTime(); if ((X509_cmp_time(X509_get_notBefore(cert), ¤tTime.sec) >= 0) || (X509_cmp_time(X509_get_notAfter(cert), ¤tTime.sec) <= 0)) { LE_ERROR("Current certificate expired, please add a valid certificate"); status = LE_FORMAT_ERROR; goto end; } // Get a pointer to the current certificate verification pool store = SSL_CTX_get_cert_store(contextPtr->sslCtxPtr); if (!store) { LE_ERROR("Unable to get a pointer to the X509 certificate"); goto end; } // Add certificate to the verification pool if (!X509_STORE_add_cert(store, cert)) { LE_ERROR("Unable to add certificate to pool"); goto end; } status = LE_OK; end: if (cert) { X509_free(cert); } if (bio) { BIO_free(bio); } return status; }