[PATCH] lib: fwts_release: call lsb_release rather than parsing raw data (LP: #1266823)

IvanHu ivan.hu at canonical.com
Thu Jan 9 06:49:10 UTC 2014


On 01/07/2014 11:41 PM, Colin King wrote:
> From: Colin Ian King <colin.king at canonical.com>
>
> Getting release info only works if /etc/lsb_release exists. Some Debian
> based systems may have this information fetched from other places, so instead
> parse the output from lsb_release -a to get the information as this provides
> the consistent output across Debian systems.
>
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
>   src/lib/src/fwts_release.c | 17 +++++++++++------
>   1 file changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/src/lib/src/fwts_release.c b/src/lib/src/fwts_release.c
> index 24f8789..f82ab4e 100644
> --- a/src/lib/src/fwts_release.c
> +++ b/src/lib/src/fwts_release.c
> @@ -35,7 +35,7 @@ static void fwts_release_field_get(char *needle, char *delimiter, char *text, ch
>   	if (strstr(text, needle) == NULL)
>   		return;
>   	str++;
> -	while (*str == ' ')
> +	while (*str == ' ' || *str == '\t')
>   		str++;
>
>   	if (*str)
> @@ -53,10 +53,10 @@ void fwts_release_get_debian(fwts_list *list, fwts_release *release)
>   	fwts_list_foreach(item, list) {
>   		char *line = fwts_text_list_text(item);
>
> -		fwts_release_field_get("DISTRIB_ID", "=", line, &release->distributor);
> -		fwts_release_field_get("DISTRIB_RELEASE", "=", line, &release->description);
> -		fwts_release_field_get("DISTRIB_CODENAME", "=", line, &release->release);
> -		fwts_release_field_get("DISTRIB_DESCRIPTION", "=", line, &release->codename);
> +		fwts_release_field_get("Distributor ID:", ":", line, &release->distributor);

Just minor thing,
The Field should be changed to "Distributor ID", remove the delimiter.

> +		fwts_release_field_get("Release", ":", line, &release->description);
> +		fwts_release_field_get("Codename", ":", line, &release->release);
> +		fwts_release_field_get("Description", ":", line, &release->codename);
>   	}
>   }
>
> @@ -78,6 +78,7 @@ fwts_release *fwts_release_get(void)
>   {
>   	fwts_list *list;
>   	fwts_release *release;
> +	int status;
>
>   	if ((release = calloc(1, sizeof(fwts_release))) == NULL)
>   		return NULL;
> @@ -86,7 +87,11 @@ fwts_release *fwts_release_get(void)
>   	 *  For the moment, check in /etc/lsb-release, we need to add in
>   	 *  support for different distros too.
>   	 */
> -	if ((list = fwts_file_open_and_read("/etc/lsb-release")) != NULL) {
> +	if (fwts_pipe_exec("lsb_release -a", &list, &status) != FWTS_OK) {
> +		free(release);
> +		return NULL;
> +	}
> +	if (list) {
>   		fwts_release_get_debian(list, release);
>   		fwts_list_free(list, free);
>   	}
>




More information about the fwts-devel mailing list