diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2014-07-16 11:32:07 -0500 |
---|---|---|
committer | Charles Kerr <charles.kerr@canonical.com> | 2014-07-16 11:32:07 -0500 |
commit | bf07982baca283c98624d4e64efbf0e641d019d0 (patch) | |
tree | 783ef181bba6a42cea297fc33569cfb83544467c | |
parent | a66b3889574a355fe900cbb8d8e5d39c82043de9 (diff) | |
download | ayatana-indicator-session-bf07982baca283c98624d4e64efbf0e641d019d0.tar.gz ayatana-indicator-session-bf07982baca283c98624d4e64efbf0e641d019d0.tar.bz2 ayatana-indicator-session-bf07982baca283c98624d4e64efbf0e641d019d0.zip |
use g_shell_unquote() to unmunge the values in /etc/os-release
-rw-r--r-- | src/service.c | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/src/service.c b/src/service.c index c9d1b13..034e67c 100644 --- a/src/service.c +++ b/src/service.c @@ -332,21 +332,22 @@ get_current_real_name (IndicatorSessionService * self) static GHashTable* get_os_release (void) { + static const char * const os_release = "/etc/os-release"; GHashTable * hash; GIOChannel * io; hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - if ((io = g_io_channel_new_file ("/etc/os-release", "r", NULL))) + if ((io = g_io_channel_new_file (os_release, "r", NULL))) { GString * key = g_string_new (NULL); for (;;) { GIOStatus status; - char *in; - GString * val; - gsize i; + char * in; + GError * error; + gchar * val; /* read a line */ status = g_io_channel_read_line_string (io, key, NULL, NULL); @@ -363,21 +364,19 @@ get_os_release (void) continue; *in++ = '\0'; - /* remove quotes and newlines; unescape escape sequences */ - val = g_string_new(in); - for (i=0; i<val->len; ) + /* unmunge the value component */ + g_strstrip(in); /* eat linefeed */ + error = NULL; + val = g_shell_unquote (in, &error); + if (error != NULL) { - if (val->str[i]=='\\' && ((i+1)<val->len)) /* unescape: skip 1, keep 1 */ - g_string_erase (val, i++, 1); - - else if ((val->str[i]=='\'') || (val->str[i]=='"') || (val->str[i]=='\n')) /* skip */ - g_string_erase (val, i, 1); - - else /* keep */ - i++; + g_warning("Unable to unquote \"%s\": %s", in, error->message); + val = g_strdup(in); + g_clear_error(&error); } - - g_hash_table_insert (hash, g_strdup(key->str), g_string_free(val,FALSE)); + + g_debug("from \"%s\": key [%s] val [%s]", os_release, key->str, val); + g_hash_table_insert (hash, g_strdup(key->str), val); /* hash owns val now */ } g_string_free(key, TRUE); |