示例#1
0
//--------------------------------------------------------------------------------------------------
static le_clk_Time_t GetConfigKickTimeoutInterval
(
    pid_t procId,  ///< The process id of the client
    uid_t appId    ///< The user id of the application
)
{
    char appName[LIMIT_MAX_APP_NAME_BYTES] = "";
    char procName[LIMIT_MAX_PROCESS_NAME_BYTES] = "";
    char configPath[LIMIT_MAX_PATH_BYTES] = "";

    const int defaultTimeout = TIMEOUT_DEFAULT;
    int proc_milliseconds = CFG_TIMEOUT_USE_DEFAULT;
    int app_milliseconds = CFG_TIMEOUT_USE_DEFAULT;

    if (LE_OK == user_GetAppName(appId, appName, sizeof(appName) ))
    {    // Check if there is a config for the process name first else check under the app name

        // It's a real app. Let's look up the config!
        LE_DEBUG("Getting configured watchdog timeout for app %s", appName);
        if (le_path_Concat("/", configPath, sizeof(configPath), "apps", appName,
                "watchdogTimeout", NULL) == LE_OK)
        {
            app_milliseconds = le_cfg_QuickGetInt(configPath, CFG_TIMEOUT_USE_DEFAULT);
        }

        if (LE_OK == GetProcessNameFromPid( procId, procName, sizeof(procName)))
        {
            // get the config
            configPath[0]='\0';
            LE_DEBUG("Getting configured watchdog timeout for process %s", procName);

            if(le_path_Concat("/", configPath, sizeof(configPath), "apps", appName, "procs",
                    procName, "watchdogTimeout", NULL) == LE_OK)
            {
                proc_milliseconds = le_cfg_QuickGetInt(configPath, CFG_TIMEOUT_USE_DEFAULT);
            }
        }

        // find a valid value starting at proc level and working up
        if (proc_milliseconds == CFG_TIMEOUT_USE_DEFAULT)
        {
            if (app_milliseconds == CFG_TIMEOUT_USE_DEFAULT)
            {
                proc_milliseconds = defaultTimeout;
                LE_WARN("No watchdog timeout configured for %s - using default %d ms", appName,
                  proc_milliseconds);
            }
            else
            {
                proc_milliseconds = app_milliseconds;
                LE_INFO("No watchdog timeout configured for process %s - using app timeout %d ms",
                    procName, proc_milliseconds);
            }
        }
        else
        {
            LE_DEBUG("Watchdog timeout configured for %s - timeout %d ms", procName,
              proc_milliseconds);
        }
    }
    else
    {
        // We have no idea what process is calling us, but we can set a default timeout
        // and play along.
        // TODO: Find a way to get the configured watchdog timeout duration for unsandboxed
        //       apps, which run as root.
        proc_milliseconds = defaultTimeout;
        LE_WARN("Unknown app with uid %u requested watchdog - using default timeout %d ms", appId,
          proc_milliseconds);
    }
    return MakeTimerInterval(proc_milliseconds);
}
示例#2
0
static void QuickFunctionTest()
{
    le_result_t result;

    char pathBuffer[STR_SIZE] = { 0 };

    LE_INFO("---- Quick Function Test -----------------------------------------------------------");

    {
        snprintf(pathBuffer, STR_SIZE, "%s/quickFunctions/strVal", TestRootDir);

        char strBuffer[513] = { 0 };

        result = le_cfg_QuickGetString(pathBuffer, strBuffer, 513, "");
        LE_FATAL_IF(result != LE_OK,
                    "Test: %s - Test failure, result == %s.",
                    TestRootDir,
                    LE_RESULT_TXT(result));
        LE_DEBUG("<<< Get STRING <%s>", strBuffer);

        le_cfg_QuickSetString(pathBuffer, "Something funny is going on!");

        result = le_cfg_QuickGetString(pathBuffer, strBuffer, 513, "");
        LE_FATAL_IF(result != LE_OK,
                    "Test: %s - Test failure, result == %s.",
                    TestRootDir,
                    LE_RESULT_TXT(result));
        LE_DEBUG("<<< Get STRING <%s>", strBuffer);
    }

    {
        snprintf(pathBuffer, STR_SIZE, "%s/quickFunctions/intVal", TestRootDir);

        int value = le_cfg_QuickGetInt(pathBuffer, 0);
        LE_DEBUG("<<< Get INT <%d>", value);

        le_cfg_QuickSetInt(pathBuffer, 1111);

        value = le_cfg_QuickGetInt(pathBuffer, 0);
        LE_DEBUG("<<< Get INT <%d>", value);
    }

    {
        snprintf(pathBuffer, STR_SIZE, "%s/quickFunctions/floatVal", TestRootDir);

        double value = le_cfg_QuickGetFloat(pathBuffer, 0.0);
        LE_DEBUG("<<< Get FLOAT <%f>", value);

        le_cfg_QuickSetFloat(pathBuffer, 1024.25);

        value = le_cfg_QuickGetFloat(pathBuffer, 0.0);
        LE_FATAL_IF(result != LE_OK,
                    "Test: %s - failure, result == %s.",
                    TestRootDir,
                    LE_RESULT_TXT(result));
        LE_DEBUG("<<< Get FLOAT <%f>", value);
    }

    {
        snprintf(pathBuffer, STR_SIZE, "%s/quickFunctions/boolVal", TestRootDir);

        bool value = le_cfg_QuickGetBool(pathBuffer, false);
        LE_DEBUG("<<< Get BOOL <%d>", value);

        le_cfg_QuickSetBool(pathBuffer, true);

        value = le_cfg_QuickGetBool(pathBuffer, false);
        LE_FATAL_IF(result != LE_OK,
                    "Test: %s - failure, result == %s.",
                    TestRootDir,
                    LE_RESULT_TXT(result));
        LE_DEBUG("<<< Get BOOL <%d>", value);
    }
}