diff options
Diffstat (limited to 'modules/computer')
| -rw-r--r-- | modules/computer/alsa.c | 71 | ||||
| -rw-r--r-- | modules/computer/boots.c | 65 | ||||
| -rw-r--r-- | modules/computer/display.c | 148 | ||||
| -rw-r--r-- | modules/computer/environment.c | 45 | ||||
| -rw-r--r-- | modules/computer/filesystem.c | 112 | ||||
| -rw-r--r-- | modules/computer/languages.c | 112 | ||||
| -rw-r--r-- | modules/computer/loadavg.c | 50 | ||||
| -rw-r--r-- | modules/computer/memory.c | 59 | ||||
| -rw-r--r-- | modules/computer/modules.c | 174 | ||||
| -rw-r--r-- | modules/computer/os.c | 220 | ||||
| -rw-r--r-- | modules/computer/uptime.c | 76 | ||||
| -rw-r--r-- | modules/computer/users.c | 65 | 
12 files changed, 1197 insertions, 0 deletions
| diff --git a/modules/computer/alsa.c b/modules/computer/alsa.c new file mode 100644 index 00000000..f1ff3ad8 --- /dev/null +++ b/modules/computer/alsa.c @@ -0,0 +1,71 @@ +/* + *    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("[Audio Devices]\n"); +    gint n = 0; + +    if (computer->alsa) { +	for (p = computer->alsa->cards; p; p = p->next) { +	    AlsaCard *ac = (AlsaCard *) p->data; + +	    tmp = h_strdup_cprintf("Audio Adapter#%d=%s\n", +	                           tmp, ++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 new file mode 100644 index 00000000..4a1023f6 --- /dev/null +++ b/modules/computer/boots.c @@ -0,0 +1,65 @@ +/* + *    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) +{ +    FILE *last; +    char buffer[256]; + +    scan_os(FALSE); + +    if (!computer->os->boots) +      computer->os->boots = g_strdup("[Boots]\n"); +    else +      return; +     +    last = popen("last", "r"); +    if (last) { +      while (fgets(buffer, 256, last)) { +        if (strstr(buffer, "system boot")) { +          gchar **tmp, *buf = buffer; +           +          strend(buffer, '\n'); +           +          while (*buf) { +            if (*buf == ' ' && *(buf + 1) == ' ') { +              strcpy(buf, buf + 1); +               +              buf--; +            } else { +              buf++; +            } +          } + +          tmp = g_strsplit(buffer, " ", 0); +          computer->os->boots = h_strdup_cprintf("\n%s %s %s %s=%s|%s", +                                                computer->os->boots, +						tmp[4], tmp[5], tmp[6], tmp[7], tmp[3], tmp[8]); +          g_strfreev(tmp); +        } +      } +       +      pclose(last); +    } +} diff --git a/modules/computer/display.c b/modules/computer/display.c new file mode 100644 index 00000000..ce23bbfd --- /dev/null +++ b/modules/computer/display.c @@ -0,0 +1,148 @@ +/* + *    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, ":", 0); + +            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); + +              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 new file mode 100644 index 00000000..8ef63b2d --- /dev/null +++ b/modules/computer/environment.c @@ -0,0 +1,45 @@ +/* + *    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("[Environment Variables]\n"); +    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 new file mode 100644 index 00000000..fcd8cf31 --- /dev/null +++ b/modules/computer/filesystem.c @@ -0,0 +1,112 @@ +/* + *    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; + +static gboolean +remove_filesystem_entries(gpointer key, gpointer value, gpointer data) +{ +    return g_str_has_prefix(key, "FS"); +} + +void +scan_filesystems(void) +{ +    FILE *mtab; +    gchar buf[1024]; +    struct statfs sfs; +    int count = 0; + +    g_free(fs_list); +    fs_list = g_strdup(""); +    g_hash_table_foreach_remove(moreinfo, remove_filesystem_entries, NULL); + +    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; +		if ((strhash = g_hash_table_lookup(moreinfo, tmp[0]))) { +		    g_hash_table_remove(moreinfo, tmp[0]); +		    g_free(strhash); +		} +		 +		strreplacechr(tmp[0], "#", '_'); +		 +		strhash = g_strdup_printf("[%s]\n" +					  "Filesystem=%s\n" +					  "Mounted As=%s\n" +					  "Mount Point=%s\n" +					  "Size=%s\n" +					  "Used=%s\n" +					  "Available=%s\n", +					  tmp[0], +					  tmp[2], +					  strstr(tmp[3], "rw") ? "Read-Write" : +					  "Read-Only", tmp[1], strsize, strused, +					  stravail); +		g_hash_table_insert(moreinfo, g_strdup_printf("FS%d", ++count), strhash); + +		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/languages.c b/modules/computer/languages.c new file mode 100644 index 00000000..2808da1b --- /dev/null +++ b/modules/computer/languages.c @@ -0,0 +1,112 @@ +/* + *    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" + +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); + +#define FIELD(f) f ? f : "(Unknown)" +	    currlocale = g_strdup_printf("[Locale Information]\n" +					 "Name=%s (%s)\n" +					 "Source=%s\n" +					 "Address=%s\n" +					 "Email=%s\n" +					 "Language=%s\n" +					 "Territory=%s\n" +					 "Revision=%s\n" +					 "Date=%s\n" +					 "Codeset=%s\n", +					 name, FIELD(title), +					 FIELD(source), FIELD(address), +					 FIELD(email), FIELD(language), +					 FIELD(territory), FIELD(revision), +					 FIELD(date), FIELD(codeset)); +#undef FIELD + +	    g_hash_table_insert(moreinfo, g_strdup(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 new file mode 100644 index 00000000..523812be --- /dev/null +++ b/modules/computer/loadavg.c @@ -0,0 +1,50 @@ +/* + *    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" + +LoadInfo * +computer_get_loadinfo(void) +{ +    LoadInfo *li = g_new0(LoadInfo, 1); +    FILE *procloadavg; + +    procloadavg = fopen("/proc/loadavg", "r"); +    (void)fscanf(procloadavg, "%f %f %f", &(li->load1), &(li->load5), +	   &(li->load15)); +    fclose(procloadavg); + +    return li; +} + +gchar * +computer_get_formatted_loadavg() +{ +    LoadInfo *li; +    gchar *tmp; + +    li = computer_get_loadinfo(); + +    tmp = +	g_strdup_printf("%.2f, %.2f, %.2f", li->load1, li->load5, +			li->load15); + +    g_free(li); +    return tmp; +} diff --git a/modules/computer/memory.c b/modules/computer/memory.c new file mode 100644 index 00000000..3d320e8a --- /dev/null +++ b/modules/computer/memory.c @@ -0,0 +1,59 @@ +/* + *    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); + +	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 new file mode 100644 index 00000000..195c444b --- /dev/null +++ b/modules/computer/modules.c @@ -0,0 +1,174 @@ +/* + *    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" + +#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;                        					\ +  } + +static gboolean +remove_module_devices(gpointer key, gpointer value, gpointer data) +{ +    return g_str_has_prefix(key, "MOD"); +} + +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); +    } + +    if (module_list) { +        g_free(module_list); +    } +     +    module_list = NULL; +    g_hash_table_foreach_remove(moreinfo, remove_module_devices, NULL); + +    lsmod_path = find_program("lsmod"); +    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 : ""); + +#define NONE_IF_NULL(var) (var) ? (var) : "N/A" + +	/* create the module information string */ +	strmodule = g_strdup_printf("[Module Information]\n" +				    "Path=%s\n" +				    "Used Memory=%.2fKiB\n" +				    "[Description]\n" +				    "Name=%s\n" +				    "Description=%s\n" +				    "Version Magic=%s\n" +				    "[Copyright]\n" +				    "Author=%s\n" +				    "License=%s\n", +				    NONE_IF_NULL(filename), +				    memory / 1024.0, +				    modname, +				    NONE_IF_NULL(description), +				    NONE_IF_NULL(vermagic), +				    NONE_IF_NULL(author), +				    NONE_IF_NULL(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); +	} + +	g_hash_table_insert(moreinfo, hashkey, strmodule); + +	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 new file mode 100644 index 00000000..36b061fc --- /dev/null +++ b/modules/computer/os.c @@ -0,0 +1,220 @@ +/* + *    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 <sys/utsname.h> +#include "hardinfo.h" +#include "computer.h" + +static gchar * +get_libc_version(void) +{ +    FILE *libc; +    gchar buf[256], *tmp, *p; + +    if (g_file_test("/lib/ld-uClibc.so.0", G_FILE_TEST_EXISTS)) { +      return g_strdup("uClibc Library"); +    } else if (!g_file_test("/lib/libc.so.6", G_FILE_TEST_EXISTS)) { +      goto err; +    } +    +    libc = popen("/lib/libc.so.6", "r"); +    if (!libc) goto err; +     +    (void)fgets(buf, 256, libc); +    if (pclose(libc)) goto err; +     +    tmp = strstr(buf, "version "); +    if (!tmp) goto err; +     +    p = strchr(tmp, ','); +    if (p) *p = '\0'; +    else goto err; +     +    return g_strdup_printf("GNU C Library version %s (%sstable)", +                           strchr(tmp, ' ') + 1, +                           strstr(buf, " stable ") ? "" : "un"); +  err: +    return g_strdup("Unknown"); +} + +#include <gdk/gdkx.h> + +void +detect_desktop_environment(OperatingSystem * os) +{ +    const gchar *tmp = g_getenv("GNOME_DESKTOP_SESSION_ID"); +    FILE *version; +    char vers[16]; + +    if (tmp) { +	/* FIXME: this might not be true, as the gnome-panel in path +	   may not be the one that's running. +	   see where the user's running panel is and run *that* to +	   obtain the version. */ +	version = popen("gnome-about --gnome-version", "r"); +	if (version) { +	    (void)fscanf(version, "Version: %s", vers); +	    if (pclose(version)) +	        goto unknown; +	} else { +	    goto unknown; +	} + +	os->desktop = g_strdup_printf("GNOME %s", vers); +    } else if (g_getenv("KDE_FULL_SESSION")) { + +	if (g_getenv("KDE_SESSION_VERSION") && strstr(g_getenv("KDE_SESSION_VERSION"),(gchar *)"4")) { +	    version = popen("kwin --version", "r"); +	} else { +	    version = popen("kcontrol --version", "r"); +	} + +	if (version) { +	    char buf[32]; + +	    (void)fgets(buf, 32, version); + +	    (void)fscanf(version, "KDE: %s", vers); +	    if (pclose(version)) +	        goto unknown; +	} else { +	    goto unknown; +	} + +	os->desktop = g_strdup_printf("KDE %s", vers); +    } else { +      unknown: +	if (!g_getenv("DISPLAY")) { +	    os->desktop = g_strdup("Terminal"); +	} else { +            GdkScreen *screen = gdk_screen_get_default(); +             +            if (screen && GDK_IS_SCREEN(screen)) { +              const gchar *windowman; + +              windowman = gdk_x11_screen_get_window_manager_name(screen); +               +              if (g_str_equal(windowman, "Xfwm4")) { +                  /* FIXME: check if xprop -root | grep XFCE_DESKTOP_WINDOW +                     is defined */ +                  os->desktop = g_strdup("XFCE 4"); +              } else { +                  os->desktop = g_strdup_printf("Unknown (Window Manager: %s)", +                                                windowman); +              } +            } else { +              os->desktop = g_strdup("Unknown"); +            } +	} +    } +} + +OperatingSystem * +computer_get_os(void) +{ +    struct utsname utsbuf; +    OperatingSystem *os; +    int i; + +    os = g_new0(OperatingSystem, 1); + +    /* Attempt to get the Distribution name; try using /etc/lsb-release first, +       then doing the legacy method (checking for /etc/$DISTRO-release files) */ +    if (g_file_test("/etc/lsb-release", G_FILE_TEST_EXISTS)) { +	FILE *release; +	gchar buffer[128]; + +	release = popen("lsb_release -d", "r"); +	if (release) { +            (void)fgets(buffer, 128, release); +            pclose(release); + +            os->distro = buffer; +            os->distro = g_strdup(os->distro + strlen("Description:\t")); +        } +    } + +    for (i = 0;; i++) { +	if (distro_db[i].file == NULL) { +	    os->distrocode = g_strdup("unk"); +	    os->distro = g_strdup("Unknown distribution"); +	    break; +	} + +	if (g_file_test(distro_db[i].file, G_FILE_TEST_EXISTS)) { +	    FILE *distro_ver; +	    char buf[128]; + +	    distro_ver = fopen(distro_db[i].file, "r"); +	    if (distro_ver) { +                (void)fgets(buf, 128, distro_ver); +                fclose(distro_ver); +            } else { +                continue; +            } + +	    buf[strlen(buf) - 1] = 0; + +	    if (!os->distro) { +		/* +		 * HACK: Some Debian systems doesn't include +		 * the distribuition name in /etc/debian_release, +		 * so add them here.  +		 */ +		if (!strncmp(distro_db[i].codename, "deb", 3) && +		    ((buf[0] >= '0' && buf[0] <= '9') || buf[0] != 'D')) { +		    os->distro = g_strdup_printf +			("Debian GNU/Linux %s", buf); +		} else { +		    os->distro = g_strdup(buf); +		} +	    } +	     +	    if (g_str_equal(distro_db[i].codename, "ppy")) { +	      gchar *tmp; +	       +	      tmp = g_strdup_printf("Puppy Linux %.2f", atof(os->distro) / 100.0); +	      g_free(os->distro); +	      os->distro = tmp; +	    } +	     +	    os->distrocode = g_strdup(distro_db[i].codename); + +	    break; +	} +    } + +    os->distro = g_strstrip(os->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 = g_strdup(g_getenv("LC_MESSAGES")); +    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); +    detect_desktop_environment(os); + +    return os; +} diff --git a/modules/computer/uptime.c b/modules/computer/uptime.c new file mode 100644 index 00000000..8eb563fa --- /dev/null +++ b/modules/computer/uptime.c @@ -0,0 +1,76 @@ +/* + *    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 { +	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; +    gchar *tmp; + +    ui = computer_get_uptime(); + +    /* FIXME: Use ngettext */ +#define plural(x) ((x > 1) ? "s" : "") + +    if (ui->days < 1) { +	if (ui->hours < 1) { +	    tmp = +		g_strdup_printf("%d minute%s", ui->minutes, +				plural(ui->minutes)); +	} else { +	    tmp = +		g_strdup_printf("%d hour%s, %d minute%s", ui->hours, +				plural(ui->hours), ui->minutes, +				plural(ui->minutes)); +	} +    } else { +	tmp = +	    g_strdup_printf("%d day%s, %d hour%s and %d minute%s", +			    ui->days, plural(ui->days), ui->hours, +			    plural(ui->hours), ui->minutes, +			    plural(ui->minutes)); +    } + +    g_free(ui); +    return tmp; +} diff --git a/modules/computer/users.c b/modules/computer/users.c new file mode 100644 index 00000000..e303ac6e --- /dev/null +++ b/modules/computer/users.c @@ -0,0 +1,65 @@ +/* + *    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; + +static gboolean +remove_users(gpointer key, gpointer value, gpointer data) +{ +    return g_str_has_prefix(key, "USER"); +} + +void +scan_users_do(void) +{ +    struct passwd *passwd_; +    passwd_ = getpwent(); +    if (!passwd_) +        return; + +    if (users) { +        g_free(users); +        g_hash_table_foreach_remove(moreinfo, remove_users, NULL); +    } + +    users = g_strdup(""); + +    while (passwd_) { +        gchar *key = g_strdup_printf("USER%s", passwd_->pw_name); +        gchar *val = g_strdup_printf("[User Information]\n" +                "User ID=%d\n" +                "Group ID=%d\n" +                "Home directory=%s\n" +                "Default shell=%s\n", +                (gint) passwd_->pw_uid, +                (gint) passwd_->pw_gid, +                passwd_->pw_dir, +                passwd_->pw_shell); +        g_hash_table_insert(moreinfo, key, val); + +        strend(passwd_->pw_gecos, ','); +        users = h_strdup_cprintf("$%s$%s=%s\n", users, key, passwd_->pw_name, passwd_->pw_gecos); +        passwd_ = getpwent(); +    } +     +    endpwent(); +} | 
