diff options
author | Simon Quigley <tsimonq2@ubuntu.com> | 2018-12-23 23:54:25 -0600 |
---|---|---|
committer | Simon Quigley <tsimonq2@ubuntu.com> | 2018-12-23 23:54:25 -0600 |
commit | a739f196cba9e5c4376e97b1ac95e1d15b1ccb55 (patch) | |
tree | eab9260f076de9ba9bf81e44c727c64a963a2895 /modules/computer | |
parent | 3972650bc68dc3b846b6eabfd83e37872005741e (diff) |
Remove orig content.
Diffstat (limited to 'modules/computer')
-rw-r--r-- | modules/computer/alsa.c | 71 | ||||
-rw-r--r-- | modules/computer/boots.c | 66 | ||||
-rw-r--r-- | modules/computer/display.c | 151 | ||||
-rw-r--r-- | modules/computer/environment.c | 45 | ||||
-rw-r--r-- | modules/computer/filesystem.c | 105 | ||||
-rw-r--r-- | modules/computer/groups.c | 45 | ||||
-rw-r--r-- | modules/computer/languages.c | 134 | ||||
-rw-r--r-- | modules/computer/loadavg.c | 68 | ||||
-rw-r--r-- | modules/computer/memory.c | 62 | ||||
-rw-r--r-- | modules/computer/modules.c | 177 | ||||
-rw-r--r-- | modules/computer/os.c | 393 | ||||
-rw-r--r-- | modules/computer/uptime.c | 72 | ||||
-rw-r--r-- | modules/computer/users.c | 61 |
13 files changed, 0 insertions, 1450 deletions
diff --git a/modules/computer/alsa.c b/modules/computer/alsa.c deleted file mode 100644 index 00c1fceb..00000000 --- a/modules/computer/alsa.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * 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. - * - * 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 "computer.h" - -gchar * -computer_get_alsacards(Computer * computer) -{ - GSList *p; - gchar *tmp = g_strdup_printf("[%s]\n", _("Audio Devices")); - gint n = 0; - - if (computer->alsa) { - for (p = computer->alsa->cards; p; p = p->next) { - AlsaCard *ac = (AlsaCard *) p->data; - - tmp = h_strdup_cprintf("%s#%d=%s\n", tmp, - _("Audio Adapter"), ++n, ac->friendly_name); - } - } - - return tmp; -} - -AlsaInfo * -computer_get_alsainfo(void) -{ - AlsaInfo *ai; - AlsaCard *ac; - FILE *cards; - gchar buffer[128]; - - cards = fopen("/proc/asound/cards", "r"); - if (!cards) - return NULL; - - ai = g_new0(AlsaInfo, 1); - - while (fgets(buffer, 128, cards)) { - gchar **tmp; - - ac = g_new0(AlsaCard, 1); - - tmp = g_strsplit(buffer, ":", 0); - - ac->friendly_name = g_strdup(tmp[1]); - ai->cards = g_slist_append(ai->cards, ac); - - g_strfreev(tmp); - (void)fgets(buffer, 128, cards); /* skip next line */ - } - fclose(cards); - - return ai; -} diff --git a/modules/computer/boots.c b/modules/computer/boots.c deleted file mode 100644 index ba458242..00000000 --- a/modules/computer/boots.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * 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. - * - * 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 <stdio.h> -#include <string.h> -#include "hardinfo.h" -#include "computer.h" - -void -scan_boots_real(void) -{ - gchar **tmp; - gboolean spawned; - gchar *out, *err, *p, *s, *next_nl; - - scan_os(FALSE); - - if (!computer->os->boots) - computer->os->boots = strdup(""); - else - return; - - spawned = g_spawn_command_line_sync("last", - &out, &err, NULL, NULL); - if (spawned && out != NULL) { - p = out; - while(next_nl = strchr(p, '\n')) { - strend(p, '\n'); - if (strstr(p, "system boot")) { - s = p; - while (*s) { - if (*s == ' ' && *(s + 1) == ' ') { - memmove(s, s + 1, strlen(s) + 1); - s--; - } else { - s++; - } - } - tmp = g_strsplit(p, " ", 0); - computer->os->boots = - h_strdup_cprintf("\n%s %s %s %s=%s", - computer->os->boots, - tmp[4], tmp[5], tmp[6], tmp[7], tmp[3]); - g_strfreev(tmp); - } - p = next_nl + 1; - } - g_free(out); - g_free(err); - } -} diff --git a/modules/computer/display.c b/modules/computer/display.c deleted file mode 100644 index 61eac4eb..00000000 --- a/modules/computer/display.c +++ /dev/null @@ -1,151 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * 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. - * - * 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 "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)"); - } - -} - -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); - } - - 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 = ""; - } -} - -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; - } - - get_glx_info(di); - get_x11_info(di); - - return di; -} diff --git a/modules/computer/environment.c b/modules/computer/environment.c deleted file mode 100644 index dc0fb6f3..00000000 --- a/modules/computer/environment.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2008 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * 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. - * - * 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 "computer.h" - -static gchar *_env = NULL; -void scan_env_var(gboolean reload) -{ - SCAN_START(); - - gchar **envlist; - gint i; - - g_free(_env); - - _env = g_strdup_printf("[%s]\n", _("Environment Variables") ); - for (i = 0, envlist = g_listenv(); envlist[i]; i++) { - _env = h_strdup_cprintf("%s=%s\n", _env, - envlist[i], g_getenv(envlist[i])); - } - g_strfreev(envlist); - - SCAN_END(); -} - -gchar *callback_env_var(void) -{ - return g_strdup(_env); -} diff --git a/modules/computer/filesystem.c b/modules/computer/filesystem.c deleted file mode 100644 index 397dc636..00000000 --- a/modules/computer/filesystem.c +++ /dev/null @@ -1,105 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * 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. - * - * 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 - * - * Some code from xfce4-mount-plugin, version 0.4.3 - * Copyright (C) 2005 Jean-Baptiste jb_dul@yahoo.com - * Distributed under the terms of GNU GPL 2. - */ - -#include <string.h> -#include <sys/vfs.h> -#include "hardinfo.h" -#include "computer.h" - -gchar *fs_list = NULL; - -void -scan_filesystems(void) -{ - FILE *mtab; - gchar buf[1024]; - struct statfs sfs; - int count = 0; - - g_free(fs_list); - fs_list = g_strdup(""); - moreinfo_del_with_prefix("COMP:FS"); - - mtab = fopen("/etc/mtab", "r"); - if (!mtab) - return; - - while (fgets(buf, 1024, mtab)) { - gfloat size, used, avail; - gchar **tmp; - - tmp = g_strsplit(buf, " ", 0); - if (!statfs(tmp[1], &sfs)) { - gfloat use_ratio; - - size = (float) sfs.f_bsize * (float) sfs.f_blocks; - avail = (float) sfs.f_bsize * (float) sfs.f_bavail; - used = size - avail; - - if (size == 0.0f) { - continue; - } - - if (avail == 0.0f) { - use_ratio = 100.0f; - } else { - use_ratio = 100.0f * (used / size); - } - - gchar *strsize = size_human_readable(size), - *stravail = size_human_readable(avail), - *strused = size_human_readable(used); - - gchar *strhash; - - strreplacechr(tmp[0], "#", '_'); - strhash = g_strdup_printf("[%s]\n" - "%s=%s\n" - "%s=%s\n" - "%s=%s\n" - "%s=%s\n" - "%s=%s\n" - "%s=%s\n", - tmp[0], /* path */ - _("Filesystem"), tmp[2], - _("Mounted As"), ( strstr(tmp[3], "rw") != NULL) ? _("Read-Write") : _("Read-Only"), - _("Mount Point"), tmp[1], - _("Size"), strsize, - _("Used"), strused, - _("Available"), stravail); - gchar *key = g_strdup_printf("FS%d", ++count); - 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, - count, tmp[0], use_ratio, stravail, strsize, tmp[1]); - - g_free(strsize); - g_free(stravail); - g_free(strused); - } - g_strfreev(tmp); - } - - fclose(mtab); -} diff --git a/modules/computer/groups.c b/modules/computer/groups.c deleted file mode 100644 index 244b8000..00000000 --- a/modules/computer/groups.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2012 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * 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. - * - * 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 <sys/types.h> -#include <grp.h> -#include "hardinfo.h" -#include "computer.h" - -gchar *groups = NULL; - -void -scan_groups_do(void) -{ - struct group *group_; - - setgrent(); - group_ = getgrent(); - if (!group_) - return; - - g_free(groups); - groups = g_strdup(""); - - while (group_) { - groups = h_strdup_cprintf("%s=%d\n", groups, group_->gr_name, group_->gr_gid); - group_ = getgrent(); - } - - endgrent(); -} diff --git a/modules/computer/languages.c b/modules/computer/languages.c deleted file mode 100644 index d4681839..00000000 --- a/modules/computer/languages.c +++ /dev/null @@ -1,134 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * 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. - * - * 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 "hardinfo.h" -#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; - - 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; - } - } - - fclose(locale); - - os->languages = retval; -} diff --git a/modules/computer/loadavg.c b/modules/computer/loadavg.c deleted file mode 100644 index 7311dbf0..00000000 --- a/modules/computer/loadavg.c +++ /dev/null @@ -1,68 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * 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. - * - * 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 "hardinfo.h" -#include "computer.h" - -static gboolean -computer_get_loadinfo(LoadInfo *li) -{ - FILE *procloadavg; - char buf[64]; - int ret; - - procloadavg = fopen("/proc/loadavg", "r"); - if (!procloadavg) - return FALSE; - - if (!fgets(buf, sizeof(buf), procloadavg)) { - fclose(procloadavg); - return FALSE; - } - - ret = sscanf(buf, "%f %f %f", &li->load1, &li->load5, &li->load15); - if (ret != 3) { - size_t len = strlen(buf); - size_t i; - - for (i = 0; i < len; i++) { - if (buf[i] == '.') - buf[i] = ','; - } - - ret = sscanf(buf, "%f %f %f", &li->load1, &li->load5, &li->load15); - } - - fclose(procloadavg); - - return ret == 3; -} - -gchar * -computer_get_formatted_loadavg() -{ - LoadInfo li; - - if (!computer_get_loadinfo(&li)) - return g_strdup(_("Couldn't obtain load average")); - - return g_strdup_printf("%.2f, %.2f, %.2f", li.load1, li.load5, - li.load15); -} diff --git a/modules/computer/memory.c b/modules/computer/memory.c deleted file mode 100644 index dc8599c2..00000000 --- a/modules/computer/memory.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * 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. - * - * 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 "computer.h" - -MemoryInfo * -computer_get_memory(void) -{ - MemoryInfo *mi; - FILE *procmem; - gchar buffer[128]; - - procmem = fopen("/proc/meminfo", "r"); - if (!procmem) - return NULL; - mi = g_new0(MemoryInfo, 1); - - while (fgets(buffer, 128, procmem)) { - gchar **tmp = g_strsplit(buffer, ":", 2); - if (tmp[1] == NULL) { - g_strfreev(tmp); - continue; - } - tmp[0] = g_strstrip(tmp[0]); - tmp[1] = g_strstrip(tmp[1]); - - get_int("MemTotal", mi->total); - get_int("MemFree", mi->free); - get_int("Cached", mi->cached); - - g_strfreev(tmp); - } - fclose(procmem); - - mi->used = mi->total - mi->free; - - mi->total /= 1000; - mi->cached /= 1000; - mi->used /= 1000; - mi->free /= 1000; - - mi->used -= mi->cached; - mi->ratio = 1 - (gdouble) mi->used / mi->total; - - return mi; -} diff --git a/modules/computer/modules.c b/modules/computer/modules.c deleted file mode 100644 index df876e3a..00000000 --- a/modules/computer/modules.c +++ /dev/null @@ -1,177 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * 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. - * - * 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 "hardinfo.h" -#include "computer.h" -#include "cpu_util.h" /* for STRIFNULL() */ - -#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; - -void -scan_modules_do(void) -{ - FILE *lsmod; - gchar buffer[1024]; - gchar *lsmod_path; - - if (!_module_hash_table) { - _module_hash_table = g_hash_table_new(g_str_hash, g_str_equal); - } - - g_free(module_list); - - module_list = NULL; - moreinfo_del_with_prefix("COMP:MOD"); - - lsmod_path = find_program("lsmod"); - if (!lsmod_path) - return; - lsmod = popen(lsmod_path, "r"); - if (!lsmod) { - g_free(lsmod_path); - return; - } - - (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), - g_strdup_printf("Kernel module (%s)", modname)); - } 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); - } - - 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); - } - pclose(lsmod); - - g_free(lsmod_path); -} diff --git a/modules/computer/os.c b/modules/computer/os.c deleted file mode 100644 index a8886f64..00000000 --- a/modules/computer/os.c +++ /dev/null @@ -1,393 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * 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. - * - * 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 <gdk/gdkx.h> -#include <string.h> -#include <sys/utsname.h> -#include "hardinfo.h" -#include "computer.h" - -static gchar * -get_libc_version(void) -{ - static const struct { - const char *test_cmd; - const char *match_str; - const char *lib_name; - gboolean try_ver_str; - gboolean use_stderr; - } libs[] = { - { "ldd --version", "GLIBC", N_("GNU C Library"), TRUE, FALSE}, - { "ldd --version", "GNU libc", N_("GNU C Library"), TRUE, FALSE}, - { "ldconfig -V", "GLIBC", N_("GNU C Library"), TRUE, FALSE}, - { "ldconfig -V", "GNU libc", N_("GNU C Library"), TRUE, FALSE}, - { "ldconfig -v", "uClibc", N_("uClibc or uClibc-ng"), FALSE, FALSE}, - { "diet", "diet version", N_("diet libc"), TRUE, TRUE}, - { NULL } - }; - int i; - - for (i = 0; libs[i].test_cmd; i++) { - gboolean spawned; - gchar *out, *err, *p; - - spawned = g_spawn_command_line_sync(libs[i].test_cmd, - &out, &err, NULL, NULL); - if (!spawned) - continue; - - if (libs[i].use_stderr) { - p = strend(idle_free(err), '\n'); - g_free(out); - } else { - p = strend(idle_free(out), '\n'); - g_free(err); - } - - if (!p || !strstr(p, libs[i].match_str)) - continue; - - if (libs[i].try_ver_str) { - /* skip the first word, likely "ldconfig" or name of utility */ - const gchar *ver_str = strchr(p, ' '); - - if (ver_str) { - return g_strdup_printf("%s / %s", _(libs[i].lib_name), - ver_str + 1); - } - } - - return g_strdup(_(libs[i].lib_name)); - } - - return g_strdup(_("Unknown")); -} - -static gchar *detect_kde_version(void) -{ - const gchar *cmd; - const gchar *tmp = g_getenv("KDE_SESSION_VERSION"); - gchar *out; - gboolean spawned; - - if (tmp && tmp[0] == '4') { - cmd = "kwin --version"; - } else { - cmd = "kcontrol --version"; - } - - spawned = g_spawn_command_line_sync(cmd, &out, NULL, NULL, NULL); - if (!spawned) - return NULL; - - tmp = strstr(idle_free(out), "KDE: "); - return tmp ? g_strdup(tmp + strlen("KDE: ")) : NULL; -} - -static gchar * -detect_gnome_version(void) -{ - gchar *tmp; - gchar *out; - gboolean spawned; - - spawned = g_spawn_command_line_sync( - "gnome-shell --version", &out, NULL, NULL, NULL); - if (spawned) { - tmp = strstr(idle_free(out), _("GNOME Shell ")); - - if (tmp) { - tmp += strlen(_("GNOME Shell ")); - return g_strdup_printf("GNOME %s", strend(tmp, '\n')); - } - } - - spawned = g_spawn_command_line_sync( - "gnome-about --gnome-version", &out, NULL, NULL, NULL); - if (spawned) { - tmp = strstr(idle_free(out), _("Version: ")); - - if (tmp) { - tmp += strlen(_("Version: ")); - return g_strdup_printf("GNOME %s", strend(tmp, '\n')); - } - } - - return NULL; -} - -static gchar * -detect_window_manager(void) -{ - GdkScreen *screen = gdk_screen_get_default(); - const gchar *windowman; - const gchar *curdesktop; - - if (!screen || !GDK_IS_SCREEN(screen)) - return NULL; - - windowman = gdk_x11_screen_get_window_manager_name(screen); - - if (g_str_equal(windowman, "Xfwm4")) - return g_strdup("XFCE 4"); - - curdesktop = g_getenv("XDG_CURRENT_DESKTOP"); - if (curdesktop) { - const gchar *desksession = g_getenv("DESKTOP_SESSION"); - - if (desksession && !g_str_equal(curdesktop, desksession)) - return g_strdup(desksession); - } - - return g_strdup_printf(_("Unknown (Window Manager: %s)"), windowman); -} - -static gchar * -desktop_with_session_type(const gchar *desktop_env) -{ - const char *tmp; - - tmp = g_getenv("XDG_SESSION_TYPE"); - if (tmp) { - if (!g_str_equal(tmp, "unspecified")) - return g_strdup_printf(_(/*/{desktop environment} on {session type}*/ "%s on %s"), desktop_env, tmp); - } - - return g_strdup(desktop_env); -} - -static gchar * -detect_xdg_environment(const gchar *env_var) -{ - const gchar *tmp; - - tmp = g_getenv(env_var); - if (!tmp) - return NULL; - - if (g_str_equal(tmp, "GNOME") || g_str_equal(tmp, "gnome")) { - gchar *maybe_gnome = detect_gnome_version(); - - if (maybe_gnome) - return maybe_gnome; - } - if (g_str_equal(tmp, "KDE") || g_str_equal(tmp, "kde")) { - gchar *maybe_kde = detect_kde_version(); - - if (maybe_kde) - return maybe_kde; - } - - return g_strdup(tmp); -} - -static gchar * -detect_desktop_environment(void) -{ - const gchar *tmp; - gchar *windowman; - - windowman = detect_xdg_environment("XDG_CURRENT_DESKTOP"); - if (windowman) - return windowman; - windowman = detect_xdg_environment("XDG_SESSION_DESKTOP"); - if (windowman) - return windowman; - - tmp = g_getenv("KDE_FULL_SESSION"); - if (tmp) { - gchar *maybe_kde = detect_kde_version(); - - if (maybe_kde) - return maybe_kde; - } - tmp = g_getenv("GNOME_DESKTOP_SESSION_ID"); - if (tmp) { - gchar *maybe_gnome = detect_gnome_version(); - - if (maybe_gnome) - return maybe_gnome; - } - - windowman = detect_window_manager(); - if (windowman) - return windowman; - - if (!g_getenv("DISPLAY")) - return g_strdup(_("Terminal")); - - return g_strdup(_("Unknown")); -} - -gchar * -computer_get_entropy_avail(void) -{ - gchar tab_entropy_fstr[][32] = { - N_(/*/bits of entropy for rng (0)*/ "(None or not available)"), - N_(/*/bits of entropy for rng (low/poor value)*/ "%d bits (low)"), - N_(/*/bits of entropy for rng (medium value)*/ "%d bits (medium)"), - N_(/*/bits of entropy for rng (high/good value)*/ "%d bits (healthy)") - }; - gint bits = h_sysfs_read_int("/proc/sys/kernel/random", "entropy_avail"); - if (bits > 3000) return g_strdup_printf(_(tab_entropy_fstr[3]), bits); - if (bits > 200) return g_strdup_printf(_(tab_entropy_fstr[2]), bits); - if (bits > 1) return g_strdup_printf(_(tab_entropy_fstr[1]), bits); - return g_strdup_printf(_(tab_entropy_fstr[0]), bits); -} - -gchar * -computer_get_language(void) -{ - gchar *tab_lang_env[] = - { "LANGUAGE", "LANG", "LC_ALL", "LC_MESSAGES", NULL }; - gchar *lc = NULL, *env = NULL, *ret = NULL; - gint i = 0; - - lc = setlocale(LC_ALL, NULL); - - while (tab_lang_env[i] != NULL) { - env = g_strdup( g_getenv(tab_lang_env[i]) ); - if (env != NULL) break; - i++; - } - - if (env != NULL) - if (lc != NULL) - ret = g_strdup_printf("%s (%s)", lc, env); - else - ret = g_strdup_printf("%s", env); - else - if (lc != NULL) - ret = g_strdup_printf("%s", lc); - - if (ret == NULL) - ret = g_strdup( _("(Unknown)") ); - - return ret; -} - -static gchar * -detect_distro(void) -{ - static const struct { - const gchar *file; - const gchar *codename; - const gchar *override; - } distro_db[] = { -#define DB_PREFIX "/etc/" - { DB_PREFIX "arch-release", "arch", "Arch Linux" }, - { DB_PREFIX "fatdog-version", "fatdog" }, - { DB_PREFIX "debian_version", "deb" }, - { DB_PREFIX "slackware-version", "slk" }, - { DB_PREFIX "mandrake-release", "mdk" }, - { DB_PREFIX "mandriva-release", "mdv" }, - { DB_PREFIX "fedora-release", "fdra" }, - { DB_PREFIX "coas", "coas" }, - { DB_PREFIX "environment.corel", "corel"}, - { DB_PREFIX "gentoo-release", "gnt" }, - { DB_PREFIX "conectiva-release", "cnc" }, - { DB_PREFIX "versão-conectiva", "cnc" }, - { 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" }, - { DB_PREFIX "zenwalk-version", "zen" }, - { DB_PREFIX "DISTRO_SPECS", "ppy", "Puppy Linux" }, - { DB_PREFIX "puppyversion", "ppy", "Puppy Linux" }, - { DB_PREFIX "distro-release", "fl" }, - { DB_PREFIX "vine-release", "vine" }, - { DB_PREFIX "PartedMagic-version", "pmag" }, - /* - * RedHat must be the *last* one to be checked, since - * some distros (like Mandrake) includes a redhat-relase - * file too. - */ - { DB_PREFIX "redhat-release", "rh" }, -#undef DB_PREFIX - { NULL, NULL } - }; - 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"); - - if (tmp) - return g_strdup(tmp + strlen("Description:\t")); - } - - for (i = 0; distro_db[i].file; i++) { - if (!g_file_get_contents(distro_db[i].file, &contents, NULL, NULL)) - continue; - - if (distro_db[i].override) { - g_free(contents); - return g_strdup(distro_db[i].override); - } - - if (g_str_equal(distro_db[i].codename, "deb")) { - /* 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)); - } - - if (g_str_equal(distro_db[i].codename, "fatdog")) - return g_strdup_printf("Fatdog64 [%.10s]", (char*)idle_free(contents)); - - return contents; - } - - return g_strdup(_("Unknown")); -} - -OperatingSystem * -computer_get_os(void) -{ - struct utsname utsbuf; - OperatingSystem *os; - int i; - - os = g_new0(OperatingSystem, 1); - - os->distro = g_strstrip(detect_distro()); - - /* 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->hostname = g_strdup(utsbuf.nodename); - os->language = computer_get_language(); - os->homedir = g_strdup(g_get_home_dir()); - os->username = g_strdup_printf("%s (%s)", - g_get_user_name(), g_get_real_name()); - os->libc = get_libc_version(); - scan_languages(os); - - os->desktop = detect_desktop_environment(); - if (os->desktop) - os->desktop = desktop_with_session_type(idle_free(os->desktop)); - - os->entropy_avail = computer_get_entropy_avail(); - - return os; -} diff --git a/modules/computer/uptime.c b/modules/computer/uptime.c deleted file mode 100644 index 6ef3d250..00000000 --- a/modules/computer/uptime.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * 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. - * - * 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 "computer.h" - -UptimeInfo * -computer_get_uptime(void) -{ - UptimeInfo *ui = g_new0(UptimeInfo, 1); - FILE *procuptime; - gulong minutes; - - if ((procuptime = fopen("/proc/uptime", "r")) != NULL) { - (void)fscanf(procuptime, "%lu", &minutes); - ui->minutes = minutes / 60; - fclose(procuptime); - } else { - g_free(ui); - return NULL; - } - - ui->hours = ui->minutes / 60; - ui->minutes %= 60; - ui->days = ui->hours / 24; - ui->hours %= 24; - - return ui; -} - -gchar * -computer_get_formatted_uptime() -{ - UptimeInfo *ui; - const gchar *days_fmt, *hours_fmt, *minutes_fmt; - gchar *full_fmt = NULL, *ret = NULL; - - ui = computer_get_uptime(); - - days_fmt = ngettext("%d day", "%d days", ui->days); - hours_fmt = ngettext("%d hour", "%d hours", ui->hours); - minutes_fmt = ngettext("%d minute", "%d minutes", ui->minutes); - - if (ui->days < 1) { - if (ui->hours < 1) { - ret = g_strdup_printf(minutes_fmt, ui->minutes); - } else { - full_fmt = g_strdup_printf("%s %s", hours_fmt, minutes_fmt); - ret = g_strdup_printf(full_fmt, ui->hours, ui->minutes); - } - } else { - full_fmt = g_strdup_printf("%s %s %s", days_fmt, hours_fmt, minutes_fmt); - ret = g_strdup_printf(full_fmt, ui->days, ui->hours, ui->minutes); - } - g_free(full_fmt); - g_free(ui); - return ret; -} diff --git a/modules/computer/users.c b/modules/computer/users.c deleted file mode 100644 index f47320bb..00000000 --- a/modules/computer/users.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2009 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * 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. - * - * 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 <pwd.h> -#include "hardinfo.h" -#include "computer.h" - -gchar *users = NULL; - -void -scan_users_do(void) -{ - struct passwd *passwd_; - passwd_ = getpwent(); - if (!passwd_) - return; - - if (users) { - g_free(users); - moreinfo_del_with_prefix("COMP:USER"); - } - - users = g_strdup(""); - - while (passwd_) { - gchar *key = g_strdup_printf("USER%s", passwd_->pw_name); - gchar *val = g_strdup_printf("[%s]\n" - "%s=%d\n" - "%s=%d\n" - "%s=%s\n" - "%s=%s\n", - _("User Information"), - _("User ID"), (gint) passwd_->pw_uid, - _("Group ID"), (gint) passwd_->pw_gid, - _("Home Directory"), passwd_->pw_dir, - _("Default Shell"), passwd_->pw_shell); - moreinfo_add_with_prefix("COMP", key, val); - - strend(passwd_->pw_gecos, ','); - users = h_strdup_cprintf("$%s$%s=%s\n", users, key, passwd_->pw_name, passwd_->pw_gecos); - passwd_ = getpwent(); - g_free(key); - } - - endpwent(); -} |