Example #1
0
//--------------------------------------------------------------------------------------------------
static void PrintUsage
(
    void
)
{
    int idx;
    const char * usagePtr[] =
    {
     "Usage of the 'simTest' application is:",
     "SIM allocation test: app runProc simTest --exe=simTest -- create <ext/emb/unsp> <pin>",
     "SIM state test: app runProc simTest --exe=simTest -- state <ext1/ext2/emb/unsp> <pin>",
     "SIM authentication test: app runProc simTest"
     " --exe=simTest -- auth <ext/emb/unsp> <pin> <puk>",
     "No SIM test: app runProc simTest --exe=simTest -- nosim <ext/emb/unsp>",
     "SIM select: app runProc simTest --exe=simTest -- select",
     "SIM lock test: app runProc simTest --exe=simTest -- lock <emb/ext1/ext2/rem/unsp> <pin>",
     "SIM GetICCID test: app runProc simTest --exe=simTest -- iccid <emb/ext1/ext2/rem/unsp>",
     "SIM GetEID test: app runProc simTest --exe=simTest -- eid <emb/ext1/ext2/rem/unsp>",
     "SIM send apdu test: app runProc simTest --exe=simTest -- access <emb/ext1/ext2/rem/unsp>",
     "SIM allocation test: app runProc simTest --exe=simTest -- powerUpDown",
     "SIM events: app runProc simTest --exe=simTest -- events",
     "SIM auto selection: app runProc simTest --exe=simTest -- auto <1/0>",
     "",
    };

    for (idx = 0; idx < NUM_ARRAY_MEMBERS(usagePtr); idx++)
    {
        Print((char*) usagePtr[idx]);
    }
}
Example #2
0
//--------------------------------------------------------------------------------------------------
static void PrintUsage()
{
    int idx;
    bool sandboxed = (getuid() != 0);
    const char * usagePtr[] = {
                    "Sequence <id>",
                    "    : Display Help",
                    "  0 : Get temperature",
                    "  1 : Set Get Platform Thresholds",
                    "  2 : Set Get Radio Thresholds",
                    "  3 : Configure Platform Thresolds event",
                    "  4 : Configure Radio Thresolds event",
                    "  5 : Test Thresolds event, (use CTR+C to exit before first Critical Event)",
                    "  6 : Restore Radio temperature Thresolds",
                    "  7 : Restore Platform temperature Thresolds"
    };

    for(idx = 0; idx < NUM_ARRAY_MEMBERS(usagePtr); idx++)
    {
        if(sandboxed)
        {
            LE_INFO("%s", usagePtr[idx]);
        }
        else
        {
            fprintf(stderr, "%s\r\n", usagePtr[idx]);
        }
    }
}
Example #3
0
//--------------------------------------------------------------------------------------------------
static void PrintUsage
(
    void
)
{
    int idx;
    bool sandboxed = (getuid() != 0);
    const char * usagePtr[] =
    {
            "Usage of the simToolkit app is:",
            "   execInApp simToolkit simToolkit <accept/reject/none>",
    };

    for(idx = 0; idx < NUM_ARRAY_MEMBERS(usagePtr); idx++)
    {
        if(sandboxed)
        {
            LE_INFO("%s", usagePtr[idx]);
        }
        else
        {
            fprintf(stderr, "%s\n", usagePtr[idx]);
        }
    }
}
Example #4
0
//--------------------------------------------------------------------------------------------------
le_result_t fwDaemons_SigChildHandler
(
    pid_t pid,              ///< [IN] Pid of the process that produced the SIGCHLD.
    int status              ///< [IN] Status of the process.
)
{
    // See which daemon produced this signal.
    DaemonObj_t* daemonObjPtr = NULL;

    int i;
    for (i = 0; i < NUM_ARRAY_MEMBERS(FrameworkDaemons); i++)
    {
        if (FrameworkDaemons[i].pid == pid)
        {
            daemonObjPtr = &(FrameworkDaemons[i]);

            // Check status of process and handle SIGCONT and SIGSTOP signals.
            if ( WIFSTOPPED(status) || WIFCONTINUED(status) )
            {
                // The framework dameon was either stopped or continued which should not happen kill
                // the process now.
                kill_Hard(pid);

                // Return LE_OK here, when the process actually dies we'll get another SIGCHLD.
                return LE_OK;
            }

            // Mark this daemon as dead.
            daemonObjPtr->pid = -1;
            kill_Died(pid);

            break;
        }
    }

    if (daemonObjPtr == NULL)
    {
        return LE_NOT_FOUND;
    }

    if (ShutdownIndex >= 0)
    {
        // We are in the midst of a shutdown sequence, continue the shutdown sequence.
        ShutdownIndex = ShutdownNextDaemon(ShutdownIndex);

        return LE_OK;
    }
    else
    {
        // This was an unexpected error from one of the framework daemons.
        LE_EMERG("The framework daemon '%s' has experienced a problem.",
                le_path_GetBasenamePtr(daemonObjPtr->path, "/"));

        return LE_FAULT;
    }
}
Example #5
0
static void dataRouterUpdateHandler
(
    dataRouter_DataType_t type,
    const char* key,
    void* contextPtr
)
{
    LE_DEBUG("Processing update for key=%s", key);
    uint32_t timestamp;
    std::string keyStr(key);
    switch (type)
    {
        case DATAROUTER_BOOLEAN:
        {
            bool b;
            dataRouter_ReadBoolean(key, &b, &timestamp);
            DataValue value(b);
            globals.data[keyStr] = value;
            break;
        }

        case DATAROUTER_INTEGER:
        {
            int32_t i;
            dataRouter_ReadInteger(key, &i, &timestamp);
            DataValue value(i);
            globals.data[keyStr] = value;
            break;
        }

        case DATAROUTER_FLOAT:
        {
            double d;
            dataRouter_ReadFloat(key, &d, &timestamp);
            DataValue value(d);
            globals.data[keyStr] = value;
            break;
        }

        case DATAROUTER_STRING:
        {
            char buffer[128];
            dataRouter_ReadString(key, buffer, NUM_ARRAY_MEMBERS(buffer), &timestamp);
            std::string s(buffer);
            DataValue value(s);
            globals.data[keyStr] = value;
            break;
        }

        default:
        {
            LE_FATAL("Invalid data type (%d)", type);
            break;
        }
    }
}
Example #6
0
// This is testing if Mutex_t.waitingList is displayed correctly.
// Thread1 successfully locks mutexes 1, 2, and 3, and then Thread 2 and 3 tries to lock mutex 1, and 
// Thread 4 and 5 tries to lock mutex 3.
// Therefore the expected result is that Mutex1's waiting list has Thread2 and 3, Mutex2's waiting 
// list is empty, and Mutex3's waiting list has Thread4 and 5.
void testWaitingList
(
    void
)
{
    le_mutex_Ref_t mutex1Ref = le_mutex_CreateNonRecursive("Mutex1");
    le_mutex_Ref_t mutex2Ref = le_mutex_CreateNonRecursive("Mutex2");
    le_mutex_Ref_t mutex3Ref = le_mutex_CreateNonRecursive("Mutex3");

    // create mutex arrays to be passed to each thread.
    le_mutex_Ref_t mutexRefArray1[3] = {mutex1Ref, mutex2Ref, mutex3Ref};
    le_mutex_Ref_t mutexRefArray2[1] = {mutex1Ref};
    le_mutex_Ref_t mutexRefArray3[1] = {mutex3Ref};

    // put the arrays in a data struct containing size
    MutexRefArray_t mra1 = {NUM_ARRAY_MEMBERS(mutexRefArray1), mutexRefArray1};
    MutexRefArray_t mra2 = {NUM_ARRAY_MEMBERS(mutexRefArray2), mutexRefArray2};
    MutexRefArray_t mra3 = {NUM_ARRAY_MEMBERS(mutexRefArray3), mutexRefArray3};

    // create thread refs
    le_thread_Ref_t thread1Ref = le_thread_Create("Thread1", LockMutex, (void*)&mra1);
    le_thread_Ref_t thread2Ref = le_thread_Create("Thread2", LockMutex, (void*)&mra2);
    le_thread_Ref_t thread3Ref = le_thread_Create("Thread3", LockMutex, (void*)&mra2);
    le_thread_Ref_t thread4Ref = le_thread_Create("Thread4", LockMutex, (void*)&mra3);
    le_thread_Ref_t thread5Ref = le_thread_Create("Thread5", LockMutex, (void*)&mra3);

    // start the threads
    le_thread_Start(thread1Ref);
    // Do not proceed untiil Thread1 has gotten all the mutex locks
    le_sem_Wait(SemaRef);
    le_thread_Start(thread2Ref);
    le_thread_Start(thread3Ref);
    le_thread_Start(thread4Ref);
    le_thread_Start(thread5Ref);

    // Threads 2, 3, 4, and 5 are mutex-locked and therefore can't get to Post. The function needs 
    // to hang around for a bit for the mutex refs to be available for the threads.
    le_sem_Wait(SemaRef);

    LE_INFO("++++++++++++++++++  END OF testWaitingList (shouldn't get here) +++++++++++++++++++++");
}
Example #7
0
//--------------------------------------------------------------------------------------------------
void fwDaemons_Shutdown
(
    void
)
{
    // Set the Shutdown index to the last daemon in the list.
    ShutdownIndex = NUM_ARRAY_MEMBERS(FrameworkDaemons) - 1;

    // Start the shutdown sequence.  After the first framework daemon is shutdown the shutdown
    // sequence will be continued by the fwDaemons_SigChildHandler().
    ShutdownIndex = ShutdownNextDaemon(ShutdownIndex);
}
Example #8
0
//--------------------------------------------------------------------------------------------------
le_result_t le_mrc_GetSignalQual
(
    uint32_t*   qualityPtr  ///< [OUT] The received signal strength quality (0 = no signal strength,
                            ///        5 = very good signal strength).
)
{
    le_result_t   res;
    int32_t       rssi;   // The received signal strength (in dBm).
    int32_t       thresholds[] = {-113, -100, -90, -80, -65}; // TODO: Verify thresholds !
    uint32_t      i=0;
    size_t        thresholdsCount = NUM_ARRAY_MEMBERS(thresholds);

    if (qualityPtr == NULL)
    {
        LE_KILL_CLIENT("qualityPtr is NULL !");
        return LE_FAULT;
    }

    if ((res=pa_mrc_GetSignalQuality(&rssi)) == LE_OK)
    {
        for (i=0; i<thresholdsCount; i++)
        {
            if (rssi <= thresholds[i])
            {
                *qualityPtr = i;
                break;
            }
        }
        if (i == thresholdsCount)
        {
            *qualityPtr = i;
        }

        LE_DEBUG("pa_mrc_GetSignalQuality has returned rssi=%ddBm", rssi);
        return LE_OK;
    }
    else if (res == LE_OUT_OF_RANGE)
    {
        LE_DEBUG("pa_mrc_GetSignalQuality has returned LE_OUT_OF_RANGE");
        *qualityPtr = 0;
        return LE_OK;
    }
    else
    {
        LE_ERROR("pa_mrc_GetSignalQuality has returned %d", res);
        *qualityPtr = 0;
        return LE_NOT_POSSIBLE;
    }
}
Example #9
0
//--------------------------------------------------------------------------------------------------
static bool IsHiddenApp
(
    const char* appName  ///< Name of the application to check.
)
//--------------------------------------------------------------------------------------------------
{
    if (true == le_cfg_QuickGetBool("/lwm2m/hideDefaultApps", true))
    {
        static char* appList[] =
            {
                "airvantage",
                "audioService",
                "avcService",
                "cellNetService",
                "dataConnectionService",
                "modemService",
                "positioningService",
                "powerMgr",
                "secStore",
                "voiceCallService",
                "fwupdateService",
                "smsInboxService",
                "gpioService",
                "tools",
                "atService",
                "atClient",
                "atServer",
                "spiService",
                "devMode",
                "wifiService",
                "wifiClientTest",
                "wifiApTest",
                "wifiWebAp",
                "wifi"
            };

        size_t i;
        for (i = 0; i < NUM_ARRAY_MEMBERS(appList); i++)
        {
            if (0 == strcmp(appList[i], appName))
            {
                return true;
            }
        }
    }

    return false;
}
Example #10
0
//--------------------------------------------------------------------------------------------------
void fwDaemons_Start
(
    void
)
{
    int i;
    for (i = 0; i < NUM_ARRAY_MEMBERS(FrameworkDaemons); i++)
    {
        StartDaemon(&(FrameworkDaemons[i]));
    }

    LE_INFO("All framework daemons ready.");

    // Load the current IPC binding configuration into the Service Directory.
    LoadIpcBindingConfig();
}
Example #11
0
//-------------------------------------------------------------------------------------------------
static le_sim_Id_t GetSimId
(
    const char * strPtr
)
{
    int i;
    for(i = 0; i < NUM_ARRAY_MEMBERS(SimIdStringAssocs); i++)
    {
        if (0 == strcmp(SimIdStringAssocs[i].strPtr, strPtr))
        {
            return SimIdStringAssocs[i].simId;
        }
    }

    LE_ERROR("Unable to convert '%s' to a le_sim_Id_t", strPtr);
    PrintUsage();
    exit(EXIT_FAILURE);
}
Example #12
0
//--------------------------------------------------------------------------------------------------
static void PrintAllHelp()
{
    int serviceIdx;

    for(serviceIdx = 0; serviceIdx < NUM_ARRAY_MEMBERS(Services); serviceIdx++)
    {
        const cm_Service_t * servicePtr = &Services[serviceIdx];

        if (NULL == servicePtr->helpHandler)
        {
            printf("No help for service '%s'\n", servicePtr->serviceNamePtr);
        }
        else
        {
            servicePtr->helpHandler();
        }
    }
}
Example #13
0
//--------------------------------------------------------------------------------------------------
static void PrintUsage()
{
    int idx;
    const char * usagePtr[] = {
            "Usage of the 'simTest' application is:",
            "SIM allocation test: simTest create <sim_select> <pin>",
            "SIM state test: simTest state <sim_select> <pin>",
            "SIM authentification test: simTest auth <sim_select> <pin> <puk>",
            "No SIM test: simTest nosim <sim_select>",
            "SIM select: simTest select",
            "SIM lock test: simTest lock <sim_select> <pin>",
            "",
    };

    for(idx = 0; idx < NUM_ARRAY_MEMBERS(usagePtr); idx++)
    {
        Print((char*) usagePtr[idx]);
    }
}
Example #14
0
//--------------------------------------------------------------------------------------------------
le_result_t le_atClient_SetCommandAndSend
(
    le_atClient_CmdRef_t* cmdRefPtr,
        ///< [OUT] Command reference

    le_atClient_DeviceRef_t devRef,
        ///< [IN] Device reference

    const char* commandPtr,
        ///< [IN] AT Command

    const char* interRespPtr,
        ///< [IN] Expected Intermediate Response

    const char* finalRespPtr,
        ///< [IN] Expected Final Response

    uint32_t timeout
        ///< [IN] Timeout
)
{
    LE_ASSERT(devRef == AtClientDeviceRef);

    int i = 0;

    CurrentCmdPtr = NULL;

    while ( i < NUM_ARRAY_MEMBERS(AtCommandList) )
    {
        if (strncmp(commandPtr,
            AtCommandList[i].commandNamePtr,
            strlen(AtCommandList[i].commandNamePtr)) == 0)
        {
            CurrentCmdPtr = &AtCommandList[i];
            *cmdRefPtr = (le_atClient_CmdRef_t) CurrentCmdPtr;
            return LE_OK;
        }
        i++;
    }

    return LE_FAULT;
}
Example #15
0
//--------------------------------------------------------------------------------------------------
static void PrintUsage()
{
    int idx;
    bool sandboxed = (getuid() != 0);
    const char * usagePtr[] = {
            "Usage of the riPinTest app is:",
            "   execInApp riPinTest riPinTest <take/release/pulse> [pulse duration in ms]"};

    for(idx = 0; idx < NUM_ARRAY_MEMBERS(usagePtr); idx++)
    {
        if(sandboxed)
        {
            LE_INFO("%s", usagePtr[idx]);
        }
        else
        {
            fprintf(stderr, "%s\n", usagePtr[idx]);
        }
    }
}
Example #16
0
//--------------------------------------------------------------------------------------------------
static void PrintUsage()
{
    int idx;
    bool sandboxed = (getuid() != 0);
    const char * usagePtr[] = {
            "Usage of the eCallTest bin is:",
            "   eCallTest <PSAP number>",
    };

    for(idx = 0; idx < NUM_ARRAY_MEMBERS(usagePtr); idx++)
    {
        if(sandboxed)
        {
            LE_INFO("%s", usagePtr[idx]);
        }
        else
        {
            fprintf(stderr, "%s\n", usagePtr[idx]);
        }
    }
}
Example #17
0
//--------------------------------------------------------------------------------------------------
static void PrintUsage()
{
    int idx;
    bool sandboxed = (getuid() != 0);
    const char * usagePtr[] = {
            "Usage of the 'trig' tool is:",
            "   trig <number of passengers>",
    };

    for(idx = 0; idx < NUM_ARRAY_MEMBERS(usagePtr); idx++)
    {
        if(sandboxed)
        {
            LE_INFO("%s", usagePtr[idx]);
        }
        else
        {
            fprintf(stderr, "%s\n", usagePtr[idx]);
        }
    }
}
Example #18
0
//--------------------------------------------------------------------------------------------------
static void PrintUsage()
{
    int idx;
    bool sandboxed = (getuid() != 0);
    const char * usagePtr[] = {
            "Usage of the voicePromptMcc2 test is:",
            "   \"execInApp voicePromptMcc2 voicePromptMcc2 <phone number>\" with .wav file",
            "   \"execInApp voicePromptMcc2 voicePromptMcc2 <phone number> AMR\" with .amr file"
    };

    for(idx = 0; idx < NUM_ARRAY_MEMBERS(usagePtr); idx++)
    {
        if(sandboxed)
        {
            LE_INFO("%s", usagePtr[idx]);
        }
        else
        {
            fprintf(stderr, "%s\n", usagePtr[idx]);
        }
    }
}
Example #19
0
//--------------------------------------------------------------------------------------------------
static void PrintUsage()
{
    int idx;
    bool sandboxed = (getuid() != 0);
    const char * usagePtr[] = {
            "Usage of the 'audioCallPbRecApp' tool is:",
            "   execInApp audioCallPbRecApp audioCallPbRecApp <tel number>",
            "",
    };

    for(idx = 0; idx < NUM_ARRAY_MEMBERS(usagePtr); idx++)
    {
        if(sandboxed)
        {
            LE_INFO("%s", usagePtr[idx]);
        }
        else
        {
            fprintf(stderr, "%s\n", usagePtr[idx]);
        }
    }
}
Example #20
0
// This is testing Traceable Recursive Mutex.
// The expected result is the same as "testRecursive", except "traceable" should also be true (1).
void testTraceableRecursive
(
    void
)
{
    le_mutex_Ref_t mutex1Ref = le_mutex_CreateTraceableRecursive("TracRecurMutex1");

    le_mutex_Ref_t mutexRefArray1[3] = {mutex1Ref, mutex1Ref, mutex1Ref};

    MutexRefArray_t mra1 = {NUM_ARRAY_MEMBERS(mutexRefArray1), mutexRefArray1};

    le_thread_Ref_t thread1Ref = le_thread_Create("Thread1", LockMutex, (void*)&mra1);

    le_thread_Start(thread1Ref);

    le_sem_Wait(SemaRef);

    // Keep the function around so that mutex refs are available.
    le_sem_Wait(SemaRef);

    LE_INFO("++++++++++++++++++  END OF testTraceableRecursive (shouldn't get here) +++++++++++++++++++++");
}
Example #21
0
//--------------------------------------------------------------------------------------------------
static void PrintUsage()
{
    int     idx;
    bool    sandboxed = (getuid() != 0);
    const   char * usagePtr[] =
            {
                "Usage of the 'mqttSender' tool is:",
                "   send <Key> <Value>"
            };

    for (idx = 0; idx < NUM_ARRAY_MEMBERS(usagePtr); idx++)
    {
        if(sandboxed)
        {
            LE_INFO("%s", usagePtr[idx]);
        }
        else
        {
            fprintf(stderr, "%s\n", usagePtr[idx]);
        }
    }
}
Example #22
0
//--------------------------------------------------------------------------------------------------
static void PrintUsage
(
    void
)
{
    int idx;
    const char * usagePtr[] = {
            "Usage of the 'simTest' application is:",
            "SIM allocation test: simTest create <ext/emb> <pin>",
            "SIM state test: simTest state <ext/emb> <pin>",
            "SIM authentification test: simTest auth <ext/emb> <pin> <puk>",
            "No SIM test: simTest nosim <ext/emb>",
            "SIM select: simTest select",
            "SIM lock test: simTest lock <emb/ext1/ext2/rem> <pin>",
            "SIM GetICCID test: simTest iccid <emb/ext1/ext2/rem>"
            "",
    };

    for(idx = 0; idx < NUM_ARRAY_MEMBERS(usagePtr); idx++)
    {
        Print((char*) usagePtr[idx]);
    }
}
Example #23
0
//--------------------------------------------------------------------------------------------------
static void ExecuteCommand
(
    const char * serviceNamePtr,   ///< [IN] Service to address
    const char * commandPtr,       ///< [IN] Command to execute (NULL = run default command)
    uint32_t numArgs
)
{
    int serviceIdx;

    for(serviceIdx = 0; serviceIdx < NUM_ARRAY_MEMBERS(Services); serviceIdx++)
    {
        const cm_Service_t * servicePtr = &Services[serviceIdx];

        if (strcmp(servicePtr->serviceNamePtr, serviceNamePtr) == 0)
        {
            LE_FATAL_IF( (NULL == servicePtr->commandHandler),
                "No command handler for service '%s'", servicePtr->serviceNamePtr);

            if (commandPtr == NULL)
            {
                LE_FATAL_IF( (NULL == servicePtr->defaultCommandPtr),
                    "No default command for service '%s'", servicePtr->serviceNamePtr);

                servicePtr->commandHandler(servicePtr->defaultCommandPtr, numArgs);
            }
            else
            {
                servicePtr->commandHandler(commandPtr, numArgs);
            }

            return;
        }
    }

    fprintf(stderr, "This service does not exist.\n");
    exit(EXIT_FAILURE);
}
Example #24
0
//--------------------------------------------------------------------------------------------------
le_result_t le_event_ServiceLoop
(
    void
)
{
    event_PerThreadRec_t* perThreadRecPtr = thread_GetEventRecPtr();
    int epollFd = CONTAINER_OF(perThreadRecPtr,
                               event_LinuxPerThreadRec_t,
                               portablePerThreadRec)->epollFd;
    struct epoll_event epollEventList[MAX_EPOLL_EVENTS];

    LE_DEBUG("perThreadRecPtr->liveEventCount is" "%" PRIu64, perThreadRecPtr->liveEventCount);

    // If there are still live events remaining in the queue, process a single event, then return
    if (perThreadRecPtr->liveEventCount > 0)
    {
        perThreadRecPtr->liveEventCount--;

        // This function assumes the mutex is NOT locked.
        event_ProcessOneEventReport(perThreadRecPtr);

        return LE_OK;
    }

    int result;

    do
    {
        // If no events on the queue, try to refill the event queue.
        // Ask epoll what, if anything, has happened on any of the file descriptors that we are
        // monitoring using our epoll fd.  (NOTE: This is non-blocking.)
        result = epoll_wait(epollFd, epollEventList, NUM_ARRAY_MEMBERS(epollEventList), 0);

        if ((result < 0) && (EINTR == errno))
        {
            // If epoll was interrupted,
            // Check if someone has cancelled the thread and terminate the thread now, if so.
            pthread_testcancel();
        }
    }
    while ((result < 0) && (EINTR == errno));

    // If something happened on one or more of the monitored file descriptors,
    if (result > 0)
    {
        int i;

        // Check if someone has cancelled the thread and terminate the thread now, if so.
        pthread_testcancel();

        // For each fd event reported by epoll_wait(), if it is any file descriptor other
        // than the eventfd (which is used to indicate that there is something on the
        // Event Queue), queue an Event Report to the Event Queue for that fd.
        for (i = 0; i < result; i++)
        {
            // Get the pointer that we registered with epoll_ctl(2) along with this fd.
            // The value of this pointer will either be NULL or a Safe Reference for an
            // FD Monitor object.  If it is NULL, then the Event Queue's eventfd is the
            // fd that experienced the event, which we will deal with later in this function.
            void* safeRef = epollEventList[i].data.ptr;

            if (safeRef != NULL)
            {
                fdMon_Report(safeRef, EPollToPoll(epollEventList[i].events));
            }
        }
    }
    // Otherwise, check if an epoll_wait() reported an error.
    // Interruptions are tested above, so this is always a fatal error.
    else if (result < 0)
    {
        LE_FATAL("epoll_wait() failed.  errno = %d.", errno);
    }
    // Otherwise, if epoll_wait() returned zero, then either this function was called without
    // waiting for the eventfd to be readable, or the eventfd was readable momentarily, but
    // something changed between the time the application code detected the readable condition
    // and now that made the eventfd not readable anymore.
    else
    {
        LE_DEBUG("epoll_wait() returned zero.");

        return LE_WOULD_BLOCK;
    }

    // Read the eventfd to reset it to zero so epoll stops telling us about it until more
    // are added.
    perThreadRecPtr->liveEventCount = fa_event_WaitForEvent(perThreadRecPtr);

    LE_DEBUG("perThreadRecPtr->liveEventCount is" "%" PRIu64, perThreadRecPtr->liveEventCount);

    // If events were read, process the top event
    if (perThreadRecPtr->liveEventCount > 0)
    {
        perThreadRecPtr->liveEventCount--;
        event_ProcessOneEventReport(perThreadRecPtr);

        return LE_OK;
    }
    else
    {
        return LE_WOULD_BLOCK;
    }
}
Example #25
0
//--------------------------------------------------------------------------------------------------
void fa_event_RunLoop
(
    void
)
{
    event_PerThreadRec_t* perThreadRecPtr = thread_GetEventRecPtr();

    int epollFd = CONTAINER_OF(perThreadRecPtr,
                               event_LinuxPerThreadRec_t,
                               portablePerThreadRec)->epollFd;
    struct epoll_event epollEventList[MAX_EPOLL_EVENTS];

    // Make sure nobody calls this function more than once in the same thread.
    LE_ASSERT(perThreadRecPtr->state == LE_EVENT_LOOP_INITIALIZED);

    // Update the state of the Event Loop.
    perThreadRecPtr->state = LE_EVENT_LOOP_RUNNING;

    // Enter the infinite loop itself.
    for (;;)
    {
        // Wait for something to happen on one of the file descriptors that we are monitoring
        // using our epoll fd.
        int result = epoll_wait(epollFd, epollEventList, NUM_ARRAY_MEMBERS(epollEventList), -1);

        // If something happened on one or more of the monitored file descriptors,
        if (result > 0)
        {
            int i;

            // Check if someone has cancelled the thread and terminate the thread now, if so.
            pthread_testcancel();

            // For each fd event reported by epoll_wait(), if it is any file descriptor other
            // than the eventfd (which is used to indicate that there is something on the
            // Event Queue), queue an Event Report to the Event Queue for that fd.
            for (i = 0; i < result; i++)
            {
                // Get the pointer that we registered with epoll_ctl(2) along with this fd.
                // The value of this pointer will either be NULL or a Safe Reference for an
                // FD Monitor object.  If it is NULL, then the Event Queue's eventfd is the
                // fd that experienced the event.
                void* safeRef = epollEventList[i].data.ptr;

                if (safeRef != NULL)
                {
                    fdMon_Report(safeRef, EPollToPoll(epollEventList[i].events));
                }
            }

            // Process all the Event Reports on the Event Queue.
            event_ProcessEventReports(perThreadRecPtr);
        }
        // Otherwise, if an epoll_wait() reported an error, hopefully it's just an interruption
        // by a signal (EINTR).  Anything else is a fatal error.
        else if (result < 0)
        {
            if (errno != EINTR)
            {
                LE_FATAL("epoll_wait() failed.  errno = %d.", errno);
            }

            // It was just EINTR, so we are okay to go back to sleep.  But first,
            // check if someone has cancelled the thread and terminate the thread now, if so.
            pthread_testcancel();
        }
        // Otherwise, if epoll_wait() returned zero, something has gone horribly wrong, because
        // it should never return zero.
        else
        {
            LE_FATAL("epoll_wait() returned zero!");
        }
    }
}
Example #26
0
    // test for bad file descriptor
    AtSession.devRef = le_atServer_Open(-1);
    LE_ASSERT(AtSession.devRef == NULL);

    // save a copy of fd and duplicate it before Opening the server after a call to
    // le_atServer_Open the file descriptor will be closed
    AtSession.fd = ServerData.connFd;

    // start the server
    AtSession.devRef = le_atServer_Open(dup(ServerData.connFd));
    LE_ASSERT(AtSession.devRef != NULL);
    sharedDataPtr->devRef = AtSession.devRef;

    // AT commands handling tests
    AtSession.cmdsCount = NUM_ARRAY_MEMBERS(atCmdCreation);

    // AT commands subscriptions
    while (i < AtSession.cmdsCount)
    {
        atCmdCreation[i].cmdRef = le_atServer_Create(atCmdCreation[i].atCmdPtr);
        LE_ASSERT(atCmdCreation[i].cmdRef != NULL);

        AtSession.atCmds[i] = atCmdCreation[i];

        LE_ASSERT(le_atServer_AddCommandHandler(atCmdCreation[i].cmdRef,
                                                atCmdCreation[i].handlerPtr,
                                                (void *)&AtSession) != NULL);

        i++;
    }
Example #27
0
//--------------------------------------------------------------------------------------------------
le_result_t fwDaemons_SigChildHandler
(
    pid_t pid               ///< [IN] Pid of the process that produced the SIGCHLD.
)
{
    // See which daemon produced this signal.
    DaemonObj_t* daemonObjPtr = NULL;

    int i;
    for (i = 0; i < NUM_ARRAY_MEMBERS(FrameworkDaemons); i++)
    {
        if (FrameworkDaemons[i].pid == pid)
        {
            daemonObjPtr = &(FrameworkDaemons[i]);

            // Mark this daemon as dead.
            daemonObjPtr->pid = -1;
            kill_Died(pid);

            break;
        }
    }

    if (daemonObjPtr == NULL)
    {
        return LE_NOT_FOUND;
    }

    // This child process is a framework daemon.
    // Reap the child now.
    int status = wait_ReapChild(pid);

    if (ShutdownIndex >= 0)
    {
        // We are in the midst of a shutdown sequence, continue the shutdown sequence.
        ShutdownIndex = ShutdownNextDaemon(ShutdownIndex);

        return LE_OK;
    }
    else
    {
        const char* daemonName = le_path_GetBasenamePtr(daemonObjPtr->path, "/");

        if (WIFEXITED(status))
        {
            // This was an unexpected error from one of the framework daemons.
            LE_EMERG("Framework daemon '%s' has exited with code %d.",
                     daemonName,
                     WEXITSTATUS(status));
        }
        else if (WIFSIGNALED(status))
        {
            // This was an unexpected error from one of the framework daemons.
            LE_EMERG("Framework daemon '%s' has been killed by a signal: %d.",
                     daemonName,
                     WTERMSIG(status));
        }
        else
        {
            // This was an unexpected error from one of the framework daemons.
            LE_EMERG("Framework daemon '%s' has died for an unknown reason (status = 0x%x).",
                     daemonName,
                     status);
        }

        return LE_FAULT;
    }
}
Example #28
0
//--------------------------------------------------------------------------------------------------
static void ConfigureGdb
(
    void
)
{
    le_cfg_ConnectService();
    le_cfgAdmin_ConnectService();

    // Get a write iterator to the application node.
    le_cfg_IteratorRef_t cfgIter = le_cfg_CreateWriteTxn("/apps");
    le_cfg_GoToNode(cfgIter, AppName);

    // Check if this is a temporary configuration that was previously created by this or a similar
    // tool.
    if (!le_cfg_IsEmpty(cfgIter, CFG_DEBUG_TOOL))
    {
        char debugTool[LIMIT_MAX_PATH_BYTES];

        // Don't need to check return code because the value is just informative and does not matter
        // if it is truncated.
        le_cfg_GetString(cfgIter, CFG_DEBUG_TOOL, debugTool, sizeof(debugTool), "");

        fprintf(stderr, "This application has already been configured for %s debug mode.\n", debugTool);
        exit(EXIT_FAILURE);
    }

    // Write into the config's debug tool node to indicate that this configuration has been modified.
    le_cfg_SetString(cfgIter, CFG_DEBUG_TOOL, "gdb");

    // Add 512K to the maxFileSytemBytes so that we can debug this app in sandboxed mode
    uint32_t maxBytes;

    maxBytes = le_cfg_GetInt(cfgIter, "maxFileSystemBytes", DEFAULT_LIMIT_MAX_FILE_SYSTEM_BYTES);
    maxBytes += ADD_FILE_SYSTEM_BYTES;  // add an additional 512KBytes
    LE_INFO("Resetting maxFileSystemBytes to %d bytes", maxBytes);
    le_cfg_SetInt(cfgIter, "maxFileSystemBytes", maxBytes);

    // Add gdbserver and libs to the app's 'requires/files' section.
    le_cfg_GoToNode(cfgIter, "requires/files");
    AddImportFiles(cfgIter, &GdbFilesImports, NUM_ARRAY_MEMBERS(GdbFilesImports));

    // Add /proc to the app's dirs section.
    le_cfg_GoToParent(cfgIter);
    le_cfg_GoToNode(cfgIter, "dirs");
    AddImportFiles(cfgIter, &GdbDirsImports, NUM_ARRAY_MEMBERS(GdbDirsImports));

    // Delete the list of processes.
    le_cfg_GoToParent(cfgIter);
    le_cfg_GoToParent(cfgIter);
    int i;
    for (i = 0; i < NumProcs; i++)
    {
        char nodePath[LIMIT_MAX_PATH_BYTES];

        int n = snprintf(nodePath, sizeof(nodePath), "procs/%s", ProcNames[i]);

        INTERNAL_ERR_IF(n >= sizeof(nodePath), "Node name is too long.");
        INTERNAL_ERR_IF(n < 0, "Format error.  %m");

        le_cfg_DeleteNode(cfgIter, nodePath);
    }

    le_cfg_CommitTxn(cfgIter);
}