diff options
Diffstat (limited to 'modules/computer')
-rw-r--r-- | modules/computer/alsa.c | 4 | ||||
-rw-r--r-- | modules/computer/boots.c | 8 | ||||
-rw-r--r-- | modules/computer/display.c | 169 | ||||
-rw-r--r-- | modules/computer/environment.c | 4 | ||||
-rw-r--r-- | modules/computer/filesystem.c | 13 | ||||
-rw-r--r-- | modules/computer/groups.c | 4 | ||||
-rw-r--r-- | modules/computer/languages.c | 262 | ||||
-rw-r--r-- | modules/computer/loadavg.c | 4 | ||||
-rw-r--r-- | modules/computer/memory.c | 4 | ||||
-rw-r--r-- | modules/computer/memory_usage.c | 125 | ||||
-rw-r--r-- | modules/computer/modules.c | 471 | ||||
-rw-r--r-- | modules/computer/os.c | 249 | ||||
-rw-r--r-- | modules/computer/ubuntu_flavors.c | 90 | ||||
-rw-r--r-- | modules/computer/uptime.c | 4 | ||||
-rw-r--r-- | modules/computer/users.c | 4 |
15 files changed, 1009 insertions, 406 deletions
diff --git a/modules/computer/alsa.c b/modules/computer/alsa.c index 00c1fceb..f74d2752 100644 --- a/modules/computer/alsa.c +++ b/modules/computer/alsa.c @@ -1,10 +1,10 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> + * Copyright (C) 2003-2006 L. A. F. Pereira <l@tia.mat.br> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. + * the Free Software Foundation, version 2 or later. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of diff --git a/modules/computer/boots.c b/modules/computer/boots.c index ba458242..52c122e4 100644 --- a/modules/computer/boots.c +++ b/modules/computer/boots.c @@ -1,10 +1,10 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@hardinfo.org> + * Copyright (C) 2003-2007 L. A. F. Pereira <l@tia.mat.br> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. + * the Free Software Foundation, version 2 or later. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -21,6 +21,8 @@ #include "hardinfo.h" #include "computer.h" +extern void scan_os(gboolean reload); + void scan_boots_real(void) { @@ -35,7 +37,7 @@ scan_boots_real(void) else return; - spawned = g_spawn_command_line_sync("last", + spawned = hardinfo_spawn_command_line_sync("last", &out, &err, NULL, NULL); if (spawned && out != NULL) { p = out; diff --git a/modules/computer/display.c b/modules/computer/display.c index 61eac4eb..98cb7bf7 100644 --- a/modules/computer/display.c +++ b/modules/computer/display.c @@ -1,10 +1,10 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@hardinfo.org> + * Copyright (C) 2003-2007 L. A. F. Pereira <l@tia.mat.br> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. + * the Free Software Foundation, version 2 or later. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -21,131 +21,54 @@ #include "hardinfo.h" #include "computer.h" -static void -get_glx_info(DisplayInfo *di) -{ - gchar *output; - if (g_spawn_command_line_sync("glxinfo", &output, NULL, NULL, NULL)) { - gchar **output_lines; - gint i = 0; - - for (output_lines = g_strsplit(output, "\n", 0); - output_lines && output_lines[i]; - i++) { - if (strstr(output_lines[i], "OpenGL")) { - gchar **tmp = g_strsplit(output_lines[i], ":", 0); - - tmp[1] = g_strchug(tmp[1]); - - get_str("OpenGL vendor str", di->ogl_vendor); - get_str("OpenGL renderer str", di->ogl_renderer); - get_str("OpenGL version str", di->ogl_version); - - g_strfreev(tmp); - } else if (strstr(output_lines[i], "direct rendering: Yes")) { - di->dri = TRUE; - } - } - - g_free(output); - g_strfreev(output_lines); - - if (!di->ogl_vendor) - di->ogl_vendor = _("(Unknown)"); - if (!di->ogl_renderer) - di->ogl_renderer = _("(Unknown)"); - if (!di->ogl_version) - di->ogl_version = _("(Unknown)"); - - } else { - di->ogl_vendor = di->ogl_renderer = di->ogl_version = _("(Unknown)"); +DisplayInfo *computer_get_display(void) { + DisplayInfo *di = g_new0(DisplayInfo, 1); + wl_info *wl = get_walyand_info(); + xinfo *xi = xinfo_get_info(); + xrr_info *xrr = xi->xrr; + glx_info *glx = xi->glx; + + di->width = di->height = 0; + if (xrr->screen_count > 0) { + di->width = xrr->screens[0].px_width; + di->height = xrr->screens[0].px_height; } - -} - -static void -get_x11_info(DisplayInfo *di) -{ - gchar *output; - - if (g_spawn_command_line_sync("xdpyinfo", &output, NULL, NULL, NULL)) { - gchar **output_lines, **old; - - output_lines = g_strsplit(output, "\n", 0); - g_free(output); - - old = output_lines; - while (*output_lines) { - gchar **tmp = g_strsplit(*output_lines, ":", 2); - output_lines++; - - if (tmp[1] && tmp[0]) { - tmp[1] = g_strchug(tmp[1]); - - get_str("vendor string", di->vendor); - get_str("X.Org version", di->version); - get_str("XFree86 version", di->version); - get_str("name of display", di->display_name); - - if (g_str_has_prefix(tmp[0], "number of extensions")) { - int n; - - di->extensions = g_strdup(""); - - for (n = atoi(tmp[1]); n; n--) { - di->extensions = h_strconcat(di->extensions, - g_strstrip(*(++output_lines)), - "=\n", - NULL); - } - g_strfreev(tmp); - - break; - } - } - - g_strfreev(tmp); - } - - g_strfreev(old); + di->vendor = xi->vendor; + di->session_type = wl->xdg_session_type; + + if (strcmp(di->session_type, "x11") == 0 ) { + if (xi->nox) { + di->display_server = g_strdup(_("(Unknown)")); + /* assumed x11 previously, because it wasn't set */ + free(wl->xdg_session_type); + di->session_type = wl->xdg_session_type = NULL; + } else if (xi->vendor && xi->version) + di->display_server = g_strdup_printf("%s %s", xi->vendor, xi->version ); + else if (xi->vendor && xi->release_number) + di->display_server = g_strdup_printf("[X11] %s %s", xi->vendor, xi->release_number ); + else + di->display_server = g_strdup("X11"); + } else + if (strcmp(di->session_type, "wayland") == 0 ) { + di->display_server = g_strdup("Wayland"); + } else + if (strcmp(di->session_type, "mir") == 0 ) { + di->display_server = g_strdup("Mir"); + } else { + di->display_server = g_strdup(_("(Unknown)")); } - GdkScreen *screen = gdk_screen_get_default(); - - if (screen && GDK_IS_SCREEN(screen)) { - gint n_monitors = gdk_screen_get_n_monitors(screen); - gint i; - - di->monitors = NULL; - for (i = 0; i < n_monitors; i++) { - GdkRectangle rect; - - gdk_screen_get_monitor_geometry(screen, i, &rect); - - di->monitors = h_strdup_cprintf(_("Monitor %d=%dx%d pixels\n"), - di->monitors, i, rect.width, rect.height); - } - } else { - di->monitors = ""; - } + di->xi = xi; + di->wl = wl; + return di; } -DisplayInfo * -computer_get_display(void) -{ - DisplayInfo *di = g_new0(DisplayInfo, 1); - - GdkScreen *screen = gdk_screen_get_default(); - - if (screen && GDK_IS_SCREEN(screen)) { - di->width = gdk_screen_get_width(screen); - di->height = gdk_screen_get_height(screen); - } else { - di->width = di->height = 0; +void computer_free_display(DisplayInfo *di) { + /* fyi: DisplayInfo is in computer.h */ + if (di) { + free(di->display_server); + xinfo_free(di->xi); + wl_free(di->wl); + free(di); } - - get_glx_info(di); - get_x11_info(di); - - return di; } diff --git a/modules/computer/environment.c b/modules/computer/environment.c index dc0fb6f3..2f29c861 100644 --- a/modules/computer/environment.c +++ b/modules/computer/environment.c @@ -1,10 +1,10 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2008 Leandro A. F. Pereira <leandro@hardinfo.org> + * Copyright (C) 2003-2008 L. A. F. Pereira <l@tia.mat.br> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. + * the Free Software Foundation, version 2 or later. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of diff --git a/modules/computer/filesystem.c b/modules/computer/filesystem.c index 397dc636..e9c84811 100644 --- a/modules/computer/filesystem.c +++ b/modules/computer/filesystem.c @@ -1,10 +1,10 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> + * Copyright (C) 2003-2006 L. A. F. Pereira <l@tia.mat.br> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. + * the Free Software Foundation, version 2 or later. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -71,6 +71,8 @@ scan_filesystems(void) gchar *strhash; + gboolean rw = strstr(tmp[3], "rw") != NULL; + strreplacechr(tmp[0], "#", '_'); strhash = g_strdup_printf("[%s]\n" "%s=%s\n" @@ -81,7 +83,7 @@ scan_filesystems(void) "%s=%s\n", tmp[0], /* path */ _("Filesystem"), tmp[2], - _("Mounted As"), ( strstr(tmp[3], "rw") != NULL) ? _("Read-Write") : _("Read-Only"), + _("Mounted As"), rw ? _("Read-Write") : _("Read-Only"), _("Mount Point"), tmp[1], _("Size"), strsize, _("Used"), strused, @@ -90,9 +92,10 @@ scan_filesystems(void) moreinfo_add_with_prefix("COMP", key, strhash); g_free(key); - fs_list = h_strdup_cprintf("$FS%d$%s=%.2f %% (%s of %s)|%s\n", + fs_list = h_strdup_cprintf("$FS%d$%s%s=%.2f %% (%s of %s)|%s\n", fs_list, - count, tmp[0], use_ratio, stravail, strsize, tmp[1]); + count, tmp[0], rw ? "" : "π", + use_ratio, stravail, strsize, tmp[1]); g_free(strsize); g_free(stravail); diff --git a/modules/computer/groups.c b/modules/computer/groups.c index 244b8000..9371e211 100644 --- a/modules/computer/groups.c +++ b/modules/computer/groups.c @@ -1,10 +1,10 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2012 Leandro A. F. Pereira <leandro@hardinfo.org> + * Copyright (C) 2012 L. A. F. Pereira <l@tia.mat.br> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. + * the Free Software Foundation, version 2 or later. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of diff --git a/modules/computer/languages.c b/modules/computer/languages.c index d4681839..b2d4910f 100644 --- a/modules/computer/languages.c +++ b/modules/computer/languages.c @@ -1,10 +1,10 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@hardinfo.org> + * Copyright (C) 2003-2007 L. A. F. Pereira <l@tia.mat.br> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. + * the Free Software Foundation, version 2 or later. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -22,113 +22,161 @@ #include "computer.h" #include "cpu_util.h" /* for UNKIFNULL() */ -void -scan_languages(OperatingSystem * os) -{ - FILE *locale; - gchar buf[512], *retval = NULL; - - locale = popen("locale -va && echo", "r"); - if (!locale) - return; - +typedef struct { gchar name[32]; - gchar *title = NULL, - *source = NULL, - *address = NULL, - *email = NULL, - *language = NULL, - *territory = NULL, - *revision = NULL, - *date = NULL, - *codeset = NULL; - - while (fgets(buf, 512, locale)) { - if (!strncmp(buf, "locale:", 7)) { - sscanf(buf, "locale: %s", name); - (void)fgets(buf, 128, locale); - } else if (strchr(buf, '|')) { - gchar **tmp = g_strsplit(buf, "|", 2); - - tmp[0] = g_strstrip(tmp[0]); - - if (tmp[1]) { - tmp[1] = g_strstrip(tmp[1]); - - get_str("title", title); - get_str("source", source); - get_str("address", address); - get_str("email", email); - get_str("language", language); - get_str("territory", territory); - get_str("revision", revision); - get_str("date", date); - get_str("codeset", codeset); - } - - g_strfreev(tmp); - } else { - gchar *currlocale; - - retval = h_strdup_cprintf("$%s$%s=%s\n", retval, name, name, title); - - UNKIFNULL(title); - UNKIFNULL(source); - UNKIFNULL(address); - UNKIFNULL(email); - UNKIFNULL(language); - UNKIFNULL(territory); - UNKIFNULL(revision); - UNKIFNULL(date); - UNKIFNULL(codeset); - - /* values may have & */ - title = hardinfo_clean_value(title, 1); - source = hardinfo_clean_value(source, 1); - address = hardinfo_clean_value(address, 1); - email = hardinfo_clean_value(email, 1); - language = hardinfo_clean_value(language, 1); - territory = hardinfo_clean_value(territory, 1); - - currlocale = g_strdup_printf("[%s]\n" - /* Name */ "%s=%s (%s)\n" - /* Source */ "%s=%s\n" - /* Address */ "%s=%s\n" - /* Email */ "%s=%s\n" - /* Language */ "%s=%s\n" - /* Territory */"%s=%s\n" - /* Revision */ "%s=%s\n" - /* Date */ "%s=%s\n" - /* Codeset */ "%s=%s\n", - _("Locale Information"), - _("Name"), name, title, - _("Source"), source, - _("Address"), address, - _("E-mail"), email, - _("Language"), language, - _("Territory"), territory, - _("Revision"), revision, - _("Date"), date, - _("Codeset"), codeset ); - - moreinfo_add_with_prefix("COMP", name, currlocale); - - g_free(title); - g_free(source); - g_free(address); - g_free(email); - g_free(language); - g_free(territory); - g_free(revision); - g_free(date); - g_free(codeset); - - title = source = address = email = language = territory = \ - revision = date = codeset = NULL; - } + gchar *title, + *source, + *address, + *email, + *language, + *territory, + *revision, + *date, + *codeset; +} locale_info; + +void locale_info_free(locale_info *s) { + if (s) { + g_free(s->title); + g_free(s->source); + g_free(s->address); + g_free(s->email); + g_free(s->language); + g_free(s->territory); + g_free(s->revision); + g_free(s->date); + g_free(s->codeset); + free(s); } +} - fclose(locale); +/* TODO: use info_* */ +gchar *locale_info_section(locale_info *s) { + gchar *name = g_strdup(s->name); + gchar *title = g_strdup(s->title), + *source = g_strdup(s->source), + *address = g_strdup(s->address), + *email = g_strdup(s->email), + *language = g_strdup(s->language), + *territory = g_strdup(s->territory), + *revision = g_strdup(s->revision), + *date = g_strdup(s->date), + *codeset = g_strdup(s->codeset); + + UNKIFNULL(title); + UNKIFNULL(source); + UNKIFNULL(address); + UNKIFNULL(email); + UNKIFNULL(language); + UNKIFNULL(territory); + UNKIFNULL(revision); + UNKIFNULL(date); + UNKIFNULL(codeset); + + /* values may have & */ + title = hardinfo_clean_value(title, 1); + source = hardinfo_clean_value(source, 1); + address = hardinfo_clean_value(address, 1); + email = hardinfo_clean_value(email, 1); + language = hardinfo_clean_value(language, 1); + territory = hardinfo_clean_value(territory, 1); + + gchar *ret = g_strdup_printf("[%s]\n" + /* Name */ "%s=%s (%s)\n" + /* Source */ "%s=%s\n" + /* Address */ "%s=%s\n" + /* Email */ "%s=%s\n" + /* Language */ "%s=%s\n" + /* Territory */"%s=%s\n" + /* Revision */ "%s=%s\n" + /* Date */ "%s=%s\n" + /* Codeset */ "%s=%s\n", + _("Locale Information"), + _("Name"), name, title, + _("Source"), source, + _("Address"), address, + _("E-mail"), email, + _("Language"), language, + _("Territory"), territory, + _("Revision"), revision, + _("Date"), date, + _("Codeset"), codeset ); + g_free(name); + g_free(title); + g_free(source); + g_free(address); + g_free(email); + g_free(language); + g_free(territory); + g_free(revision); + g_free(date); + g_free(codeset); + return ret; +} - os->languages = retval; +void +scan_languages(OperatingSystem * os) +{ + gboolean spawned; + gchar *out, *err, *p, *next_nl; + + gchar *ret = NULL; + locale_info *curr = NULL; + int last = 0; + + spawned = hardinfo_spawn_command_line_sync("locale -va", + &out, &err, NULL, NULL); + if (spawned) { + ret = g_strdup(""); + p = out; + while(1) { + /* `locale -va` doesn't end the last locale block + * with an \n, which makes this more complicated */ + next_nl = strchr(p, '\n'); + if (next_nl == NULL) + next_nl = strchr(p, 0); + last = (*next_nl == 0) ? 1 : 0; + strend(p, '\n'); + if (strncmp(p, "locale:", 7) == 0) { + curr = g_new0(locale_info, 1); + sscanf(p, "locale: %s", curr->name); + /* TODO: 'directory:' and 'archive:' */ + } else if (strchr(p, '|')) { + do {/* get_str() has a continue in it, + * how fn frustrating that was to figure out */ + gchar **tmp = g_strsplit(p, "|", 2); + tmp[0] = g_strstrip(tmp[0]); + if (tmp[1]) { + tmp[1] = g_strstrip(tmp[1]); + get_str("title", curr->title); + get_str("source", curr->source); + get_str("address", curr->address); + get_str("email", curr->email); + get_str("language", curr->language); + get_str("territory", curr->territory); + get_str("revision", curr->revision); + get_str("date", curr->date); + get_str("codeset", curr->codeset); + } + g_strfreev(tmp); + } while (0); + } else if (strstr(p, "------")) { + /* do nothing */ + } else if (curr) { + /* a blank line is the end of a locale */ + gchar *li_str = locale_info_section(curr); + gchar *clean_title = hardinfo_clean_value(curr->title, 0); /* may contain & */ + ret = h_strdup_cprintf("$%s$%s=%s\n", ret, curr->name, curr->name, clean_title); + moreinfo_add_with_prefix("COMP", g_strdup(curr->name), li_str); /* becomes owned by moreinfo */ + locale_info_free(curr); + curr = NULL; + g_free(clean_title); + } + if (last) break; + p = next_nl + 1; + } + g_free(out); + g_free(err); + } + os->languages = ret; } diff --git a/modules/computer/loadavg.c b/modules/computer/loadavg.c index 7311dbf0..802ae2aa 100644 --- a/modules/computer/loadavg.c +++ b/modules/computer/loadavg.c @@ -1,10 +1,10 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> + * Copyright (C) 2003-2006 L. A. F. Pereira <l@tia.mat.br> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. + * the Free Software Foundation, version 2 or later. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of diff --git a/modules/computer/memory.c b/modules/computer/memory.c index dc8599c2..994e4040 100644 --- a/modules/computer/memory.c +++ b/modules/computer/memory.c @@ -1,10 +1,10 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> + * Copyright (C) 2003-2006 L. A. F. Pereira <l@tia.mat.br> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. + * the Free Software Foundation, version 2 or later. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of diff --git a/modules/computer/memory_usage.c b/modules/computer/memory_usage.c new file mode 100644 index 00000000..12c62fe7 --- /dev/null +++ b/modules/computer/memory_usage.c @@ -0,0 +1,125 @@ +/* + * HardInfo - Displays System Information + * Copyright (C) 2003-2007 L. A. F. Pereira <l@tia.mat.br> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 or later. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <string.h> +#include "devices.h" + +GHashTable *memlabels = NULL; + +void scan_memory_do(void) +{ + gchar **keys, *tmp, *tmp_label, *trans_val; + static gint offset = -1; + gint i; + + if (offset == -1) { + /* gah. linux 2.4 adds three lines of data we don't need in + * /proc/meminfo. + * The lines look something like this: + * total: used: free: shared: buffers: cached: + * Mem: 3301101568 1523159040 1777942528 0 3514368 1450356736 + * Swap: 0 0 0 + */ + gchar *os_kernel = module_call_method("computer::getOSKernel"); + if (os_kernel) { + offset = strstr(os_kernel, "Linux 2.4") ? 3 : 0; + g_free(os_kernel); + } else { + offset = 0; + } + } + + g_file_get_contents("/proc/meminfo", &meminfo, NULL, NULL); + + keys = g_strsplit(meminfo, "\n", 0); + + g_free(meminfo); + g_free(lginterval); + + meminfo = g_strdup(""); + lginterval = g_strdup(""); + + for (i = offset; keys[i]; i++) { + gchar **newkeys = g_strsplit(keys[i], ":", 0); + + if (!newkeys[0]) { + g_strfreev(newkeys); + break; + } + + g_strstrip(newkeys[0]); + g_strstrip(newkeys[1]); + + /* try to find a localizable label */ + tmp = g_hash_table_lookup(memlabels, newkeys[0]); + if (tmp) + tmp_label = _(tmp); + else + tmp_label = ""; /* or newkeys[0] */ + /* although it doesn't matter... */ + + if (strstr(newkeys[1], "kB")) { + trans_val = g_strdup_printf("%d %s", atoi(newkeys[1]), _("KiB") ); + } else { + trans_val = strdup(newkeys[1]); + } + + moreinfo_add_with_prefix("DEV", newkeys[0], g_strdup(trans_val)); + + tmp = g_strconcat(meminfo, newkeys[0], "=", trans_val, "|", tmp_label, "\n", NULL); + g_free(meminfo); + meminfo = tmp; + + g_free(trans_val); + + tmp = g_strconcat(lginterval, + "UpdateInterval$", newkeys[0], "=1000\n", NULL); + g_free(lginterval); + lginterval = tmp; + + g_strfreev(newkeys); + } + g_strfreev(keys); +} + +void init_memory_labels(void) +{ + static const struct { + char *proc_label; + char *real_label; + } proc2real[] = { + { "MemTotal", N_("Total Memory") }, + { "MemFree", N_("Free Memory") }, + { "SwapCached", N_("Cached Swap") }, + { "HighTotal", N_("High Memory") }, + { "HighFree", N_("Free High Memory") }, + { "LowTotal", N_("Low Memory") }, + { "LowFree", N_("Free Low Memory") }, + { "SwapTotal", N_("Virtual Memory") }, + { "SwapFree", N_("Free Virtual Memory") }, + { NULL }, + }; + gint i; + + memlabels = g_hash_table_new(g_str_hash, g_str_equal); + + for (i = 0; proc2real[i].proc_label; i++) { + g_hash_table_insert(memlabels, proc2real[i].proc_label, + _(proc2real[i].real_label)); + } +} diff --git a/modules/computer/modules.c b/modules/computer/modules.c index df876e3a..14028362 100644 --- a/modules/computer/modules.c +++ b/modules/computer/modules.c @@ -1,10 +1,10 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> + * Copyright (C) 2003-2006 L. A. F. Pereira <l@tia.mat.br> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. + * the Free Software Foundation, version 2 or later. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -17,161 +17,384 @@ */ #include <string.h> +#include <sys/utsname.h> +#include <json-glib/json-glib.h> -#include "hardinfo.h" +#include "syncmanager.h" #include "computer.h" #include "cpu_util.h" /* for STRIFNULL() */ +#include "hardinfo.h" -#define GET_STR(field_name,ptr) \ - if (!ptr && strstr(tmp[0], field_name)) { \ - ptr = g_markup_escape_text(g_strstrip(tmp[1]), strlen(tmp[1])); \ - g_strfreev(tmp); \ - continue; \ - } +#define GET_STR(field_name, ptr) \ + if (!ptr && strstr(tmp[0], field_name)) { \ + ptr = g_markup_escape_text(g_strstrip(tmp[1]), strlen(tmp[1])); \ + g_strfreev(tmp); \ + continue; \ + } GHashTable *_module_hash_table = NULL; +static gchar *kernel_modules_dir = NULL; + +enum icons { + ICON_INVALID = 0, + + ICON_AUDIO, + ICON_BLUETOOTH, + ICON_CAMERA_WEB, + ICON_CDROM, + ICON_CRYPTOHASH, + ICON_DEVICES, + ICON_HDD, + ICON_INPUTDEVICES, + ICON_JOYSTICK, + ICON_KEYBOARD, + ICON_MEDIA_FLOPPY, + ICON_MEDIA_REMOVABLE, + ICON_MEMORY, + ICON_MONITOR, + ICON_MOUSE, + ICON_NETWORK, + ICON_NETWORK_CONNECTIONS, + ICON_NETWORK_INTERFACE, + ICON_THERM, + ICON_USB, + ICON_WIRELESS, + + ICON_MAX, +}; + +static const char *icon_table[ICON_MAX] = { + [ICON_AUDIO] = "audio", + [ICON_BLUETOOTH] = "bluetooth", + [ICON_CAMERA_WEB] = "camera-web", + [ICON_CDROM] = "cdrom", + [ICON_CRYPTOHASH] = "cryptohash", + [ICON_DEVICES] = "devices", + [ICON_HDD] = "hdd", + [ICON_INPUTDEVICES] = "inputdevices", + [ICON_JOYSTICK] = "joystick", + [ICON_KEYBOARD] = "keyboard", + [ICON_MEDIA_FLOPPY] = "media-floppy", + [ICON_MEDIA_REMOVABLE] = "media-removable", + [ICON_MEMORY] = "memory", + [ICON_MONITOR] = "monitor", + [ICON_MOUSE] = "mouse", + [ICON_NETWORK] = "network", + [ICON_NETWORK_CONNECTIONS] = "network-connections", + [ICON_NETWORK_INTERFACE] = "network-interface", + [ICON_THERM] = "therm", + [ICON_USB] = "usb", + [ICON_WIRELESS] = "wireless", +}; + +/* Keep this sorted by reverse strlen(dir)! */ +static const struct { + const gchar *dir; + enum icons icon; +} modules_icons[] = { + {"drivers/input/joystick/", ICON_JOYSTICK}, + {"drivers/input/keyboard/", ICON_KEYBOARD}, + {"drivers/media/usb/uvc/", ICON_CAMERA_WEB}, + {"drivers/net/wireless/", ICON_WIRELESS}, + {"drivers/net/ethernet/", ICON_NETWORK_INTERFACE}, + {"drivers/input/mouse/", ICON_MOUSE}, + {"drivers/bluetooth/", ICON_BLUETOOTH}, + {"drivers/media/v4l", ICON_CAMERA_WEB}, + {"arch/x86/crypto/", ICON_CRYPTOHASH}, + {"drivers/crypto/", ICON_CRYPTOHASH}, + {"net/bluetooth/", ICON_BLUETOOTH}, + {"drivers/input/", ICON_INPUTDEVICES}, + {"drivers/cdrom/", ICON_CDROM}, + {"drivers/hwmon/", ICON_THERM}, + {"drivers/iommu/", ICON_MEMORY}, + {"net/wireless/", ICON_WIRELESS}, + {"drivers/nvme/", ICON_HDD}, + {"net/ethernet/", ICON_NETWORK_INTERFACE}, + {"drivers/scsi/", ICON_HDD}, + {"drivers/edac/", ICON_MEMORY}, + {"drivers/hid/", ICON_INPUTDEVICES}, + {"drivers/gpu/", ICON_MONITOR}, + {"drivers/i2c/", ICON_MEMORY}, + {"drivers/ata/", ICON_HDD}, + {"drivers/usb/", ICON_USB}, + {"drivers/pci/", ICON_DEVICES}, + {"drivers/net/", ICON_NETWORK}, + {"drivers/mmc/", ICON_MEDIA_REMOVABLE}, + {"crypto/", ICON_CRYPTOHASH}, + {"sound/", ICON_AUDIO}, + {"net/", ICON_NETWORK_CONNECTIONS}, + {"fs/", ICON_MEDIA_FLOPPY}, + {}, +}; + +static GHashTable *module_icons; -void -scan_modules_do(void) +static void build_icon_table_iter(JsonObject *object, + const gchar *key, + JsonNode *value, + gpointer user_data) { + char *key_copy = g_strdup(key); + char *p; + + for (p = key_copy; *p; p++) { + if (*p == '_') + *p = '-'; + } + + enum icons icon; + const gchar *value_str = json_node_get_string(value); + for (icon = ICON_INVALID; icon < ICON_MAX; icon++) { + const char *icon_name = icon_table[icon]; + + if (!icon_name) + continue; + + if (g_str_equal(value_str, icon_name)) { + g_hash_table_insert(module_icons, + key_copy, GINT_TO_POINTER(icon)); + return; + } + } + + g_free(key_copy); +} + +void kernel_module_icon_init(void) +{ + gchar *icon_json; + + static SyncEntry sync_entry = { + .name = N_("Update kernel module icon table"), + .file_name = "kernel-module-icons.json", + }; + sync_manager_add_entry(&sync_entry); + + icon_json = g_build_filename(g_get_user_config_dir(), + "hardinfo", "kernel-module-icons.json", + NULL); + + module_icons = g_hash_table_new(g_str_hash, g_str_equal); + + if (!g_file_test(icon_json, G_FILE_TEST_EXISTS)) + goto out; + + JsonParser *parser = json_parser_new(); + if (!json_parser_load_from_file(parser, icon_json, NULL)) + goto out_destroy_parser; + + JsonNode *root = json_parser_get_root(parser); + if (json_node_get_node_type(root) != JSON_NODE_OBJECT) + goto out_destroy_parser; + + JsonObject *icons = json_node_get_object(root); + if (!icons) + goto out_destroy_parser; + + json_object_foreach_member(icons, build_icon_table_iter, NULL); + +out_destroy_parser: + g_object_unref(parser); + +out: + g_free(icon_json); +} + +static const gchar* get_module_icon(const char *modname, const char *path) +{ + char *modname_temp = g_strdup(modname); + char *p; + for (p = modname_temp; *p; p++) { + if (*p == '_') + *p = '-'; + } + gpointer icon = g_hash_table_lookup(module_icons, modname_temp); + g_free(modname_temp); + if (icon) + return icon_table[GPOINTER_TO_INT(icon)]; + + if (path == NULL) /* modinfo couldn't find module path */ + return NULL; + + if (kernel_modules_dir == NULL) { + struct utsname utsbuf; + uname(&utsbuf); + kernel_modules_dir = g_strdup_printf("/lib/modules/%s/kernel/", utsbuf.release); + } + + if (!g_str_has_prefix(path, kernel_modules_dir)) + return NULL; + + const gchar *path_no_prefix = path + strlen(kernel_modules_dir); + const size_t path_no_prefix_len = strlen(path_no_prefix); + int i; + + for (i = 0; modules_icons[i].dir; i++) { + if (g_str_has_prefix(path_no_prefix, modules_icons[i].dir)) + return icon_table[modules_icons[i].icon]; + } + + return NULL; +} + +void scan_modules_do(void) { FILE *lsmod; gchar buffer[1024]; gchar *lsmod_path; + gchar *module_icons; + const gchar *icon; - if (!_module_hash_table) { - _module_hash_table = g_hash_table_new(g_str_hash, g_str_equal); - } + if (!_module_hash_table) { _module_hash_table = g_hash_table_new(g_str_hash, g_str_equal); } g_free(module_list); + kernel_modules_dir = NULL; module_list = NULL; + module_icons = NULL; moreinfo_del_with_prefix("COMP:MOD"); lsmod_path = find_program("lsmod"); - if (!lsmod_path) - return; + if (!lsmod_path) return; lsmod = popen(lsmod_path, "r"); if (!lsmod) { g_free(lsmod_path); - return; + return; } - (void)fgets(buffer, 1024, lsmod); /* Discards the first line */ + (void)fgets(buffer, 1024, lsmod); /* Discards the first line */ while (fgets(buffer, 1024, lsmod)) { - gchar *buf, *strmodule, *hashkey; - gchar *author = NULL, - *description = NULL, - *license = NULL, - *deps = NULL, *vermagic = NULL, *filename = NULL, modname[64]; - FILE *modi; - glong memory; - - shell_status_pulse(); - - buf = buffer; - - sscanf(buf, "%s %ld", modname, &memory); - - hashkey = g_strdup_printf("MOD%s", modname); - buf = g_strdup_printf("/sbin/modinfo %s 2>/dev/null", modname); - - modi = popen(buf, "r"); - while (fgets(buffer, 1024, modi)) { - gchar **tmp = g_strsplit(buffer, ":", 2); - - GET_STR("author", author); - GET_STR("description", description); - GET_STR("license", license); - GET_STR("depends", deps); - GET_STR("vermagic", vermagic); - GET_STR("filename", filename); - - g_strfreev(tmp); - } - pclose(modi); - g_free(buf); - - /* old modutils includes quotes in some strings; strip them */ - /*remove_quotes(modname); - remove_quotes(description); - remove_quotes(vermagic); - remove_quotes(author); - remove_quotes(license); */ - - /* old modutils displays <none> when there's no value for a - given field; this is not desirable in the module name - display, so change it to an empty string */ - if (description && g_str_equal(description, "<none>")) { - g_free(description); - description = g_strdup(""); - - g_hash_table_insert(_module_hash_table, - g_strdup(modname), + gchar *buf, *strmodule, *hashkey; + gchar *author = NULL, *description = NULL, *license = NULL, *deps = NULL, *vermagic = NULL, + *filename = NULL, *srcversion = NULL, *version = NULL, *retpoline = NULL, + *intree = NULL, modname[64]; + FILE *modi; + glong memory; + + shell_status_pulse(); + + buf = buffer; + + sscanf(buf, "%s %ld", modname, &memory); + + hashkey = g_strdup_printf("MOD%s", modname); + buf = g_strdup_printf("/sbin/modinfo %s 2>/dev/null", modname); + + modi = popen(buf, "r"); + while (fgets(buffer, 1024, modi)) { + gchar **tmp = g_strsplit(buffer, ":", 2); + + GET_STR("author", author); + GET_STR("description", description); + GET_STR("license", license); + GET_STR("depends", deps); + GET_STR("vermagic", vermagic); + GET_STR("filename", filename); + GET_STR("srcversion", srcversion); /* so "version" doesn't catch */ + GET_STR("version", version); + GET_STR("retpoline", retpoline); + GET_STR("intree", intree); + + g_strfreev(tmp); + } + pclose(modi); + g_free(buf); + + /* old modutils includes quotes in some strings; strip them */ + /*remove_quotes(modname); + remove_quotes(description); + remove_quotes(vermagic); + remove_quotes(author); + remove_quotes(license); */ + + /* old modutils displays <none> when there's no value for a + given field; this is not desirable in the module name + display, so change it to an empty string */ + if (description && g_str_equal(description, "<none>")) { + g_free(description); + description = g_strdup(""); + + g_hash_table_insert(_module_hash_table, g_strdup(modname), g_strdup_printf("Kernel module (%s)", modname)); - } else { - g_hash_table_insert(_module_hash_table, - g_strdup(modname), - g_strdup(description)); + } else { + g_hash_table_insert(_module_hash_table, g_strdup(modname), g_strdup(description)); } - /* append this module to the list of modules */ - module_list = h_strdup_cprintf("$%s$%s=%s\n", - module_list, - hashkey, - modname, - description ? description : ""); - - STRIFNULL(filename, _("(Not available)") ); - STRIFNULL(description, _("(Not available)") ); - STRIFNULL(vermagic, _("(Not available)") ); - STRIFNULL(author, _("(Not available)") ); - STRIFNULL(license, _("(Not available)") ); - - /* create the module information string */ - strmodule = g_strdup_printf("[%s]\n" - "%s=%s\n" - "%s=%.2f %s\n" - "[%s]\n" - "%s=%s\n" - "%s=%s\n" - "%s=%s\n" - "[%s]\n" - "%s=%s\n" - "%s=%s\n", - _("Module Information"), - _("Path"), filename, - _("Used Memory"), memory / 1024.0, _("KiB"), - _("Description"), - _("Name"), modname, - _("Description"), description, - _("Version Magic"), vermagic, - _("Copyright"), - _("Author"), author, - _("License"), license ); - - /* if there are dependencies, append them to that string */ - if (deps && strlen(deps)) { - gchar **tmp = g_strsplit(deps, ",", 0); - - strmodule = h_strconcat(strmodule, - "\n[", _("Dependencies"), "]\n", - g_strjoinv("=\n", tmp), - "=\n", NULL); - g_strfreev(tmp); - g_free(deps); - } + /* append this module to the list of modules */ + module_list = h_strdup_cprintf("$%s$%s=%s\n", module_list, hashkey, modname, + description ? description : ""); + icon = get_module_icon(modname, filename); + module_icons = h_strdup_cprintf("Icon$%s$%s=%s.png\n", module_icons, hashkey, + modname, icon ? icon: "module"); + + STRIFNULL(filename, _("(Not available)")); + STRIFNULL(description, _("(Not available)")); + STRIFNULL(vermagic, _("(Not available)")); + STRIFNULL(author, _("(Not available)")); + STRIFNULL(license, _("(Not available)")); + STRIFNULL(version, _("(Not available)")); + + gboolean ry = FALSE, ity = FALSE; + if (retpoline && *retpoline == 'Y') ry = TRUE; + if (intree && *intree == 'Y') ity = TRUE; - moreinfo_add_with_prefix("COMP", hashkey, strmodule); - g_free(hashkey); + g_free(retpoline); + g_free(intree); - g_free(license); - g_free(description); - g_free(author); - g_free(vermagic); - g_free(filename); + retpoline = g_strdup(ry ? _("Yes") : _("No")); + intree = g_strdup(ity ? _("Yes") : _("No")); + + /* create the module information string */ + strmodule = g_strdup_printf("[%s]\n" + "%s=%s\n" + "%s=%.2f %s\n" + "[%s]\n" + "%s=%s\n" + "%s=%s\n" + "%s=%s\n" + "%s=%s\n" + "%s=%s\n" + "%s=%s\n" + "[%s]\n" + "%s=%s\n" + "%s=%s\n", + _("Module Information"), _("Path"), filename, _("Used Memory"), + memory / 1024.0, _("KiB"), _("Description"), _("Name"), modname, + _("Description"), description, _("Version Magic"), vermagic, + _("Version"), version, _("In Linus' Tree"), intree, + _("Retpoline Enabled"), retpoline, _("Copyright"), _("Author"), + author, _("License"), license); + + /* if there are dependencies, append them to that string */ + if (deps && strlen(deps)) { + gchar **tmp = g_strsplit(deps, ",", 0); + + strmodule = h_strconcat(strmodule, "\n[", _("Dependencies"), "]\n", + g_strjoinv("=\n", tmp), "=\n", NULL); + g_strfreev(tmp); + g_free(deps); + } + + moreinfo_add_with_prefix("COMP", hashkey, strmodule); + g_free(hashkey); + + g_free(license); + g_free(description); + g_free(author); + g_free(vermagic); + g_free(filename); + g_free(srcversion); + g_free(version); + g_free(retpoline); + g_free(intree); } pclose(lsmod); g_free(lsmod_path); + g_free(kernel_modules_dir); + + if (module_list != NULL && module_icons != NULL) { + module_list = h_strdup_cprintf("[$ShellParam$]\n%s", module_list, module_icons); + } + g_free(module_icons); } diff --git a/modules/computer/os.c b/modules/computer/os.c index a8886f64..7648eef3 100644 --- a/modules/computer/os.c +++ b/modules/computer/os.c @@ -1,10 +1,10 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> + * Copyright (C) 2003-2006 L. A. F. Pereira <l@tia.mat.br> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. + * the Free Software Foundation, version 2 or later. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -21,6 +21,7 @@ #include <sys/utsname.h> #include "hardinfo.h" #include "computer.h" +#include "distro_flavors.h" static gchar * get_libc_version(void) @@ -46,7 +47,7 @@ get_libc_version(void) gboolean spawned; gchar *out, *err, *p; - spawned = g_spawn_command_line_sync(libs[i].test_cmd, + spawned = hardinfo_spawn_command_line_sync(libs[i].test_cmd, &out, &err, NULL, NULL); if (!spawned) continue; @@ -91,7 +92,7 @@ static gchar *detect_kde_version(void) cmd = "kcontrol --version"; } - spawned = g_spawn_command_line_sync(cmd, &out, NULL, NULL, NULL); + spawned = hardinfo_spawn_command_line_sync(cmd, &out, NULL, NULL, NULL); if (!spawned) return NULL; @@ -106,7 +107,7 @@ detect_gnome_version(void) gchar *out; gboolean spawned; - spawned = g_spawn_command_line_sync( + spawned = hardinfo_spawn_command_line_sync( "gnome-shell --version", &out, NULL, NULL, NULL); if (spawned) { tmp = strstr(idle_free(out), _("GNOME Shell ")); @@ -117,7 +118,7 @@ detect_gnome_version(void) } } - spawned = g_spawn_command_line_sync( + spawned = hardinfo_spawn_command_line_sync( "gnome-about --gnome-version", &out, NULL, NULL, NULL); if (spawned) { tmp = strstr(idle_free(out), _("Version: ")); @@ -131,17 +132,42 @@ detect_gnome_version(void) return NULL; } + static gchar * -detect_window_manager(void) +detect_mate_version(void) { - GdkScreen *screen = gdk_screen_get_default(); - const gchar *windowman; - const gchar *curdesktop; + gchar *tmp; + gchar *out; + gboolean spawned; - if (!screen || !GDK_IS_SCREEN(screen)) - return NULL; + spawned = hardinfo_spawn_command_line_sync( + "mate-about --version", &out, NULL, NULL, NULL); + if (spawned) { + tmp = strstr(idle_free(out), _("MATE Desktop Environment ")); - windowman = gdk_x11_screen_get_window_manager_name(screen); + if (tmp) { + tmp += strlen(_("MATE Desktop Environment ")); + return g_strdup_printf("MATE %s", strend(tmp, '\n')); + } + } + + return NULL; +} + +static gchar * +detect_window_manager(void) +{ + const gchar *curdesktop; + const gchar* windowman; + GdkScreen *screen = gdk_screen_get_default(); + +#if GTK_CHECK_VERSION(3,0,0) + if (GDK_IS_X11_SCREEN(screen)) { +#else + if (screen && GDK_IS_SCREEN(screen)) { +#endif + windowman = gdk_x11_screen_get_window_manager_name(screen); + } else return g_strdup("Not X11"); if (g_str_equal(windowman, "Xfwm4")) return g_strdup("XFCE 4"); @@ -192,6 +218,12 @@ detect_xdg_environment(const gchar *env_var) if (maybe_kde) return maybe_kde; } + if (g_str_equal(tmp, "MATE") || g_str_equal(tmp, "mate")) { + gchar *maybe_mate = detect_mate_version(); + + if (maybe_mate) + return maybe_mate; + } return g_strdup(tmp); } @@ -235,6 +267,44 @@ detect_desktop_environment(void) } gchar * +computer_get_dmesg_status(void) +{ + gchar *out = NULL, *err = NULL; + int ex = 1, result = 0; + hardinfo_spawn_command_line_sync("dmesg", &out, &err, &ex, NULL); + g_free(out); + g_free(err); + result += (getuid() == 0) ? 2 : 0; + result += ex ? 1 : 0; + switch(result) { + case 0: /* readable, user */ + return g_strdup(_("User access allowed")); + case 1: /* unreadable, user */ + return g_strdup(_("User access forbidden")); + case 2: /* readable, root */ + return g_strdup(_("Access allowed (running as superuser)")); + case 3: /* unreadable, root */ + return g_strdup(_("Access forbidden? (running as superuser)")); + } + return g_strdup(_("(Unknown)")); +} + +gchar * +computer_get_aslr(void) +{ + switch (h_sysfs_read_int("/proc/sys/kernel", "randomize_va_space")) { + case 0: + return g_strdup(_("Disabled")); + case 1: + return g_strdup(_("Partially enabled (mmap base+stack+VDSO base)")); + case 2: + return g_strdup(_("Fully enabled (mmap base+stack+VDSO base+heap)")); + default: + return g_strdup(_("Unknown")); + } +} + +gchar * computer_get_entropy_avail(void) { gchar tab_entropy_fstr[][32] = { @@ -281,7 +351,77 @@ computer_get_language(void) return ret; } -static gchar * +static Distro +parse_os_release(void) +{ + gchar *pretty_name = NULL; + gchar *id = NULL; + gchar *codename = NULL; + gchar **split, *contents, **line; + + if (!g_file_get_contents("/usr/lib/os-release", &contents, NULL, NULL)) + return (Distro) {}; + + split = g_strsplit(idle_free(contents), "\n", 0); + if (!split) + return (Distro) {}; + + for (line = split; *line; line++) { + if (!strncmp(*line, "ID=", sizeof("ID=") - 1)) { + id = g_strdup(*line + strlen("ID=")); + } else if (!strncmp(*line, "CODENAME=", sizeof("CODENAME=") - 1)) { + codename = g_strdup(*line + strlen("CODENAME=")); + } else if (!strncmp(*line, "PRETTY_NAME=", sizeof("PRETTY_NAME=") - 1)) { + pretty_name = g_strdup(*line + + strlen("PRETTY_NAME=\"")); + strend(pretty_name, '"'); + } + } + + g_strfreev(split); + + if (pretty_name) + return (Distro) { .distro = pretty_name, .codename = codename, .id = id }; + + g_free(id); + return (Distro) {}; +} + +static Distro +parse_lsb_release(void) +{ + gchar *pretty_name = NULL; + gchar *id = NULL; + gchar *codename = NULL; + gchar **split, *contents, **line; + + if (!hardinfo_spawn_command_line_sync("/usr/bin/lsb_release -di", &contents, NULL, NULL, NULL)) + return (Distro) {}; + + split = g_strsplit(idle_free(contents), "\n", 0); + if (!split) + return (Distro) {}; + + for (line = split; *line; line++) { + if (!strncmp(*line, "Distributor ID:\t", sizeof("Distributor ID:\t") - 1)) { + id = g_utf8_strdown(*line + strlen("Distributor ID:\t"), -1); + } else if (!strncmp(*line, "Codename:\t", sizeof("Codename:\t") - 1)) { + codename = g_utf8_strdown(*line + strlen("Codename:\t"), -1); + } else if (!strncmp(*line, "Description:\t", sizeof("Description:\t") - 1)) { + pretty_name = g_strdup(*line + strlen("Description:\t")); + } + } + + g_strfreev(split); + + if (pretty_name) + return (Distro) { .distro = pretty_name, .codename = codename, .id = id }; + + g_free(id); + return (Distro) {}; +} + +static Distro detect_distro(void) { static const struct { @@ -292,11 +432,11 @@ detect_distro(void) #define DB_PREFIX "/etc/" { DB_PREFIX "arch-release", "arch", "Arch Linux" }, { DB_PREFIX "fatdog-version", "fatdog" }, - { DB_PREFIX "debian_version", "deb" }, + { DB_PREFIX "debian_version", "debian" }, { DB_PREFIX "slackware-version", "slk" }, { DB_PREFIX "mandrake-release", "mdk" }, { DB_PREFIX "mandriva-release", "mdv" }, - { DB_PREFIX "fedora-release", "fdra" }, + { DB_PREFIX "fedora-release", "fedora" }, { DB_PREFIX "coas", "coas" }, { DB_PREFIX "environment.corel", "corel"}, { DB_PREFIX "gentoo-release", "gnt" }, @@ -305,7 +445,6 @@ detect_distro(void) { DB_PREFIX "turbolinux-release", "tl" }, { DB_PREFIX "yellowdog-release", "yd" }, { DB_PREFIX "sabayon-release", "sbn" }, - { DB_PREFIX "arch-release", "arch" }, { DB_PREFIX "enlisy-release", "enlsy" }, { DB_PREFIX "SuSE-release", "suse" }, { DB_PREFIX "sun-release", "sun" }, @@ -324,15 +463,17 @@ detect_distro(void) #undef DB_PREFIX { NULL, NULL } }; + Distro distro; gchar *contents; int i; - if (g_spawn_command_line_sync("lsb_release -d", &contents, NULL, NULL, NULL)) { - gchar *tmp = strstr(idle_free(contents), "Description:\t"); + distro = parse_os_release(); + if (distro.distro) + return distro; - if (tmp) - return g_strdup(tmp + strlen("Description:\t")); - } + distro = parse_lsb_release(); + if (distro.distro) + return distro; for (i = 0; distro_db[i].file; i++) { if (!g_file_get_contents(distro_db[i].file, &contents, NULL, NULL)) @@ -340,23 +481,31 @@ detect_distro(void) if (distro_db[i].override) { g_free(contents); - return g_strdup(distro_db[i].override); + return (Distro) { .distro = g_strdup(distro_db[i].override), + .codename = g_strdup(distro_db[i].codename) }; } - if (g_str_equal(distro_db[i].codename, "deb")) { + if (g_str_equal(distro_db[i].codename, "debian")) { /* HACK: Some Debian systems doesn't include the distribuition * name in /etc/debian_release, so add them here. */ if (isdigit(contents[0]) || contents[0] != 'D') - return g_strdup_printf("Debian GNU/Linux %s", (char*)idle_free(contents)); + return (Distro) { + .distro = g_strdup_printf("Debian GNU/Linux %s", (char*)idle_free(contents)), + .codename = g_strdup(distro_db[i].codename) + }; } - if (g_str_equal(distro_db[i].codename, "fatdog")) - return g_strdup_printf("Fatdog64 [%.10s]", (char*)idle_free(contents)); + if (g_str_equal(distro_db[i].codename, "fatdog")) { + return (Distro) { + .distro = g_strdup_printf("Fatdog64 [%.10s]", (char*)idle_free(contents)), + .codename = g_strdup(distro_db[i].codename) + }; + } - return contents; + return (Distro) { .distro = contents, .codename = g_strdup(distro_db[i].codename) }; } - return g_strdup(_("Unknown")); + return (Distro) { .distro = g_strdup(_("Unknown")) }; } OperatingSystem * @@ -368,13 +517,17 @@ computer_get_os(void) os = g_new0(OperatingSystem, 1); - os->distro = g_strstrip(detect_distro()); + Distro distro = detect_distro(); + os->distro = g_strstrip(distro.distro); + os->distroid = distro.id; + os->distrocode = distro.codename; /* Kernel and hostname info */ uname(&utsbuf); os->kernel_version = g_strdup(utsbuf.version); os->kernel = g_strdup_printf("%s %s (%s)", utsbuf.sysname, utsbuf.release, utsbuf.machine); + os->kcmdline = h_sysfs_read_string("/proc", "cmdline"); os->hostname = g_strdup(utsbuf.nodename); os->language = computer_get_language(); os->homedir = g_strdup(g_get_home_dir()); @@ -389,5 +542,41 @@ computer_get_os(void) os->entropy_avail = computer_get_entropy_avail(); + if (g_strcmp0(os->distrocode, "ubuntu") == 0) { + GSList *flavs = ubuntu_flavors_scan(); + if (flavs) { + /* just use the first one */ + os->distro_flavor = (DistroFlavor*)flavs->data; + } + g_slist_free(flavs); + } + return os; } + +const gchar * +computer_get_selinux(void) +{ + int r; + gboolean spawned = hardinfo_spawn_command_line_sync("selinuxenabled", + NULL, NULL, &r, NULL); + + if (!spawned) + return _("Not installed"); + + if (r == 0) + return _("Enabled"); + + return _("Disabled"); +} + +gchar * +computer_get_lsm(void) +{ + gchar *contents; + + if (!g_file_get_contents("/sys/kernel/security/lsm", &contents, NULL, NULL)) + return g_strdup(_("Unknown")); + + return contents; +} diff --git a/modules/computer/ubuntu_flavors.c b/modules/computer/ubuntu_flavors.c new file mode 100644 index 00000000..ac67d665 --- /dev/null +++ b/modules/computer/ubuntu_flavors.c @@ -0,0 +1,90 @@ +/* + * HardInfo - Displays System Information + * Copyright (C) 2003-2019 L. A. F. Pereira <l@tia.mat.br> + * This file Burt P. <pburt0@gmail.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 or later. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <hardinfo.h> +#include "distro_flavors.h" +#include "util_sysobj.h" /* for appfsp() */ + +static const UbuntuFlavor ubuntu_flavors[] = { + { "Vanilla Server", "distros/ubuntu.svg", "https://ubuntu.org", "ubuntu-server" }, + { "Vanilla Desktop", "distros/ubuntu.svg", "https://ubuntu.org", "ubuntu-desktop" }, + { "Xubuntu", "distros/xubuntu.svg", "https://xubuntu.org", "xubuntu-desktop" }, + { "Kubuntu", "distros/kubuntu.png", "https://kubuntu.org", "kubuntu-desktop" }, + { "Lubuntu", "distros/lubuntu.png", "https://lubuntu.me", "lubuntu-desktop" }, /* formerly or also lubuntu.net? */ + { "Ubuntu MATE", "distros/ubuntu-mate.png", "https://ubuntu-mate.org", "ubuntu-mate-desktop" }, + { "Ubuntu Budgie", "distros/ubuntu-budgie.png", "https://ubuntubudgie.org", "ubuntu-budgie-desktop" }, + { "UbuntuKylin (εζζδΈε½ε³ηζδ½η³»η»)", "distros/ubuntu-kylin.png", "https://www.ubuntukylin.com", "ubuntukylin-desktop" }, + { "UbuntuStudio", "distros/ubuntu-studio.png", "https://ubuntustudio.org", "ubuntustudio-desktop" }, + /* Deprecated flavors */ + { "Ubuntu GNOME", "distros/ubuntu-gnome.png", "https://ubuntugnome.org", "ubuntu-gnome-desktop" }, + // Edubuntu + // Mythbuntu + { NULL } +}; + +static const UbuntuFlavor *_find_flavor(const gchar *pkg) { + int i = 0; + for(; ubuntu_flavors[i].base.name; i++) { + if (SEQ(ubuntu_flavors[i].package, pkg)) + return &ubuntu_flavors[i]; + } + return NULL; +} + +/* items are const; free with g_slist_free() */ +GSList *ubuntu_flavors_scan(void) { + GSList *ret = NULL; + gboolean spawned; + gchar *out, *err, *p, *next_nl; + gint exit_status; + const UbuntuFlavor *f = NULL; + gchar *cmd_line = g_strdup("apt-cache policy"); + int i; + for(i = 0; ubuntu_flavors[i].base.name; i++) { + cmd_line = appfsp(cmd_line, "%s", ubuntu_flavors[i].package); + } + if (!i) + return NULL; + + spawned = hardinfo_spawn_command_line_sync(cmd_line, + &out, &err, &exit_status, NULL); + if (spawned) { + p = out; + while(next_nl = strchr(p, '\n')) { + strend(p, '\n'); + int mc = 0; + char pkg[32] = ""; + if (*p != ' ' && *p != '\t') + mc = sscanf(p, "%31s", pkg); + if (mc == 1) { + strend(pkg, ':'); + f = _find_flavor(pkg); + } else if + (g_strstr_len(p, -1, "Installed:") + && !g_strstr_len(p, -1, "(none)") ) { + ret = g_slist_append(ret, (void*)f); + } + p = next_nl + 1; + } + g_free(out); + g_free(err); + } + g_free(cmd_line); + return ret; +} diff --git a/modules/computer/uptime.c b/modules/computer/uptime.c index 6ef3d250..8aef1530 100644 --- a/modules/computer/uptime.c +++ b/modules/computer/uptime.c @@ -1,10 +1,10 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> + * Copyright (C) 2003-2006 L. A. F. Pereira <l@tia.mat.br> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. + * the Free Software Foundation, version 2 or later. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of diff --git a/modules/computer/users.c b/modules/computer/users.c index f47320bb..75e24f26 100644 --- a/modules/computer/users.c +++ b/modules/computer/users.c @@ -1,10 +1,10 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2009 Leandro A. F. Pereira <leandro@hardinfo.org> + * Copyright (C) 2003-2009 L. A. F. Pereira <l@tia.mat.br> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. + * the Free Software Foundation, version 2 or later. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of |