Skip to content

Commit

Permalink
problem data: add function getting parsed osinfo
Browse files Browse the repository at this point in the history
The function loads os_info from chrooted directory if problem data
contains chrootdir item, otherwise loads the standard os_info.

If os_info item is not pressent, the function adds PRETTY_NAME
key with content of os_release item to the result map.

Related to #147

Signed-off-by: Jakub Filak <jfilak@redhat.com>
Signed-off-by: Martin Milata <mmilata@redhat.com>
  • Loading branch information
Jakub Filak authored and mmilata committed Apr 23, 2013
1 parent cc303ff commit d53838e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/include/problem_data.h
Expand Up @@ -92,6 +92,22 @@ char *problem_data_get_content_or_NULL(problem_data_t *problem_data, const char
/* Aborts if key is not found: */
char *problem_data_get_content_or_die(problem_data_t *problem_data, const char *key);

/**
@brief Loads key value pairs from os_info item in to the osinfo argument
The function expects that osinfo data are stored in format of os-release(5).
The Function at first step tries to load the data from os_info obtained from
chrooted directory. If the chrooted data doesn't exist the function loads
os_info from the data obtained from the standard path. If the os_info item is
missing the function adds PRETTY_NAME key with a content of the os_release
item.
@param problem_data Problem data object to read the os_info items
@param osinfo String string map where loaded key value pairs are saved
*/
void problem_data_get_osinfo(problem_data_t *problem_data, map_string_t *osinfo);

int problem_data_send_to_abrt(problem_data_t* problem_data);

/* Conversions between in-memory and on-disk formats */
Expand Down
30 changes: 30 additions & 0 deletions src/lib/problem_data.c
Expand Up @@ -555,3 +555,33 @@ gint cmp_problem_data(gconstpointer a, gconstpointer b, gpointer filename)

return 1;
}

static bool problem_data_get_osinfo_from_items(problem_data_t *problem_data,
map_string_t *osinfo, const char *osinfo_name, const char *release_name)
{
char *data = problem_data_get_content_or_NULL(problem_data, osinfo_name);
if (data)
{
parse_osinfo(data, osinfo);
return true;
}

data = problem_data_get_content_or_NULL(problem_data, release_name);
if (!data)
return false;

insert_map_string(osinfo, xstrdup(OSINFO_PRETTY_NAME), xstrdup(data));
return true;
}

void problem_data_get_osinfo(problem_data_t *problem_data, map_string_t *osinfo)
{
char *rootdir = problem_data_get_content_or_NULL(problem_data, FILENAME_ROOTDIR);
if (rootdir &&
problem_data_get_osinfo_from_items(problem_data, osinfo,
FILENAME_OS_INFO_IN_ROOTDIR, FILENAME_OS_RELEASE_IN_ROOTDIR))
return;

problem_data_get_osinfo_from_items(problem_data, osinfo,
FILENAME_OS_INFO, FILENAME_OS_RELEASE);
}

0 comments on commit d53838e

Please sign in to comment.