Exemple #1
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;
    }
}
Exemple #2
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);
}
Exemple #3
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;
    }
}