summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cmumble.c3
-rw-r--r--src/util.c46
-rw-r--r--src/util.h3
3 files changed, 51 insertions, 1 deletions
diff --git a/src/cmumble.c b/src/cmumble.c
index ca8830f..0246789 100644
--- a/src/cmumble.c
+++ b/src/cmumble.c
@@ -292,8 +292,9 @@ cmumble_protocol_init(struct cmumble *cm)
cmumble_init_version(&version);
version.version = 0x010203;
version.release = PACKAGE_STRING;
- version.os = "Gentoo/Linux";
+ version.os = cmumble_get_os_name();
cmumble_send_version(cm, &version);
+ g_free(version.os);
cmumble_init_authenticate(&authenticate);
authenticate.username = (char *) cm->user_name;
diff --git a/src/util.c b/src/util.c
index b2549af..1f6fd41 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1,4 +1,7 @@
#include "util.h"
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
#include <glib.h>
gpointer
@@ -16,3 +19,46 @@ cmumble_find_by_id(GList *list, gsize member_offset, guint id)
return el;
}
+
+gchar *
+cmumble_get_os_name(void)
+{
+ FILE *f;
+ char *line = NULL;
+ char *os = NULL, *value, *end;
+ size_t key_len = strlen("PRETTY_NAME=");
+ size_t n;
+
+ f = fopen("/etc/os-release", "r");
+ if (f == NULL)
+ return NULL;
+
+ while (getline(&line, &n, f) != -1) {
+ if (strncmp("PRETTY_NAME=", line, key_len) == 0 && (n - key_len) > 1) {
+ value = &line[key_len];
+ if (strlen(value) == 0)
+ continue;
+
+ end = &value[strlen(value) - 1];
+ if (*end == '\n')
+ *end-- = '\0';
+
+ if (strlen(value) < 2)
+ continue;
+
+ if (value[0] == '"')
+ value++;
+
+ if (*end == '"')
+ *end = '\0';
+
+ os = strdup(value);
+ goto out;
+ }
+ }
+
+out:
+ free(line);
+ fclose(f);
+ return os;
+}
diff --git a/src/util.h b/src/util.h
index 6019fe5..e2d58c6 100644
--- a/src/util.h
+++ b/src/util.h
@@ -7,6 +7,9 @@
gpointer
cmumble_find_by_id(GList *list, gsize member_offset, guint id);
+char *
+cmumble_get_os_name(void);
+
static inline struct cmumble_user *
find_user(struct cmumble *cm, uint32_t session_id)
{