示例#1
0
struct sr_operating_system *
sr_operating_system_from_json(struct sr_json_value *root, char **error_message)
{
    if (!JSON_CHECK_TYPE(root, SR_JSON_OBJECT, "operating system"))
        return NULL;

    struct sr_operating_system *result = sr_operating_system_new();

    bool success =
        JSON_READ_STRING(root, "name", &result->name) &&
        JSON_READ_STRING(root, "version", &result->version) &&
        JSON_READ_STRING(root, "architecture", &result->architecture) &&
        JSON_READ_UINT64(root, "uptime", &result->uptime);

    /* desktop is optional - failure is not fatal */
    JSON_READ_STRING(root, "desktop", &result->desktop);
    /* variant is optional - failure is not fatal */
    JSON_READ_STRING(root, "variant", &result->variant);

    if (!success)
    {
        sr_operating_system_free(result);
        return NULL;
    }

    return result;
}
示例#2
0
文件: abrt.c 项目: airtimemedia/satyr
struct sr_operating_system *
sr_abrt_operating_system_from_dir(const char *directory,
                                  char **error_message)
{
    bool success = false;
    struct sr_operating_system *os = sr_operating_system_new();

    char *osinfo_contents = file_contents(directory, "os_info", error_message);
    if (osinfo_contents)
    {
        success = sr_operating_system_parse_etc_os_release(osinfo_contents, os);
        free(osinfo_contents);
    }

    /* fall back to os_release if parsing os_info fails */
    if (!success)
    {
        char *release_contents = file_contents(directory, "os_release",
                                               error_message);
        if (release_contents)
        {
            success = sr_operating_system_parse_etc_system_release(release_contents,
                                                                   &os->name,
                                                                   &os->version);
            free(release_contents);
        }
    }

    if (!success)
    {
        sr_operating_system_free(os);
        *error_message = sr_strdup("Failed to parse operating system release string");
        return NULL;
    }

    os->architecture = file_contents(directory, "architecture", error_message);
    if (!os->architecture)
    {
        sr_operating_system_free(os);
        return NULL;
    }

    /* optional - failure is not fatal */
    os->desktop = desktop_from_dir(directory, error_message);

    return os;
}