diff options
author | Leandro A. F. Pereira <leandro@hardinfo.org> | 2010-05-03 09:25:43 -0300 |
---|---|---|
committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2010-05-03 09:25:43 -0300 |
commit | 9a50155ec3e27aa6cedf3f118196f1947c769a29 (patch) | |
tree | c23cc6949b227b9e09432af038a44ccb81d92ce6 | |
parent | ca5a3e84296a34c2391374942001cfaf1d8395a6 (diff) |
Use CMake instead of ToscoConf.
-rw-r--r-- | hardinfo2/.gitignore | 2 | ||||
-rw-r--r-- | hardinfo2/CMakeLists.txt | 184 | ||||
-rw-r--r-- | hardinfo2/Makefile.in | 75 | ||||
-rwxr-xr-x | hardinfo2/configure | 299 | ||||
-rw-r--r-- | hardinfo2/hardinfo/hardinfo.c (renamed from hardinfo2/hardinfo.c) | 2 | ||||
-rw-r--r-- | hardinfo2/help-viewer/egg-markdown.c (renamed from hardinfo2/egg-markdown.c) | 0 | ||||
-rw-r--r-- | hardinfo2/help-viewer/help-viewer.c (renamed from hardinfo2/help-viewer.c) | 0 | ||||
-rw-r--r-- | hardinfo2/help-viewer/markdown-text-view.c (renamed from hardinfo2/markdown-text-view.c) | 0 | ||||
-rw-r--r-- | hardinfo2/includes/benchmark.h | 21 | ||||
-rw-r--r-- | hardinfo2/includes/binreloc.h (renamed from hardinfo2/binreloc.h) | 0 | ||||
-rw-r--r-- | hardinfo2/includes/blowfish.h (renamed from hardinfo2/blowfish.h) | 0 | ||||
-rw-r--r-- | hardinfo2/includes/callbacks.h (renamed from hardinfo2/callbacks.h) | 0 | ||||
-rw-r--r-- | hardinfo2/includes/computer.h (renamed from hardinfo2/computer.h) | 24 | ||||
-rw-r--r-- | hardinfo2/includes/devices.h | 87 | ||||
-rw-r--r-- | hardinfo2/includes/egg-markdown.h (renamed from hardinfo2/egg-markdown.h) | 0 | ||||
-rw-r--r-- | hardinfo2/includes/expr.h (renamed from hardinfo2/expr.h) | 0 | ||||
-rw-r--r-- | hardinfo2/includes/fftbench.h (renamed from hardinfo2/fftbench.h) | 0 | ||||
-rw-r--r-- | hardinfo2/includes/guibench.h (renamed from hardinfo2/guibench.h) | 0 | ||||
-rw-r--r-- | hardinfo2/includes/hardinfo.h (renamed from hardinfo2/hardinfo.h) | 4 | ||||
-rw-r--r-- | hardinfo2/includes/help-viewer.h (renamed from hardinfo2/help-viewer.h) | 0 | ||||
-rw-r--r-- | hardinfo2/includes/iconcache.h (renamed from hardinfo2/iconcache.h) | 0 | ||||
-rw-r--r-- | hardinfo2/includes/loadgraph.h (renamed from hardinfo2/loadgraph.h) | 0 | ||||
-rw-r--r-- | hardinfo2/includes/markdown-text-view.h (renamed from hardinfo2/markdown-text-view.h) | 0 | ||||
-rw-r--r-- | hardinfo2/includes/md5.h (renamed from hardinfo2/md5.h) | 0 | ||||
-rw-r--r-- | hardinfo2/includes/menu.h (renamed from hardinfo2/menu.h) | 0 | ||||
-rw-r--r-- | hardinfo2/includes/network.h | 14 | ||||
-rw-r--r-- | hardinfo2/includes/nqueens.h (renamed from hardinfo2/nqueens.h) | 0 | ||||
-rw-r--r-- | hardinfo2/includes/remote.h (renamed from hardinfo2/remote.h) | 0 | ||||
-rw-r--r-- | hardinfo2/includes/report.h (renamed from hardinfo2/report.h) | 0 | ||||
-rw-r--r-- | hardinfo2/includes/sha1.h (renamed from hardinfo2/sha1.h) | 0 | ||||
-rw-r--r-- | hardinfo2/includes/shell.h (renamed from hardinfo2/shell.h) | 0 | ||||
-rw-r--r-- | hardinfo2/includes/socket.h (renamed from hardinfo2/socket.h) | 0 | ||||
-rw-r--r-- | hardinfo2/includes/ssh-conn.h (renamed from hardinfo2/ssh-conn.h) | 0 | ||||
-rw-r--r-- | hardinfo2/includes/stock.h (renamed from hardinfo2/stock.h) | 0 | ||||
-rw-r--r-- | hardinfo2/includes/syncmanager.h (renamed from hardinfo2/syncmanager.h) | 0 | ||||
-rw-r--r-- | hardinfo2/includes/test-utils.h | 24 | ||||
-rw-r--r-- | hardinfo2/includes/uidefs.h (renamed from hardinfo2/uidefs.h) | 0 | ||||
-rw-r--r-- | hardinfo2/includes/vendor.h (renamed from hardinfo2/vendor.h) | 0 | ||||
-rw-r--r-- | hardinfo2/includes/x86/processor-platform.h | 36 | ||||
-rw-r--r-- | hardinfo2/includes/xmlrpc-client.h (renamed from hardinfo2/xmlrpc-client.h) | 0 | ||||
-rw-r--r-- | hardinfo2/includes/xmlrpc-server.h (renamed from hardinfo2/xmlrpc-server.h) | 0 | ||||
-rw-r--r-- | hardinfo2/modules/benchmark.c (renamed from hardinfo2/benchmark.c) | 19 | ||||
-rw-r--r-- | hardinfo2/modules/benchmark/blowfish.c (renamed from hardinfo2/blowfish.c) | 0 | ||||
-rw-r--r-- | hardinfo2/modules/benchmark/cryptohash.c | 79 | ||||
-rw-r--r-- | hardinfo2/modules/benchmark/drawing.c | 29 | ||||
-rw-r--r-- | hardinfo2/modules/benchmark/fbench.c (renamed from hardinfo2/fbench.c) | 0 | ||||
-rw-r--r-- | hardinfo2/modules/benchmark/fft.c | 65 | ||||
-rw-r--r-- | hardinfo2/modules/benchmark/fftbench.c (renamed from hardinfo2/fftbench.c) | 0 | ||||
-rw-r--r-- | hardinfo2/modules/benchmark/fib.c | 50 | ||||
-rw-r--r-- | hardinfo2/modules/benchmark/guibench.c (renamed from hardinfo2/guibench.c) | 0 | ||||
-rw-r--r-- | hardinfo2/modules/benchmark/md5.c (renamed from hardinfo2/md5.c) | 0 | ||||
-rw-r--r-- | hardinfo2/modules/benchmark/nqueens.c (renamed from hardinfo2/nqueens.c) | 0 | ||||
-rw-r--r-- | hardinfo2/modules/benchmark/raytrace.c | 47 | ||||
-rw-r--r-- | hardinfo2/modules/benchmark/sha1.c (renamed from hardinfo2/sha1.c) | 0 | ||||
-rw-r--r-- | hardinfo2/modules/computer.c (renamed from hardinfo2/computer.c) | 25 | ||||
-rw-r--r-- | hardinfo2/modules/computer/alsa.c | 71 | ||||
-rw-r--r-- | hardinfo2/modules/computer/boots.c | 65 | ||||
-rw-r--r-- | hardinfo2/modules/computer/display.c | 148 | ||||
-rw-r--r-- | hardinfo2/modules/computer/environment.c | 45 | ||||
-rw-r--r-- | hardinfo2/modules/computer/filesystem.c | 112 | ||||
-rw-r--r-- | hardinfo2/modules/computer/languages.c | 112 | ||||
-rw-r--r-- | hardinfo2/modules/computer/loadavg.c | 50 | ||||
-rw-r--r-- | hardinfo2/modules/computer/memory.c | 59 | ||||
-rw-r--r-- | hardinfo2/modules/computer/modules.c | 174 | ||||
-rw-r--r-- | hardinfo2/modules/computer/os.c | 220 | ||||
-rw-r--r-- | hardinfo2/modules/computer/uptime.c | 76 | ||||
-rw-r--r-- | hardinfo2/modules/computer/users.c | 65 | ||||
-rw-r--r-- | hardinfo2/modules/devices.c (renamed from hardinfo2/devices.c) | 82 | ||||
-rw-r--r-- | hardinfo2/modules/devices/battery.c | 307 | ||||
-rw-r--r-- | hardinfo2/modules/devices/devmemory.c | 107 | ||||
-rw-r--r-- | hardinfo2/modules/devices/dmi.c | 200 | ||||
-rw-r--r-- | hardinfo2/modules/devices/inputdevices.c | 144 | ||||
-rw-r--r-- | hardinfo2/modules/devices/pci.c | 245 | ||||
-rw-r--r-- | hardinfo2/modules/devices/printers.c | 271 | ||||
-rw-r--r-- | hardinfo2/modules/devices/resources.c | 105 | ||||
-rw-r--r-- | hardinfo2/modules/devices/sensors.c | 383 | ||||
-rw-r--r-- | hardinfo2/modules/devices/storage.c | 377 | ||||
-rw-r--r-- | hardinfo2/modules/devices/usb.c | 349 | ||||
-rw-r--r-- | hardinfo2/modules/devices/x86/processor.c | 562 | ||||
-rw-r--r-- | hardinfo2/modules/network.c (renamed from hardinfo2/network.c) | 8 | ||||
-rw-r--r-- | hardinfo2/modules/network/net.c | 454 | ||||
-rw-r--r-- | hardinfo2/modules/network/nfs.c | 61 | ||||
-rw-r--r-- | hardinfo2/modules/network/samba.c | 124 | ||||
-rw-r--r-- | hardinfo2/remote/remote.c (renamed from hardinfo2/remote.c) | 0 | ||||
-rw-r--r-- | hardinfo2/remote/ssh-conn.c (renamed from hardinfo2/ssh-conn.c) | 0 | ||||
-rw-r--r-- | hardinfo2/remote/xmlrpc-client.c (renamed from hardinfo2/xmlrpc-client.c) | 0 | ||||
-rw-r--r-- | hardinfo2/remote/xmlrpc-server.c (renamed from hardinfo2/xmlrpc-server.c) | 0 | ||||
-rw-r--r-- | hardinfo2/shell/callbacks.c (renamed from hardinfo2/callbacks.c) | 0 | ||||
-rw-r--r-- | hardinfo2/shell/iconcache.c (renamed from hardinfo2/iconcache.c) | 4 | ||||
-rw-r--r-- | hardinfo2/shell/loadgraph.c (renamed from hardinfo2/loadgraph.c) | 0 | ||||
-rw-r--r-- | hardinfo2/shell/menu.c (renamed from hardinfo2/menu.c) | 0 | ||||
-rw-r--r-- | hardinfo2/shell/report.c (renamed from hardinfo2/report.c) | 0 | ||||
-rw-r--r-- | hardinfo2/shell/shell.c (renamed from hardinfo2/shell.c) | 0 | ||||
-rw-r--r-- | hardinfo2/shell/stock.c (renamed from hardinfo2/stock.c) | 0 | ||||
-rw-r--r-- | hardinfo2/shell/syncmanager.c (renamed from hardinfo2/syncmanager.c) | 0 | ||||
-rw-r--r-- | hardinfo2/util/binreloc.c (renamed from hardinfo2/binreloc.c) | 0 | ||||
-rw-r--r-- | hardinfo2/util/expr.c (renamed from hardinfo2/expr.c) | 0 | ||||
-rw-r--r-- | hardinfo2/util/socket.c (renamed from hardinfo2/socket.c) | 0 | ||||
-rw-r--r-- | hardinfo2/util/util.c (renamed from hardinfo2/util.c) | 19 | ||||
-rw-r--r-- | hardinfo2/util/vendor.c (renamed from hardinfo2/vendor.c) | 0 |
100 files changed, 5599 insertions, 486 deletions
diff --git a/hardinfo2/.gitignore b/hardinfo2/.gitignore index 74b81873..000e8741 100644 --- a/hardinfo2/.gitignore +++ b/hardinfo2/.gitignore @@ -1,7 +1,5 @@ -hardinfo Makefile config.h -modules/* *.so *.o *~ diff --git a/hardinfo2/CMakeLists.txt b/hardinfo2/CMakeLists.txt new file mode 100644 index 00000000..24641294 --- /dev/null +++ b/hardinfo2/CMakeLists.txt @@ -0,0 +1,184 @@ +project(HardInfo) +cmake_minimum_required(VERSION 2.6) + +if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux") + set(HARDINFO_OS "linux") +else() + message(FATAL_ERROR "Unsupported operating system: ${CMAKE_HOST_SYSTEM_NAME}") +endif() + +if(${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "i[3-6]86|x86_64") + set(HARDINFO_ARCH "x86") +elseif(${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "ppc{32,64}") + set(HARDINFO_ARCH "ppc") +elseif(${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "mips") + set(HARDINFO_ARCH "mips") +elseif(${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "parisc.*") + set(HARDINFO_ARCH "parisc") +elseif(${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "sparc{32,64}") + set(HARDINFO_ARCH "sparc") +elseif(${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "arm.*") + set(HARDINFO_ARCH "arm") +elseif(${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "ia64") + set(HARDINFO_ARCH "ia64") +elseif(${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "alpha") + set(HARDINFO_ARCH "alpha") +elseif(${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "s390.*") + set(HARDINFO_ARCH "s390") +elseif(${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "m68k") + set(HARDINFO_ARCH "m68k") +elseif(${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "sh{3,4}") + set(HARDINFO_ARCH "sh") +else() + message(FATAL_ERROR "Unsupported architecture: ${CMAKE_HOST_SYSTEM_PROCESSOR}") +endif() + +message(STATUS "Building HardInfo for architecture: ${HARDINFO_OS}-${HARDINFO_ARCH}") + +include(FindPkgConfig) +pkg_check_modules(GTK REQUIRED gtk+-2.0>=2.10 glib-2.0>=2.10 gthread-2.0>=2.10) +pkg_check_modules(LIBSOUP libsoup-2.4>=2.26) + +include_directories( + ${CMAKE_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/includes + ${CMAKE_SOURCE_DIR}/includes/${HARDINFO_ARCH} + ${GTK_INCLUDE_DIRS} + ${LIBSOUP_INCLUDE_DIRS} +) +link_directories( + ${GTK_LIBRARY_DIRS} + ${LIBSOUP_LIBRARY_DIRS} +) + +set(HARDINFO_MODULES + computer + devices + benchmark + network +) +set(HARDINFO_RESOURCES + "benchmark.conf" + "benchmark.data" +) + +set(MODULE_computer_SOURCES + modules/computer.c + modules/computer/alsa.c + modules/computer/boots.c + modules/computer/display.c + modules/computer/environment.c + modules/computer/filesystem.c + modules/computer/languages.c + modules/computer/loadavg.c + modules/computer/memory.c + modules/computer/modules.c + modules/computer/os.c + modules/computer/uptime.c + modules/computer/users.c +) +set(MODULE_devices_SOURCES + modules/devices.c + modules/devices/${HARDINFO_ARCH}/processor.c + modules/devices/battery.c + modules/devices/devmemory.c + modules/devices/dmi.c + modules/devices/inputdevices.c + modules/devices/pci.c + modules/devices/printers.c + modules/devices/resources.c + modules/devices/sensors.c + modules/devices/storage.c + modules/devices/usb.c +) +set(MODULE_network_SOURCES + modules/network.c + modules/network/net.c + modules/network/nfs.c + modules/network/samba.c +) +set(MODULE_benchmark_SOURCES + modules/benchmark.c + modules/benchmark/blowfish.c + modules/benchmark/cryptohash.c + modules/benchmark/drawing.c + modules/benchmark/fbench.c + modules/benchmark/fftbench.c + modules/benchmark/fib.c + modules/benchmark/guibench.c + modules/benchmark/md5.c + modules/benchmark/nqueens.c + modules/benchmark/raytrace.c + modules/benchmark/sha1.c +) + +foreach (_module ${HARDINFO_MODULES}) + add_library(${_module} MODULE ${MODULE_${_module}_SOURCES}) +endforeach() + +add_library(hardinfo-remote SHARED + remote/remote.c + remote/ssh-conn.c + remote/xmlrpc-client.c + remote/xmlrpc-server.c +) +add_library(hardinfo-help-viewer SHARED + help-viewer/egg-markdown.c + help-viewer/help-viewer.c + help-viewer/markdown-text-view.c +) +add_library(hardinfo-shell SHARED + shell/callbacks.c + shell/iconcache.c + shell/loadgraph.c + shell/menu.c + shell/report.c + shell/shell.c + shell/stock.c + shell/syncmanager.c +) +add_library(hardinfo-util SHARED + util/binreloc.c + util/expr.c + util/socket.c + util/vendor.c + util/util.c +) +add_executable(hardinfo + hardinfo/hardinfo.c +) +target_link_libraries(hardinfo + ${GTK_LIBRARIES} + ${LIBSOUP_LIBRARIES} + hardinfo-shell + hardinfo-util +) +target_link_libraries(hardinfo-shell + hardinfo-help-viewer + hardinfo-remote +) + +install(TARGETS hardinfo ${HARDINFO_MODULES} + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib/hardinfo/modules + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE +) +install(TARGETS hardinfo-shell hardinfo-util hardinfo-help-viewer hardinfo-remote + LIBRARY DESTINATION lib + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE +) +install(FILES ${HARDINFO_RESOURCES} + DESTINATION share/hardinfo + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +) +install(DIRECTORY pixmaps + DESTINATION share/hardinfo + PATTERN "*.{png,svg}" + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +) +install(DIRECTORY doc + DESTINATION share/hardinfo + PATTERN "*.{hlp,png}" + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +) +
\ No newline at end of file diff --git a/hardinfo2/Makefile.in b/hardinfo2/Makefile.in deleted file mode 100644 index ab41e6bc..00000000 --- a/hardinfo2/Makefile.in +++ /dev/null @@ -1,75 +0,0 @@ - -CCFLAGS = -fPIC -pipe -Wall -Werror -g -CFLAGS = $(GTK_CFLAGS) $(SOUP_CFLAGS) -I. -CC = gcc $(ARCHOPTS) $(CCFLAGS) -CCSLOW = gcc -O0 $(CCFLAGS) - -# ---------------------------------------------------------------------------- - -OBJECTS = hardinfo.o shell.o util.o iconcache.o loadgraph.o \ - menu.o stock.o callbacks.o expr.o report.o binreloc.o \ - vendor.o socket.o syncmanager.o remote.o xmlrpc-server.o \ - xmlrpc-client.o ssh-conn.o egg-markdown.o markdown-text-view.o \ - help-viewer.o -BENCHMARK_OBJECTS = fbench.o sha1.o blowfish.o md5.o nqueens.o fftbench.o guibench.o - -MODULES = computer.so devices.so benchmark.so network.so - -all: hardinfo - -hardinfo: $(OBJECTS) $(MODULES) - $(CC) $(CCFLAGS) -o hardinfo -Wl,-export-dynamic $(OBJECTS) $(GTK_LIBS) \ - $(SOUP_LIBS) - -$(BENCHMARK_OBJECTS): - $(CCSLOW) $(CCFLAGS) $(CFLAGS) -c $*.c -o $@ - -benchmark.so: benchmark.c $(BENCHMARK_OBJECTS) - $(CC) $(CCFLAGS) $(CFLAGS) -o $@ -shared $< $(GTK_FLAGS) $(GTK_LIBS) $(BENCHMARK_OBJECTS) - -%.so: %.c - $(CC) $(CCFLAGS) $(CFLAGS) -o $@ -shared $< $(GTK_FLAGS) $(GTK_LIBS) - -clean: - rm -rf .xvpics pixmaps/.xvpics *.o *.so hardinfo report - find . -name \*~ -exec rm -v {} \; - find . -name x86 -type l -exec rm -v {} \; - -dist-clean: clean - rm -rf Makefile debian/hardinfo/ config.h arch/this - -package: dist-clean - @echo "Creating tar.gz..." - cd .. && tar czf $(PACKAGE).tar.gz $(PACKAGE)/* && cd $(PACKAGE) - @echo "Creating tar.bz2..." - cd .. && tar cjf $(PACKAGE).tar.bz2 $(PACKAGE)/* && cd $(PACKAGE) - -deb: dist-clean - @echo "Creating deb..." - dpkg-buildpackage -rfakeroot -k${USER} - -install: all - - rm -rf ${DESTDIR}${LIBDIR}/hardinfo/modules ${DESTDIR}/usr/share/hardinfo/pixmaps - - install -d ${DESTDIR}/usr/bin - install -d ${DESTDIR}/usr/local - install -d ${DESTDIR}/usr/share/applications - install -d ${DESTDIR}${LIBDIR}/hardinfo/modules - install -d ${DESTDIR}/usr/share/hardinfo/pixmaps - install -d ${DESTDIR}/usr/share/hardinfo/doc - - install -m 644 hardinfo.desktop ${DESTDIR}/usr/share/applications - install -m 755 hardinfo ${DESTDIR}/usr/bin/hardinfo - - install -m 755 ${MODULES} ${DESTDIR}${LIBDIR}/hardinfo/modules - install -m 644 pixmaps/* ${DESTDIR}/usr/share/hardinfo/pixmaps - install -m 644 doc/*.hlp ${DESTDIR}/usr/share/hardinfo/doc || true - install -m 644 doc/*.png ${DESTDIR}/usr/share/hardinfo/doc || true - - install -m 644 benchmark.conf ${DESTDIR}/usr/share/hardinfo - install -m 644 benchmark.data ${DESTDIR}/usr/share/hardinfo - -installer: - makepackage - diff --git a/hardinfo2/configure b/hardinfo2/configure deleted file mode 100755 index e68b61c3..00000000 --- a/hardinfo2/configure +++ /dev/null @@ -1,299 +0,0 @@ -#!/usr/bin/env bash -# -# ToscoConf 0.05 -# Copyright (c) 2003-2009 Leandro Pereira <leandro@hardinfo.org> -# All rights reserved. -# -# This script is in the Tosco Public License. It may be copied and/or -# modified, in whole or in part, provided that all copies must retain the -# above copyright notice, this condition and the following disclaimer. -# -# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, -# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# -# --------------------------------------------------------------------------- - -function usage { - echo "Usage: [-l libdir] [-r release] [-h]" - echo " -l libdir Specify the library dir [default=autodetect]" - echo " -r release Build a (release,debug) version [default=autodetect]" - echo " -h This help" -} - -ARGS=`getopt l:p:r:h $*` -if test $? != 0; then - usage - exit 1 -fi -set -- $ARGS - -FORCE_LIBDIR="" -FORCE_RELEASE="" - -for arg; do - case "$arg" in - -l) - shift; - FORCE_LIBDIR=$1; - shift ;; - -h) - usage; - exit 0 ;; - -r) - shift; - case "$1" in - release|debug) - FORCE_RELEASE=$1 ;; - *) - echo "Invalid build type; use either release or debug" - exit 1 ;; - esac - shift;; - esac -done - -# --------------------------------------------------------------------------- - -PACKAGE=`basename ${PWD} | cut -d"-" -f1`; -VERSION=`basename ${PWD} | cut -d"-" -f2`; - -if [ "$PACKAGE" == "$VERSION" ]; then - VERSION=$(date +"%F.%H:%M:%S") - RELEASE=0 -else - RELEASE=1 -fi - -echo "ToscoConf (version 0.05) for $PACKAGE version $VERSION" - -# --------------------------------------------------------------------------- - -case "$FORCE_RELEASE" in - debug) RELEASE=0;; - release) RELEASE=1;; -esac - -# --------------------------------------------------------------------------- - -echo "Determining system architecture." -OS=`uname` -case $OS in - Linux) - ;; - *) - echo "$OS (not supported, yet!)" - exit ;; -esac - -PROC=`uname -m` -LIBDIR='/usr/lib' -case $PROC in - i?86) - ln -sf linux/x86 arch/this - ARCH="ARCH_i386" ;; - ppc*) - ln -sf linux/ppc arch/this - ARCH="ARCH_PPC" ;; - x86_64) - ln -sf linux/x86_64 arch/this - ARCH="ARCH_x86_64" - LIBDIR="/usr/lib64" ;; - mips*) - ln -sf linux/mips arch/this - ARCH="ARCH_MIPS" ;; - parisc*) - ln -sf linux/parisc arch/this - ARCH="ARCH_PARISC" ;; - sparc*) - ln -sf linux/sparc arch/this - ARCH="ARCH_SPARC" ;; - armv*) - ln -sf linux/armv4l arch/this - ARCH="ARCH_ARMV4L" ;; - ia64) - ln -sf linux/ia64 arch/this - ARCH="ARCH_IA64" ;; - alpha) - ln -sf linux/alpha arch/this - ARCH="ARCH_ALPHA" ;; - s390*) - ln -sf linux/s390 arch/this - ARCH="ARCH_S390" ;; - m68k) - ln -sf linux/m68k arch/this - ARCH="ARCH_m68k" ;; - sh*) - ln -sf linux/sh arch/this - ARCH="ARCH_sh" ;; -esac - -if [ "x$ARCH" == "x" ]; then - echo "Your architecture is not supported yet. Please send the" - echo "output of the following commands to leandro@hardinfo.org:" - echo "" - echo " $ cat /proc/cpuinfo" - echo " $ uname -a" - echo " $ uname -m" - exit 1 -fi - -# --------------------------------------------------------------------------- - -echo "Building $PACKAGE for $OS $PROC ($ARCH)." -echo "" - -# --------------------------------------------------------------------------- - -if [ "x$FORCE_LIBDIR" != "x" ]; then - echo "Forcing libdir to be $FORCE_LIBDIR" - LIBDIR=$FORCE_LIBDIR -fi - -# --------------------------------------------------------------------------- - -GTK2=-1 -MIN_VERSION="2.6.0" -echo -n "Checking for GTK version >= ${MIN_VERSION}... " -for i in `which pkg-config`; do - $i --errors-to-stdout gtk+-2.0 \ - --atleast-version=$MIN_VERSION > /dev/null - case $? in - 0) - GTK_FLAGS=`pkg-config gtk+-2.0 --cflags` - GTK_LIBS=`pkg-config gtk+-2.0 --libs` - echo "found `pkg-config gtk+-2.0 --modversion`" - GTK2=1 - break ;; - *) - echo "not found." ;; - esac -done - -# -------------------------------------------------------------------------- - -if [ $GTK2 -eq -1 ]; then - echo -e "\nYou need the GTK libraries, including the development stuff." - echo "If you're using Debian, running the command as root:" - echo -e "\n\taptitude install libgtk2.0-dev\n" - echo "Will do the trick." - exit 1 -fi - -# --------------------------------------------------------------------------- - -SOUP=-1 -MIN_VERSION="2.4" -echo -n "Checking for libsoup version >= ${MIN_VERSION}... " -for i in `which pkg-config`; do - $i --errors-to-stdout libsoup-2.4 \ - --atleast-version=$MIN_VERSION > /dev/null - case $? in - 0) - SOUP_FLAGS=`pkg-config libsoup-2.4 --cflags --static` - SOUP_LIBS=`pkg-config libsoup-2.4 --libs --static` - echo "found `pkg-config libsoup-2.4 --modversion`" - SOUP=1 - break ;; - *) - echo "not found." ;; - esac -done - -# -------------------------------------------------------------------------- - -if [ $SOUP -eq -1 ]; then - echo "Disabling libsoup support. (Network Updater won't be available.)" -fi - -# -------------------------------------------------------------------------- - -echo -n "Checking for Linux Wireless Extensions (CONFIG_NET_RADIO)... " -if [ -e /proc/net/wireless ]; then - echo "found." - LINUX_WE=1 -else - echo "not found." - LINUX_WE=-1 -fi - -# -------------------------------------------------------------------------- - -if [ $LINUX_WE -eq -1 ]; then - echo "Disabling Linux Wireless Extensions support." -fi - -# -------------------------------------------------------------------------- - -echo -e "\nWriting config.h..." -cat << EOF > config.h -#ifndef __CONFIG_H__ -#define __CONFIG_H__ - -#define VERSION "$VERSION" -#define $ARCH -#define ARCH "$ARCH" -#define PLATFORM "`uname`" -#define KERNEL "`uname -r`" -#define HOSTNAME "`hostname`" -#define PREFIX "/usr/share/hardinfo" -#define LIBPREFIX "$LIBDIR/hardinfo" - -EOF - -if [ "$SOUP" == "1" ]; then - echo "#define HAS_LIBSOUP" >> config.h -fi - -if [ "$LINUX_WE" == "1" ]; then - echo "#define HAS_LINUX_WE" >> config.h -fi - -if [ "$RELEASE" == "1" ]; then - echo "#define DEBUG(...)" >> config.h -else - echo '#define DEBUG(msg,...) fprintf(stderr, "*** %s:%d (%s) *** " msg "\n", \' >> config.h - echo ' __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__)' >> config.h -fi - -cat << EOF >> config.h -#define ENABLE_BINRELOC 1 -#define RELEASE $RELEASE - -#endif /* __CONFIG_H__ */ -EOF - -echo "Writing Makefile..." - -cat << EOF > Makefile -GTK_LIBS = -lpthread -lgthread-2.0 -lrt ${GTK_LIBS} -GTK_CFLAGS = ${GTK_FLAGS} -SOUP_LIBS = ${SOUP_LIBS} -SOUP_CFLAGS = ${SOUP_FLAGS} -PACKAGE = `basename ${PWD}` -ARCHOPTS = -LIBDIR = $LIBDIR -EOF - -cat Makefile.in >> Makefile - -echo -e "\nDone. Type \"make\" to compile the program.\n" - -if [ "$RELEASE" == 0 ]; then - cat << EOF -******************************************************************** -* This is work in progress! Please report bugs or send patches to: * -* http://bugs.hardinfo.org * -******************************************************************** -EOF -else - cat << EOF -If you get errors, probably you don't have the right libraries, -includes or utilities. However, if you're sure this is a bug in my -code, please use the bug tracker at <http://bugs.hardinfo.org>. -EOF -fi diff --git a/hardinfo2/hardinfo.c b/hardinfo2/hardinfo/hardinfo.c index d36da0aa..784a3c06 100644 --- a/hardinfo2/hardinfo.c +++ b/hardinfo2/hardinfo/hardinfo.c @@ -125,7 +125,7 @@ int main(int argc, char **argv) result = module_call_method_param("benchmark::runBenchmark", params.run_benchmark); if (!result) { - g_error("Unknown benchmark ``%s'' or benchmark.so not loaded", params.run_benchmark); + g_error("Unknown benchmark ``%s'' or libbenchmark.so not loaded", params.run_benchmark); } else { g_print("%s\n", result); g_free(result); diff --git a/hardinfo2/egg-markdown.c b/hardinfo2/help-viewer/egg-markdown.c index 4056d4f9..4056d4f9 100644 --- a/hardinfo2/egg-markdown.c +++ b/hardinfo2/help-viewer/egg-markdown.c diff --git a/hardinfo2/help-viewer.c b/hardinfo2/help-viewer/help-viewer.c index ace6ef37..ace6ef37 100644 --- a/hardinfo2/help-viewer.c +++ b/hardinfo2/help-viewer/help-viewer.c diff --git a/hardinfo2/markdown-text-view.c b/hardinfo2/help-viewer/markdown-text-view.c index 6bfcc131..6bfcc131 100644 --- a/hardinfo2/markdown-text-view.c +++ b/hardinfo2/help-viewer/markdown-text-view.c diff --git a/hardinfo2/includes/benchmark.h b/hardinfo2/includes/benchmark.h new file mode 100644 index 00000000..27bcbf4c --- /dev/null +++ b/hardinfo2/includes/benchmark.h @@ -0,0 +1,21 @@ +#ifndef __BENCHMARK_H__ +#define __BENCHMARK_H__ + +#include "hardinfo.h" + +extern ProgramParameters params; + +enum { + BENCHMARK_BLOWFISH, + BENCHMARK_CRYPTOHASH, + BENCHMARK_FIB, + BENCHMARK_NQUEENS, + BENCHMARK_FFT, + BENCHMARK_RAYTRACE, + BENCHMARK_GUI, + BENCHMARK_N_ENTRIES +} BenchmarkEntries; + +extern gdouble bench_results[BENCHMARK_N_ENTRIES]; + +#endif /* __BENCHMARK_H__ */
\ No newline at end of file diff --git a/hardinfo2/binreloc.h b/hardinfo2/includes/binreloc.h index 3bf48bc6..3bf48bc6 100644 --- a/hardinfo2/binreloc.h +++ b/hardinfo2/includes/binreloc.h diff --git a/hardinfo2/blowfish.h b/hardinfo2/includes/blowfish.h index 3f33e945..3f33e945 100644 --- a/hardinfo2/blowfish.h +++ b/hardinfo2/includes/blowfish.h diff --git a/hardinfo2/callbacks.h b/hardinfo2/includes/callbacks.h index d53e1861..d53e1861 100644 --- a/hardinfo2/callbacks.h +++ b/hardinfo2/includes/callbacks.h diff --git a/hardinfo2/computer.h b/hardinfo2/includes/computer.h index ff84c271..05f7c4be 100644 --- a/hardinfo2/computer.h +++ b/hardinfo2/includes/computer.h @@ -18,6 +18,8 @@ #ifndef __COMPUTER_H__ #define __COMPUTER_H__ +#include "hardinfo.h" + #define DB_PREFIX "/etc/" static struct { @@ -159,4 +161,26 @@ struct _MemoryInfo { continue; \ } +extern gchar *users; +extern gchar *fs_list; +extern GHashTable *_module_hash_table; +extern Computer *computer; +extern GHashTable *moreinfo; +extern gchar *module_list; + +gchar *computer_get_formatted_loadavg(); +gchar *computer_get_formatted_uptime(); +gchar *computer_get_alsacards(Computer * computer); + +OperatingSystem *computer_get_os(void); +AlsaInfo *computer_get_alsainfo(void); +LoadInfo *computer_get_loadinfo(void); +MemoryInfo *computer_get_memory(void); +UptimeInfo *computer_get_uptime(void); +DisplayInfo *computer_get_display(void); + +void scan_modules_do(void); +void scan_filesystems(void); +void scan_users_do(void); + #endif /* __COMPUTER_H__ */ diff --git a/hardinfo2/includes/devices.h b/hardinfo2/includes/devices.h new file mode 100644 index 00000000..adbffd8c --- /dev/null +++ b/hardinfo2/includes/devices.h @@ -0,0 +1,87 @@ +#ifndef __DEVICES_H__ +#define __DEVICES_H__ + +#include "hardinfo.h" +#include "processor-platform.h" + +#define WALK_UNTIL(x) while((*buf != '\0') && (*buf != x)) buf++ + +#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 (g_str_has_prefix(tmp[0], field_name)) { \ + ptr = g_strdup(tmp[1]); \ + g_strfreev(tmp); \ + continue; \ + } +#define get_int(field_name,ptr) \ + if (g_str_has_prefix(tmp[0], field_name)) { \ + ptr = atoi(tmp[1]); \ + g_strfreev(tmp); \ + continue; \ + } +#define get_float(field_name,ptr) \ + if (g_str_has_prefix(tmp[0], field_name)) { \ + ptr = atof(tmp[1]); \ + g_strfreev(tmp); \ + continue; \ + } + + + +/* Processor */ +GSList *processor_scan(void); +void get_processor_strfamily(Processor * processor); +void cpu_flags_init(void); +gchar *processor_get_capabilities_from_flags(gchar * strflags); +gchar *processor_get_detailed_info(Processor * processor); +gchar *processor_get_info(GSList * processors); + +/* Memory */ +void init_memory_labels(void); +void scan_memory_do(void); + +/* Printers */ +void init_cups(void); + +/* Battery */ +void scan_battery_do(void); + +/* PCI */ +void scan_pci_do(void); + +/* Printers */ +void scan_printers_do(void); + +/* Sensors */ +void scan_sensors_do(void); + +extern gchar *battery_list; +extern gchar *dmi_info; +extern gchar *input_icons; +extern gchar *input_list; +extern gchar *lginterval; +extern gchar *meminfo; +extern gchar *pci_list; +extern gchar *printer_icons; +extern gchar *printer_list; +extern gchar *_resources; +extern gchar *sensors; +extern gchar *storage_icons; +extern gchar *storage_list; +extern gchar *usb_list; +extern GHashTable *memlabels; +extern GHashTable *moreinfo; +extern GHashTable *_pci_devices; +extern GHashTable *sensor_compute; +extern GHashTable *sensor_labels; +extern GModule *cups; + + + +#endif /* __DEVICES_H__ */
\ No newline at end of file diff --git a/hardinfo2/egg-markdown.h b/hardinfo2/includes/egg-markdown.h index 4475b9f0..4475b9f0 100644 --- a/hardinfo2/egg-markdown.h +++ b/hardinfo2/includes/egg-markdown.h diff --git a/hardinfo2/expr.h b/hardinfo2/includes/expr.h index 4bda6b72..4bda6b72 100644 --- a/hardinfo2/expr.h +++ b/hardinfo2/includes/expr.h diff --git a/hardinfo2/fftbench.h b/hardinfo2/includes/fftbench.h index 7c0afc3d..7c0afc3d 100644 --- a/hardinfo2/fftbench.h +++ b/hardinfo2/includes/fftbench.h diff --git a/hardinfo2/guibench.h b/hardinfo2/includes/guibench.h index d24403bc..d24403bc 100644 --- a/hardinfo2/guibench.h +++ b/hardinfo2/includes/guibench.h diff --git a/hardinfo2/hardinfo.h b/hardinfo2/includes/hardinfo.h index 48d0cf88..42a92a30 100644 --- a/hardinfo2/hardinfo.h +++ b/hardinfo2/includes/hardinfo.h @@ -20,7 +20,9 @@ #define __HARDINFO_H__ #include <gtk/gtk.h> -#include <shell.h> +#include "config.h" +#include "shell.h" +#include "vendor.h" typedef enum { MODULE_FLAG_NONE = 0, diff --git a/hardinfo2/help-viewer.h b/hardinfo2/includes/help-viewer.h index 688ff325..688ff325 100644 --- a/hardinfo2/help-viewer.h +++ b/hardinfo2/includes/help-viewer.h diff --git a/hardinfo2/iconcache.h b/hardinfo2/includes/iconcache.h index 97f59a82..97f59a82 100644 --- a/hardinfo2/iconcache.h +++ b/hardinfo2/includes/iconcache.h diff --git a/hardinfo2/loadgraph.h b/hardinfo2/includes/loadgraph.h index 3a53f793..3a53f793 100644 --- a/hardinfo2/loadgraph.h +++ b/hardinfo2/includes/loadgraph.h diff --git a/hardinfo2/markdown-text-view.h b/hardinfo2/includes/markdown-text-view.h index 648ea39c..648ea39c 100644 --- a/hardinfo2/markdown-text-view.h +++ b/hardinfo2/includes/markdown-text-view.h diff --git a/hardinfo2/md5.h b/hardinfo2/includes/md5.h index 1522170c..1522170c 100644 --- a/hardinfo2/md5.h +++ b/hardinfo2/includes/md5.h diff --git a/hardinfo2/menu.h b/hardinfo2/includes/menu.h index 361b2323..361b2323 100644 --- a/hardinfo2/menu.h +++ b/hardinfo2/includes/menu.h diff --git a/hardinfo2/includes/network.h b/hardinfo2/includes/network.h new file mode 100644 index 00000000..e8113089 --- /dev/null +++ b/hardinfo2/includes/network.h @@ -0,0 +1,14 @@ +#ifndef __NETWORK_H__ +#define __NETWORK_H__ + +#include "hardinfo.h" + +extern gchar *smb_shares_list; +extern gchar *nfs_shares_list; +extern gchar *network_interfaces; +extern gchar *network_icons; +extern GHashTable *moreinfo; + +void scan_net_interfaces(void); + +#endif /* __NETWORK_H__ */
\ No newline at end of file diff --git a/hardinfo2/nqueens.h b/hardinfo2/includes/nqueens.h index a4be93f0..a4be93f0 100644 --- a/hardinfo2/nqueens.h +++ b/hardinfo2/includes/nqueens.h diff --git a/hardinfo2/remote.h b/hardinfo2/includes/remote.h index 6a988a3b..6a988a3b 100644 --- a/hardinfo2/remote.h +++ b/hardinfo2/includes/remote.h diff --git a/hardinfo2/report.h b/hardinfo2/includes/report.h index 782621cb..782621cb 100644 --- a/hardinfo2/report.h +++ b/hardinfo2/includes/report.h diff --git a/hardinfo2/sha1.h b/hardinfo2/includes/sha1.h index 573ff8ac..573ff8ac 100644 --- a/hardinfo2/sha1.h +++ b/hardinfo2/includes/sha1.h diff --git a/hardinfo2/shell.h b/hardinfo2/includes/shell.h index 2eb9e6d2..2eb9e6d2 100644 --- a/hardinfo2/shell.h +++ b/hardinfo2/includes/shell.h diff --git a/hardinfo2/socket.h b/hardinfo2/includes/socket.h index 7c44837e..7c44837e 100644 --- a/hardinfo2/socket.h +++ b/hardinfo2/includes/socket.h diff --git a/hardinfo2/ssh-conn.h b/hardinfo2/includes/ssh-conn.h index b1b0a9ca..b1b0a9ca 100644 --- a/hardinfo2/ssh-conn.h +++ b/hardinfo2/includes/ssh-conn.h diff --git a/hardinfo2/stock.h b/hardinfo2/includes/stock.h index 706e5c51..706e5c51 100644 --- a/hardinfo2/stock.h +++ b/hardinfo2/includes/stock.h diff --git a/hardinfo2/syncmanager.h b/hardinfo2/includes/syncmanager.h index ae0ed267..ae0ed267 100644 --- a/hardinfo2/syncmanager.h +++ b/hardinfo2/includes/syncmanager.h diff --git a/hardinfo2/includes/test-utils.h b/hardinfo2/includes/test-utils.h new file mode 100644 index 00000000..21cac6b5 --- /dev/null +++ b/hardinfo2/includes/test-utils.h @@ -0,0 +1,24 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "libsoup/soup-types.h" + +void test_init (int argc, char **argv, GOptionEntry *entries); +void test_cleanup (void); + +extern int debug_level, errors; +extern gboolean expect_warning; +void debug_printf (int level, const char *format, ...) G_GNUC_PRINTF (2, 3); + +#ifdef HAVE_APACHE +void apache_init (void); +void apache_cleanup (void); +#endif + +SoupSession *soup_test_session_new (GType type, ...); +void soup_test_session_abort_unref (SoupSession *session); + +SoupServer *soup_test_server_new (gboolean in_own_thread); +SoupServer *soup_test_server_new_ssl (gboolean in_own_thread); + diff --git a/hardinfo2/uidefs.h b/hardinfo2/includes/uidefs.h index a54823ad..a54823ad 100644 --- a/hardinfo2/uidefs.h +++ b/hardinfo2/includes/uidefs.h diff --git a/hardinfo2/vendor.h b/hardinfo2/includes/vendor.h index 778e2ea3..778e2ea3 100644 --- a/hardinfo2/vendor.h +++ b/hardinfo2/includes/vendor.h diff --git a/hardinfo2/includes/x86/processor-platform.h b/hardinfo2/includes/x86/processor-platform.h new file mode 100644 index 00000000..dd9ae9d9 --- /dev/null +++ b/hardinfo2/includes/x86/processor-platform.h @@ -0,0 +1,36 @@ +#ifndef __PROCESSOR_PLATFORM_H__ +#define __PROCESSOR_PLATFORM_H__ + +#include "hardinfo.h" + +typedef struct _Processor Processor; +typedef struct _ProcessorCache ProcessorCache; + +struct _ProcessorCache { + gint level; + gint number_of_sets; + gint physical_line_partition; + gint size; + gchar *type; + gint ways_of_associativity; +}; + +struct _Processor { + gchar *model_name; + gchar *vendor_id; + gchar *flags; + gint cache_size; + gfloat bogomips, cpu_mhz; + + gchar *has_fpu; + gchar *bug_fdiv, *bug_hlt, *bug_f00f, *bug_coma; + + gint model, family, stepping; + gchar *strmodel; + + gint id; + + GSList *cache; +}; + +#endif /* __PROCESSOR_PLATFORM_H__ */ diff --git a/hardinfo2/xmlrpc-client.h b/hardinfo2/includes/xmlrpc-client.h index 32fad08c..32fad08c 100644 --- a/hardinfo2/xmlrpc-client.h +++ b/hardinfo2/includes/xmlrpc-client.h diff --git a/hardinfo2/xmlrpc-server.h b/hardinfo2/includes/xmlrpc-server.h index e608b711..e608b711 100644 --- a/hardinfo2/xmlrpc-server.h +++ b/hardinfo2/includes/xmlrpc-server.h diff --git a/hardinfo2/benchmark.c b/hardinfo2/modules/benchmark.c index 3ca5513e..1f85064a 100644 --- a/hardinfo2/benchmark.c +++ b/hardinfo2/modules/benchmark.c @@ -28,16 +28,7 @@ #include <sys/types.h> #include <signal.h> -enum { - BENCHMARK_BLOWFISH, - BENCHMARK_CRYPTOHASH, - BENCHMARK_FIB, - BENCHMARK_NQUEENS, - BENCHMARK_FFT, - BENCHMARK_RAYTRACE, - BENCHMARK_GUI, - BENCHMARK_N_ENTRIES -} Entries; +#include "benchmark.h" void scan_fft(gboolean reload); void scan_raytr(gboolean reload); @@ -271,7 +262,7 @@ static gchar *benchmark_include_results(gdouble result, SHELL_ORDER_ASCENDING); } -static gdouble bench_results[BENCHMARK_N_ENTRIES]; +gdouble bench_results[BENCHMARK_N_ENTRIES]; #include <arch/common/fib.h> #include <arch/common/cryptohash.h> @@ -359,7 +350,7 @@ static void do_benchmark(void (*benchmark_function)(void), int entry) if (params.gui_running && !sending_benchmark_results) { gchar *argv[] = { params.argv0, "-b", entries[entry].name, - "-m", "benchmark.so", "-a", NULL }; + "-m", "libbenchmark.so", "-a", NULL }; GPid bench_pid; gint bench_stdout; GtkWidget *bench_dialog; @@ -411,6 +402,8 @@ static void do_benchmark(void (*benchmark_function)(void), int entry) GIOChannel *channel; guint watch_id; + DEBUG("spawning benchmark; pid=%d", bench_pid); + channel = g_io_channel_unix_new(bench_stdout); watch_id = g_io_add_watch(channel, G_IO_IN, do_benchmark_handler, benchmark_dialog); @@ -654,7 +647,7 @@ void hi_module_init(void) gchar **hi_module_get_dependencies(void) { - static gchar *deps[] = { "devices.so", NULL }; + static gchar *deps[] = { "libdevices.so", NULL }; return deps; } diff --git a/hardinfo2/blowfish.c b/hardinfo2/modules/benchmark/blowfish.c index 034315ab..034315ab 100644 --- a/hardinfo2/blowfish.c +++ b/hardinfo2/modules/benchmark/blowfish.c diff --git a/hardinfo2/modules/benchmark/cryptohash.c b/hardinfo2/modules/benchmark/cryptohash.c new file mode 100644 index 00000000..99a19140 --- /dev/null +++ b/hardinfo2/modules/benchmark/cryptohash.c @@ -0,0 +1,79 @@ +/* + * 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 "md5.h" +#include "sha1.h" +#include "benchmark.h" + +static void inline md5_step(char *data, glong srclen) +{ + struct MD5Context ctx; + guchar checksum[16]; + + MD5Init(&ctx); + MD5Update(&ctx, (guchar *)data, srclen); + MD5Final(checksum, &ctx); +} + +static void inline sha1_step(char *data, glong srclen) +{ + SHA1_CTX ctx; + guchar checksum[20]; + + SHA1Init(&ctx); + SHA1Update(&ctx, (guchar*)data, srclen); + SHA1Final(checksum, &ctx); +} + +static gpointer cryptohash_for(unsigned int start, unsigned int end, void *data, gint thread_number) +{ + unsigned int i; + + for (i = start; i <= end; i++) { + if (i & 1) { + md5_step(data, 65536); + } else { + sha1_step(data, 65536); + } + } + + return NULL; +} + +static void +benchmark_cryptohash(void) +{ + gdouble elapsed = 0; + gchar *tmpsrc, *bdata_path; + + bdata_path = g_build_filename(params.path_data, "benchmark.data", NULL); + if (!g_file_get_contents(bdata_path, &tmpsrc, NULL, NULL)) { + g_free(bdata_path); + return; + } + + shell_view_set_enabled(FALSE); + shell_status_update("Running CryptoHash benchmark..."); + + elapsed = benchmark_parallel_for(0, 5000, cryptohash_for, tmpsrc); + + g_free(bdata_path); + g_free(tmpsrc); + + bench_results[BENCHMARK_CRYPTOHASH] = 312.0 / elapsed; +} diff --git a/hardinfo2/modules/benchmark/drawing.c b/hardinfo2/modules/benchmark/drawing.c new file mode 100644 index 00000000..6f01fe6b --- /dev/null +++ b/hardinfo2/modules/benchmark/drawing.c @@ -0,0 +1,29 @@ +/* + * 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 "benchmark.h" +#include "guibench.h" + +static void +benchmark_gui(void) +{ + shell_view_set_enabled(FALSE); + shell_status_update("Running drawing benchmark..."); + + bench_results[BENCHMARK_GUI] = guibench(); +} diff --git a/hardinfo2/fbench.c b/hardinfo2/modules/benchmark/fbench.c index df1b8e19..df1b8e19 100644 --- a/hardinfo2/fbench.c +++ b/hardinfo2/modules/benchmark/fbench.c diff --git a/hardinfo2/modules/benchmark/fft.c b/hardinfo2/modules/benchmark/fft.c new file mode 100644 index 00000000..f1a0ced8 --- /dev/null +++ b/hardinfo2/modules/benchmark/fft.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 <fftbench.h> + +static gpointer fft_for(unsigned int start, unsigned int end, void *data, gint thread_number) +{ + unsigned int i; + FFTBench **benches = (FFTBench **)data; + FFTBench *fftbench = (FFTBench *)(benches[thread_number]); + + for (i = start; i <= end; i++) { + fft_bench_run(fftbench); + } + + return NULL; +} + +static void +benchmark_fft(void) +{ + gdouble elapsed = 0; + int n_cores, i; + gchar *temp; + FFTBench **benches; + + shell_view_set_enabled(FALSE); + shell_status_update("Running FFT benchmark..."); + + /* Pre-allocate all benchmarks */ + temp = module_call_method("devices::getProcessorCount"); + n_cores = temp ? atoi(temp) : 1; + g_free(temp); + + benches = g_new0(FFTBench *, n_cores); + for (i = 0; i < n_cores; i++) { + benches[i] = fft_bench_new(); + } + + /* Run the benchmark */ + elapsed = benchmark_parallel_for(0, 4, fft_for, benches); + + /* Free up the memory */ + for (i = 0; i < n_cores; i++) { + fft_bench_free(benches[i]); + } + g_free(benches); + + bench_results[BENCHMARK_FFT] = elapsed; +} diff --git a/hardinfo2/fftbench.c b/hardinfo2/modules/benchmark/fftbench.c index dc25dfd6..dc25dfd6 100644 --- a/hardinfo2/fftbench.c +++ b/hardinfo2/modules/benchmark/fftbench.c diff --git a/hardinfo2/modules/benchmark/fib.c b/hardinfo2/modules/benchmark/fib.c new file mode 100644 index 00000000..3ff54dba --- /dev/null +++ b/hardinfo2/modules/benchmark/fib.c @@ -0,0 +1,50 @@ +/* + * 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 "benchmark.h" + +static gulong +fib(gulong n) +{ + if (n == 0) + return 0; + else if (n <= 2) + return 1; + return fib(n - 1) + fib(n - 2); +} + +static void +benchmark_fib(void) +{ + GTimer *timer = g_timer_new(); + gdouble elapsed; + + shell_view_set_enabled(FALSE); + shell_status_update("Calculating the 42nd Fibonacci number..."); + + g_timer_reset(timer); + g_timer_start(timer); + + fib(42); + + g_timer_stop(timer); + elapsed = g_timer_elapsed(timer, NULL); + g_timer_destroy(timer); + + bench_results[BENCHMARK_FIB] = elapsed; +} diff --git a/hardinfo2/guibench.c b/hardinfo2/modules/benchmark/guibench.c index b9573278..b9573278 100644 --- a/hardinfo2/guibench.c +++ b/hardinfo2/modules/benchmark/guibench.c diff --git a/hardinfo2/md5.c b/hardinfo2/modules/benchmark/md5.c index 70f39c45..70f39c45 100644 --- a/hardinfo2/md5.c +++ b/hardinfo2/modules/benchmark/md5.c diff --git a/hardinfo2/nqueens.c b/hardinfo2/modules/benchmark/nqueens.c index 838731c4..838731c4 100644 --- a/hardinfo2/nqueens.c +++ b/hardinfo2/modules/benchmark/nqueens.c diff --git a/hardinfo2/modules/benchmark/raytrace.c b/hardinfo2/modules/benchmark/raytrace.c new file mode 100644 index 00000000..9fc6361e --- /dev/null +++ b/hardinfo2/modules/benchmark/raytrace.c @@ -0,0 +1,47 @@ +/* + * 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 "benchmark.h" + +void fbench(); /* fbench.c */ + +static gpointer +parallel_raytrace(unsigned int start, unsigned int end, gpointer data, gint thread_number) +{ + unsigned int i; + + for (i = start; i <= end; i++) { + fbench(); + } + + return NULL; +} + +static void +benchmark_raytrace(void) +{ + gdouble elapsed = 0; + + shell_view_set_enabled(FALSE); + shell_status_update("Performing John Walker's FBENCH..."); + + elapsed = benchmark_parallel_for(0, 1000, parallel_raytrace, NULL); + + bench_results[BENCHMARK_RAYTRACE] = elapsed; +} + diff --git a/hardinfo2/sha1.c b/hardinfo2/modules/benchmark/sha1.c index b94ce254..b94ce254 100644 --- a/hardinfo2/sha1.c +++ b/hardinfo2/modules/benchmark/sha1.c diff --git a/hardinfo2/computer.c b/hardinfo2/modules/computer.c index 34696004..cb349408 100644 --- a/hardinfo2/computer.c +++ b/hardinfo2/modules/computer.c @@ -22,7 +22,6 @@ #include <config.h> #include <time.h> #include <string.h> -#include <sys/utsname.h> #include <sys/stat.h> #include <hardinfo.h> @@ -31,6 +30,8 @@ #include <vendor.h> +#include "computer.h" + /* Callbacks */ gchar *callback_summary(); gchar *callback_os(); @@ -77,24 +78,10 @@ static ModuleEntry entries[] = { {NULL}, }; -#include "computer.h" -static GHashTable *moreinfo = NULL; -static gchar *module_list = NULL; -static Computer *computer = NULL; - -#include <arch/this/modules.h> -#include <arch/common/languages.h> -#include <arch/this/alsa.h> -#include <arch/common/display.h> -#include <arch/this/loadavg.h> -#include <arch/this/memory.h> -#include <arch/this/uptime.h> -#include <arch/this/os.h> -#include <arch/this/filesystem.h> -#include <arch/common/users.h> -#include <arch/this/boots.h> -#include <arch/common/environment.h> +GHashTable *moreinfo = NULL; +gchar *module_list = NULL; +Computer *computer = NULL; gchar *hi_more_info(gchar * entry) { @@ -606,7 +593,7 @@ guchar hi_module_get_weight(void) gchar **hi_module_get_dependencies(void) { - static gchar *deps[] = { "devices.so", NULL }; + static gchar *deps[] = { "libdevices.so", NULL }; return deps; } diff --git a/hardinfo2/modules/computer/alsa.c b/hardinfo2/modules/computer/alsa.c new file mode 100644 index 00000000..f1ff3ad8 --- /dev/null +++ b/hardinfo2/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/hardinfo2/modules/computer/boots.c b/hardinfo2/modules/computer/boots.c new file mode 100644 index 00000000..4a1023f6 --- /dev/null +++ b/hardinfo2/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/hardinfo2/modules/computer/display.c b/hardinfo2/modules/computer/display.c new file mode 100644 index 00000000..ce23bbfd --- /dev/null +++ b/hardinfo2/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/hardinfo2/modules/computer/environment.c b/hardinfo2/modules/computer/environment.c new file mode 100644 index 00000000..8ef63b2d --- /dev/null +++ b/hardinfo2/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/hardinfo2/modules/computer/filesystem.c b/hardinfo2/modules/computer/filesystem.c new file mode 100644 index 00000000..fcd8cf31 --- /dev/null +++ b/hardinfo2/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/hardinfo2/modules/computer/languages.c b/hardinfo2/modules/computer/languages.c new file mode 100644 index 00000000..2808da1b --- /dev/null +++ b/hardinfo2/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/hardinfo2/modules/computer/loadavg.c b/hardinfo2/modules/computer/loadavg.c new file mode 100644 index 00000000..523812be --- /dev/null +++ b/hardinfo2/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/hardinfo2/modules/computer/memory.c b/hardinfo2/modules/computer/memory.c new file mode 100644 index 00000000..3d320e8a --- /dev/null +++ b/hardinfo2/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/hardinfo2/modules/computer/modules.c b/hardinfo2/modules/computer/modules.c new file mode 100644 index 00000000..195c444b --- /dev/null +++ b/hardinfo2/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/hardinfo2/modules/computer/os.c b/hardinfo2/modules/computer/os.c new file mode 100644 index 00000000..36b061fc --- /dev/null +++ b/hardinfo2/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/hardinfo2/modules/computer/uptime.c b/hardinfo2/modules/computer/uptime.c new file mode 100644 index 00000000..8eb563fa --- /dev/null +++ b/hardinfo2/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/hardinfo2/modules/computer/users.c b/hardinfo2/modules/computer/users.c new file mode 100644 index 00000000..e303ac6e --- /dev/null +++ b/hardinfo2/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(); +} diff --git a/hardinfo2/devices.c b/hardinfo2/modules/devices.c index 0607ba39..c15a9db1 100644 --- a/hardinfo2/devices.c +++ b/hardinfo2/modules/devices.c @@ -36,6 +36,8 @@ #include <expr.h> #include <socket.h> +#include "devices.h" + gchar *callback_processors(); gchar *callback_memory(); gchar *callback_battery(); @@ -81,61 +83,19 @@ static ModuleEntry entries[] = { {NULL} }; -static GHashTable *moreinfo = NULL; static GSList *processors = NULL; -static gchar *printer_list = NULL, *printer_icons = NULL; -static gchar *pci_list = NULL; -static gchar *input_list = NULL; -static gchar *storage_list = NULL; -static gchar *battery_list = NULL; -static gchar *meminfo = NULL, *lginterval = NULL; - -#define WALK_UNTIL(x) while((*buf != '\0') && (*buf != x)) buf++ - -#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 (g_str_has_prefix(tmp[0], field_name)) { \ - ptr = g_strdup(tmp[1]); \ - g_strfreev(tmp); \ - continue; \ - } -#define get_int(field_name,ptr) \ - if (g_str_has_prefix(tmp[0], field_name)) { \ - ptr = atoi(tmp[1]); \ - g_strfreev(tmp); \ - continue; \ - } -#define get_float(field_name,ptr) \ - if (g_str_has_prefix(tmp[0], field_name)) { \ - ptr = atof(tmp[1]); \ - g_strfreev(tmp); \ - continue; \ - } - -#include <vendor.h> - -typedef struct _Processor Processor; +gchar *printer_list = NULL; +gchar *printer_icons = NULL; +gchar *pci_list = NULL; +gchar *input_list = NULL; +gchar *storage_list = NULL; +gchar *battery_list = NULL; +gchar *meminfo = NULL; +gchar *lginterval = NULL; -#include <arch/this/processor.h> -#include <arch/this/pci.h> -#include <arch/common/printers.h> -#include <arch/this/inputdevices.h> -#include <arch/this/usb.h> -#include <arch/this/storage.h> -#include <arch/this/battery.h> -#include <arch/this/sensors.h> -#include <arch/this/devmemory.h> -#include <arch/this/resources.h> +GHashTable *moreinfo = NULL; -#if defined(ARCH_i386) || defined(ARCH_x86_64) -#include <arch/this/dmi.h> -#endif /* x86 or x86_64 */ +#include <vendor.h> gchar *get_processor_name(void) { @@ -265,42 +225,42 @@ void scan_processors(gboolean reload) { SCAN_START(); if (!processors) - processors = __scan_processors(); + processors = processor_scan(); SCAN_END(); } void scan_memory(gboolean reload) { SCAN_START(); - __scan_memory(); + scan_memory_do(); SCAN_END(); } void scan_battery(gboolean reload) { SCAN_START(); - __scan_battery(); + scan_battery_do(); SCAN_END(); } void scan_pci(gboolean reload) { SCAN_START(); - __scan_pci(); + scan_pci_do(); SCAN_END(); } void scan_sensors(gboolean reload) { SCAN_START(); - __scan_sensors(); + scan_sensors_do(); SCAN_END(); } void scan_printers(gboolean reload) { SCAN_START(); - __scan_printers(); + scan_printers_do(); SCAN_END(); } @@ -449,8 +409,8 @@ void hi_module_init(void) #endif /* defined(ARCH_i386) || defined(ARCH_x86_64) */ moreinfo = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); - __init_memory_labels(); - __init_cups(); + init_memory_labels(); + init_cups(); } void hi_module_deinit(void) @@ -476,7 +436,7 @@ ModuleAbout *hi_module_get_about(void) gchar **hi_module_get_dependencies(void) { - static gchar *deps[] = { "computer.so", NULL }; + static gchar *deps[] = { "libcomputer.so", NULL }; return deps; } diff --git a/hardinfo2/modules/devices/battery.c b/hardinfo2/modules/devices/battery.c new file mode 100644 index 00000000..37416dbb --- /dev/null +++ b/hardinfo2/modules/devices/battery.c @@ -0,0 +1,307 @@ +/* + * 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 <time.h> + +#include "hardinfo.h" +#include "devices.h" + +const struct { + gchar *key, *name; +} ups_fields[] = { + { "UPS Status", NULL }, + { "STATUS", "Status" }, + { "TIMELEFT", "Time Left" }, + { "LINEV", "Line Voltage" }, + { "LOADPCT", "Load Percent" }, + + { "UPS Battery Information", NULL }, + { "BATTV", "Battery Voltage" }, + { "BCHARGE", "Battery Charge" }, + { "BATTDATE", "Battery Date" }, + + { "UPS Information", NULL }, + { "APCMODEL", "Model" }, + { "FIRMWARE", "Firmware Version" }, + { "SERIALNO", "Serial Number" }, + { "UPSMODE", "UPS Mode" }, + { "CABLE", "Cable" }, + { "UPSNAME", "UPS Name" }, + + { "UPS Nominal Values", NULL }, + { "NOMINV", "Voltage" }, + { "NOMBATTV", "Battery Voltage" }, + { "NOMPOWER", "Power" } +}; + + +static void +__scan_battery_apcupsd(void) +{ + GHashTable *ups_data; + FILE *apcaccess; + char buffer[512], *apcaccess_path; + int i; + + apcaccess_path = find_program("apcaccess"); + + if ((apcaccess = popen(apcaccess_path, "r"))) { + /* first line isn't important */ + if (fgets(buffer, 512, apcaccess)) { + /* allocate the key, value hash table */ + ups_data = g_hash_table_new(g_str_hash, g_str_equal); + + /* read up all the apcaccess' output, saving it in the key, value hash table */ + while (fgets(buffer, 512, apcaccess)) { + buffer[9] = '\0'; + + g_hash_table_insert(ups_data, + g_strdup(g_strstrip(buffer)), + g_strdup(g_strstrip(buffer + 10))); + } + + /* builds the ups info string, respecting the field order as found in ups_fields */ + for (i = 0; i < G_N_ELEMENTS(ups_fields); i++) { + if (!ups_fields[i].name) { + /* there's no name: make a group with the key as its name */ + battery_list = h_strdup_cprintf("[%s]\n", battery_list, ups_fields[i].key); + } else { + /* there's a name: adds a line */ + battery_list = h_strdup_cprintf("%s=%s\n", battery_list, + ups_fields[i].name, + g_hash_table_lookup(ups_data, ups_fields[i].key)); + } + } + + g_hash_table_destroy(ups_data); + } + + pclose(apcaccess); + } + + g_free(apcaccess_path); +} + +static void +__scan_battery_acpi(void) +{ + gchar *acpi_path; + + gchar *present = NULL; + gchar *capacity = NULL; + gchar *technology = NULL; + gchar *voltage = NULL; + gchar *model = NULL, *serial = NULL, *type = NULL; + gchar *state = NULL, *rate = NULL; + gchar *remaining = NULL; + gchar *manufacturer = NULL; + + acpi_path = g_strdup("/proc/acpi/battery"); + if (g_file_test(acpi_path, G_FILE_TEST_EXISTS)) { + GDir *acpi; + + if ((acpi = g_dir_open(acpi_path, 0, NULL))) { + const gchar *entry; + + while ((entry = g_dir_read_name(acpi))) { + gchar *path = g_strdup_printf("%s/%s/info", acpi_path, entry); + FILE *f; + gchar buffer[256]; + gdouble charge_rate = 1.0; + + f = fopen(path, "r"); + g_free(path); + + if (!f) + goto cleanup; + + while (fgets(buffer, 256, f)) { + gchar **tmp = g_strsplit(buffer, ":", 2); + + GET_STR("present", present); + GET_STR("design capacity", capacity); + GET_STR("battery technology", technology); + GET_STR("design voltage", voltage); + GET_STR("model number", model); + GET_STR("serial number", serial); + GET_STR("battery type", type); + GET_STR("OEM info", manufacturer); + + g_strfreev(tmp); + } + fclose(f); + + path = g_strdup_printf("%s/%s/state", acpi_path, entry); + f = fopen(path, "r"); + g_free(path); + + if (!f) + goto cleanup; + + while (fgets(buffer, 256, f)) { + gchar **tmp = g_strsplit(buffer, ":", 2); + + GET_STR("charging state", state); + GET_STR("present rate", rate); + GET_STR("remaining capacity", remaining); + + g_strfreev(tmp); + } + + fclose(f); + + const gchar *url = vendor_get_url(manufacturer); + if (url) { + char *tmp = g_strdup_printf("%s (%s)", vendor_get_name(manufacturer), url); + g_free(manufacturer); + manufacturer = tmp; + } + + if (g_str_equal(present, "yes")) { + charge_rate = atof(remaining) / atof(capacity); + + battery_list = h_strdup_cprintf("\n[Battery: %s]\n" + "State=%s (load: %s)\n" + "Capacity=%s / %s (%.2f%%)\n" + "Battery Technology=%s (%s)\n" + "Manufacturer=%s\n" + "Model Number=%s\n" + "Serial Number=%s\n", + battery_list, + entry, + state, rate, + remaining, capacity, charge_rate * 100.0, + technology, type, + manufacturer, + model, + serial); + } + + cleanup: + g_free(present); + g_free(capacity); + g_free(technology); + g_free(type); + g_free(model); + g_free(serial); + g_free(state); + g_free(remaining); + g_free(rate); + g_free(manufacturer); + + present = capacity = technology = type = \ + model = serial = state = remaining = rate = NULL; + } + + g_dir_close(acpi); + } + } + + g_free(acpi_path); +} + +static void +__scan_battery_apm(void) +{ + FILE *procapm; + static char *sremaining = NULL, *stotal = NULL; + static unsigned int last_time = 0; + static int percentage = 0; + const char *ac_status[] = { "Battery", + "AC Power", + "Charging" }; + int ac_bat; + char apm_bios_ver[16], apm_drv_ver[16]; + char trash[10]; + + if ((procapm = fopen("/proc/apm", "r"))) { + int old_percentage = percentage; + + (void)fscanf(procapm, "%s %s %s 0x%x %s %s %d%%", + apm_drv_ver, apm_bios_ver, trash, + &ac_bat, trash, trash, &percentage); + fclose(procapm); + + if (last_time == 0) { + last_time = time(NULL); + sremaining = stotal = NULL; + } + + if (old_percentage - percentage > 0) { + if (sremaining && stotal) { + g_free(sremaining); + g_free(stotal); + } + + int secs_remaining = (time(NULL) - last_time) * percentage / + (old_percentage - percentage); + sremaining = seconds_to_string(secs_remaining); + stotal = seconds_to_string((secs_remaining * 100) / percentage); + + last_time = time(NULL); + } + } else { + return; + } + + if (stotal && sremaining) { + battery_list = h_strdup_cprintf("\n[Battery (APM)]\n" + "Charge=%d%%\n" + "Remaining Charge=%s of %s\n" + "Using=%s\n" + "APM driver version=%s\n" + "APM BIOS version=%s\n", + battery_list, + percentage, + sremaining, stotal, + ac_status[ac_bat], + apm_drv_ver, apm_bios_ver); + } else { + battery_list = h_strdup_cprintf("\n[Battery (APM)]\n" + "Charge=%d%%\n" + "Using=%s\n" + "APM driver version=%s\n" + "APM BIOS version=%s\n", + battery_list, + percentage, + ac_status[ac_bat], + apm_drv_ver, apm_bios_ver); + + } +} + +void +scan_battery_do(void) +{ + if (battery_list) { + g_free(battery_list); + } + battery_list = g_strdup(""); + + __scan_battery_acpi(); + __scan_battery_apm(); + __scan_battery_apcupsd(); + + if (*battery_list == '\0') { + g_free(battery_list); + + battery_list = g_strdup("[No batteries]\n" + "No batteries found on this system=\n"); + } +} diff --git a/hardinfo2/modules/devices/devmemory.c b/hardinfo2/modules/devices/devmemory.c new file mode 100644 index 00000000..8c89d567 --- /dev/null +++ b/hardinfo2/modules/devices/devmemory.c @@ -0,0 +1,107 @@ +/* + * 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 "devices.h" + +GHashTable *memlabels = NULL; + +void scan_memory_do(void) +{ + gchar **keys, *tmp; + 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 */ + 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[1]); + + if ((tmp = g_hash_table_lookup(memlabels, newkeys[0]))) { + g_free(newkeys[0]); + newkeys[0] = g_strdup(tmp); + } + + g_hash_table_replace(moreinfo, g_strdup(newkeys[0]), g_strdup(newkeys[1])); + + tmp = g_strconcat(meminfo, newkeys[0], "=", newkeys[1], "\n", NULL); + g_free(meminfo); + meminfo = tmp; + + 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 struct { + char *proc_label; + char *real_label; + } proc2real[] = { + { "MemTotal", "Total Memory" }, + { "MemFree", "Free Memory" }, + { "SwapCached", "Cached Swap" }, + { "HighTotal", "High Memory" }, + { "HighFree", "Free High Memory" }, + { "LowTotal", "Low Memory" }, + { "LowFree", "Free Low Memory" }, + { "SwapTotal", "Virtual Memory" }, + { "SwapFree", "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/hardinfo2/modules/devices/dmi.c b/hardinfo2/modules/devices/dmi.c new file mode 100644 index 00000000..8cc45462 --- /dev/null +++ b/hardinfo2/modules/devices/dmi.c @@ -0,0 +1,200 @@ +/* + * 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 + */ +/* + * DMI support based on patch by Stewart Adam <s.adam@diffingo.com> + */ +#include <unistd.h> +#include <sys/types.h> + +#include "devices.h" + +typedef struct _DMIInfo DMIInfo; + +struct _DMIInfo { + const gchar *name; + const gchar *file; /* for sysfs */ + const gchar *param; /* for dmidecode */ +}; + +DMIInfo dmi_info_table[] = { + { "$BIOS", NULL, NULL }, + { "Date", "/sys/class/dmi/id/bios_date", "bios-release-date" }, + { "Vendor", "/sys/class/dmi/id/bios_vendor", "bios-vendor" }, + { "Version", "/sys/class/dmi/id/bios_version", "bios-version" }, + { "$Board", NULL, NULL }, + { "Name", "/sys/class/dmi/id/board_name", "baseboard-product-name" }, + { "Vendor", "/sys/class/dmi/id/board_vendor", "baseboard-manufacturer" }, +}; + +gchar *dmi_info = NULL; + +gboolean dmi_get_info_dmidecode() +{ + FILE *dmi_pipe; + gchar buffer[256]; + DMIInfo *info; + gboolean dmi_failed = FALSE; + gint i; + + if (dmi_info) { + g_free(dmi_info); + dmi_info = NULL; + } + + for (i = 0; i < G_N_ELEMENTS(dmi_info_table); i++) { + info = &dmi_info_table[i]; + + if (*(info->name) == '$') { + dmi_info = h_strdup_cprintf("[%s]\n", dmi_info, + (info->name) + 1); + } else { + gchar *temp; + + if (!info->param) + continue; + + temp = g_strconcat("dmidecode -s ", info->param, NULL); + if ((dmi_pipe = popen(temp, "r"))) { + g_free(temp); + + (void)fgets(buffer, 256, dmi_pipe); + if (pclose(dmi_pipe)) { + dmi_failed = TRUE; + break; + } + + const gchar *url = vendor_get_url(buffer); + if (url) { + const gchar *vendor = vendor_get_name(buffer); + if (g_strstr_len(vendor, -1, g_strstrip(buffer)) || + g_strstr_len(g_strstrip(buffer), -1, vendor)) { + dmi_info = h_strdup_cprintf("%s=%s (%s)\n", + dmi_info, + info->name, + g_strstrip(buffer), + url); + } else { + dmi_info = h_strdup_cprintf("%s=%s (%s, %s)\n", + dmi_info, + info->name, + g_strstrip(buffer), + vendor, url); + } + } else { + dmi_info = h_strdup_cprintf("%s=%s\n", + dmi_info, + info->name, + buffer); + } + } else { + g_free(temp); + dmi_failed = TRUE; + break; + } + } + } + + if (dmi_failed) { + g_free(dmi_info); + dmi_info = NULL; + } + + return !dmi_failed; +} + +gboolean dmi_get_info_sys() +{ + FILE *dmi_file; + gchar buffer[256]; + DMIInfo *info; + gboolean dmi_failed = FALSE; + gint i; + + if (dmi_info) { + g_free(dmi_info); + dmi_info = NULL; + } + + for (i = 0; i < G_N_ELEMENTS(dmi_info_table); i++) { + info = &dmi_info_table[i]; + + if (*(info->name) == '$') { + dmi_info = h_strdup_cprintf("[%s]\n", dmi_info, + (info->name) + 1); + } else { + if (!info->file) + continue; + + if ((dmi_file = fopen(info->file, "r"))) { + (void)fgets(buffer, 256, dmi_file); + fclose(dmi_file); + + const gchar *url = vendor_get_url(buffer); + if (url) { + const gchar *vendor = vendor_get_name(buffer); + if (g_strstr_len(vendor, -1, g_strstrip(buffer)) || + g_strstr_len(g_strstrip(buffer), -1, vendor)) { + dmi_info = h_strdup_cprintf("%s=%s (%s)\n", + dmi_info, + info->name, + g_strstrip(buffer), + url); + } else { + dmi_info = h_strdup_cprintf("%s=%s (%s, %s)\n", + dmi_info, + info->name, + g_strstrip(buffer), + vendor, url); + } + } else { + dmi_info = h_strdup_cprintf("%s=%s\n", + dmi_info, + info->name, + g_strstrip(buffer)); + } + } else { + dmi_failed = TRUE; + break; + } + } + } + + if (dmi_failed) { + g_free(dmi_info); + dmi_info = NULL; + } + + return !dmi_failed; +} + +void __scan_dmi() +{ + gboolean dmi_ok; + + dmi_ok = dmi_get_info_sys(); + + if (!dmi_ok) { + dmi_ok = dmi_get_info_dmidecode(); + } + + if (!dmi_ok) { + dmi_info = g_strdup("[No DMI information]\n" + "There was an error retrieving the information.=\n" + "Please try running HardInfo as root.=\n"); + } +} diff --git a/hardinfo2/modules/devices/inputdevices.c b/hardinfo2/modules/devices/inputdevices.c new file mode 100644 index 00000000..c280e218 --- /dev/null +++ b/hardinfo2/modules/devices/inputdevices.c @@ -0,0 +1,144 @@ +/* + * 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 "devices.h" + +gchar *input_icons = NULL; + +static gboolean +remove_input_devices(gpointer key, gpointer value, gpointer data) +{ + return g_str_has_prefix(key, "INP"); +} + +static struct { + char *name; + char *icon; +} input_devices[] = { + { "Keyboard", "keyboard.png" }, + { "Joystick", "joystick.png" }, + { "Mouse", "mouse.png" }, + { "Speaker", "audio.png" }, + { "Unknown", "module.png" }, +}; + +void +__scan_input_devices(void) +{ + FILE *dev; + gchar buffer[128]; + gchar *tmp, *name = NULL, *phys = NULL; + gint bus, vendor, product, version; + int d = 0, n = 0; + + dev = fopen("/proc/bus/input/devices", "r"); + if (!dev) + return; + + if (input_list) { + g_hash_table_foreach_remove(moreinfo, remove_input_devices, NULL); + g_free(input_list); + g_free(input_icons); + } + input_list = g_strdup(""); + input_icons = g_strdup(""); + + while (fgets(buffer, 128, dev)) { + tmp = buffer; + + switch (*tmp) { + case 'N': + name = g_strdup(tmp + strlen("N: Name=")); + remove_quotes(name); + break; + case 'P': + phys = g_strdup(tmp + strlen("P: Phys=")); + break; + case 'I': + sscanf(tmp, "I: Bus=%x Vendor=%x Product=%x Version=%x", + &bus, &vendor, &product, &version); + break; + case 'H': + if (strstr(tmp, "kbd")) + d = 0; //INPUT_KEYBOARD; + else if (strstr(tmp, "js")) + d = 1; //INPUT_JOYSTICK; + else if (strstr(tmp, "mouse")) + d = 2; //INPUT_MOUSE; + else + d = 4; //INPUT_UNKNOWN; + break; + case '\n': + if (strstr(name, "PC Speaker")) { + d = 3; // INPUT_PCSPKR + } + + tmp = g_strdup_printf("INP%d", ++n); + input_list = h_strdup_cprintf("$%s$%s=\n", + input_list, + tmp, name); + input_icons = h_strdup_cprintf("Icon$%s$%s=%s\n", + input_icons, + tmp, name, + input_devices[d].icon); + gchar *strhash = g_strdup_printf("[Device Information]\n" + "Name=%s\n" + "Type=%s\n" + "Bus=0x%x\n", + name, + input_devices[d].name, + bus); + + const gchar *url = vendor_get_url(name); + if (url) { + strhash = h_strdup_cprintf("Vendor=%s (%s)\n", + strhash, + vendor_get_name(name), + url); + } else { + strhash = h_strdup_cprintf("Vendor=%x\n", + strhash, + vendor); + } + + strhash = h_strdup_cprintf("Product=0x%x\n" + "Version=0x%x\n", + strhash, product, version); + + if (phys[1] != 0) { + strhash = h_strdup_cprintf("Connected to=%s\n", + strhash, phys); + } + + if (strstr(phys,"ir")) { + strhash = h_strdup_cprintf("InfraRed port=yes\n", + strhash); + } + + g_hash_table_insert(moreinfo, tmp, strhash); + + g_free(phys); + g_free(name); + } + } + + fclose(dev); +} diff --git a/hardinfo2/modules/devices/pci.c b/hardinfo2/modules/devices/pci.c new file mode 100644 index 00000000..a8439019 --- /dev/null +++ b/hardinfo2/modules/devices/pci.c @@ -0,0 +1,245 @@ +/* + * 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 + */ + +/* + * TODO: This thing must be rewritten. We really should have a struct with all the + * PCI stuff we'll present to the user, and hash them by the PCI ID + * (domain:bus:device.function). + * This way we'll have ways to better organize the output, instead of relying + * on the order the information appears on lspci's output. + * Also, the "Resources" thing might be better implemented (and we won't need + * copies of information scattered everywhere like we do today). + */ + +#include <string.h> + +#include "hardinfo.h" +#include "devices.h" + +GHashTable *_pci_devices = NULL; + +void +scan_pci_do(void) +{ + FILE *lspci; + gchar buffer[256], *buf, *strhash = NULL, *strdevice = NULL; + gchar *category = NULL, *name = NULL, *icon, *lspci_path, *command_line = NULL; + gint n = 0, x = 0; + + if ((lspci_path = find_program("lspci")) == NULL) { + goto pci_error; + } else { + command_line = g_strdup_printf("%s -v", lspci_path); + } + + if (!_pci_devices) { + _pci_devices = g_hash_table_new(g_str_hash, g_str_equal); + } + + buf = g_build_filename(g_get_home_dir(), ".hardinfo", "pci.ids", NULL); + if (!g_file_test(buf, G_FILE_TEST_EXISTS)) { + DEBUG("using system-provided PCI IDs"); + g_free(buf); + if (!(lspci = popen(command_line, "r"))) { + goto pci_error; + } + } else { + gchar *tmp; + + tmp = g_strdup_printf("%s -i '%s'", command_line, buf); + g_free(buf); + buf = tmp; + + DEBUG("using updated PCI IDs (from %s)", buf); + if (!(lspci = popen(tmp, "r"))) { + g_free(buf); + goto pci_error; + } else { + g_free(buf); + } + } + + while (fgets(buffer, 256, lspci)) { + buf = g_strstrip(buffer); + + if (!strncmp(buf, "Flags", 5)) { + gint irq = 0, freq = 0, latency = 0, i; + gchar **list; + gboolean bus_master; + + buf += 7; + + bus_master = FALSE; + + list = g_strsplit(buf, ", ", 10); + for (i = 0; i <= 10; i++) { + if (!list[i]) + break; + + if (!strncmp(list[i], "IRQ", 3)) + sscanf(list[i], "IRQ %d", &irq); + else if (strstr(list[i], "Mhz")) + sscanf(list[i], "%dMhz", &freq); + else if (!strncmp(list[i], "bus master", 10)) + bus_master = TRUE; + else if (!strncmp(list[i], "latency", 7)) + sscanf(list[i], "latency %d", &latency); + } + g_strfreev(list); + + if (irq) + strdevice = h_strdup_cprintf("IRQ=%d\n", strdevice, irq); + if (freq) + strdevice = h_strdup_cprintf("Frequency=%dMHz\n", strdevice, freq); + if (latency) + strdevice = h_strdup_cprintf("Latency=%d\n", strdevice, latency); + + strdevice = h_strdup_cprintf("Bus Master=%s\n", strdevice, bus_master ? "Yes" : "No"); + } else if (!strncmp(buf, "Kernel modules", 14)) { + WALK_UNTIL(' '); + WALK_UNTIL(':'); + buf++; + + strdevice = h_strdup_cprintf("Kernel modules=%s\n", strdevice, buf); + } else if (!strncmp(buf, "Subsystem", 9)) { + WALK_UNTIL(' '); + buf++; + const gchar *oem_vendor_url = vendor_get_url(buf); + if (oem_vendor_url) + strdevice = h_strdup_cprintf("OEM Vendor=%s (%s)\n", + strdevice, + vendor_get_name(buf), + oem_vendor_url); + } else if (!strncmp(buf, "Capabilities", 12) + && !strstr(buf, "only to root") && + !strstr(buf, "access denied")) { + WALK_UNTIL(' '); + WALK_UNTIL(']'); + buf++; + strdevice = h_strdup_cprintf("Capability#%d=%s\n", strdevice, ++x, buf); + } else if (!strncmp(buf, "Memory at", 9) && strstr(buf, "[size=")) { + gint mem; + gchar unit; + gboolean prefetch; + gboolean _32bit; + + prefetch = strstr(buf, "non-prefetchable") ? FALSE : TRUE; + _32bit = strstr(buf, "32-bit") ? TRUE : FALSE; + + WALK_UNTIL('['); + sscanf(buf, "[size=%d%c", &mem, &unit); + + strdevice = h_strdup_cprintf("Memory#%d=%d%cB (%s%s)\n", + strdevice, ++x, + mem, + (unit == ']') ? ' ' : unit, + _32bit ? "32-bit, " : "", + prefetch ? "prefetchable" : + "non-prefetchable"); + + } else if (!strncmp(buf, "I/O ports at", 12)) { + guint io_addr, io_size; + + sscanf(buf, "I/O ports at %x [size=%d]", &io_addr, &io_size); + + strdevice = + h_strdup_cprintf("I/O ports at#%d=0x%x - 0x%x\n", + strdevice, ++x, io_addr, + io_addr + io_size - 1); + } else if ((buf[0] >= '0' && buf[0] <= '9') && (buf[4] == ':' || buf[2] == ':')) { + gint bus, device, function, domain; + gpointer start, end; + + if (strdevice != NULL && strhash != NULL) { + g_hash_table_insert(moreinfo, strhash, strdevice); + g_free(category); + g_free(name); + } + + if (buf[4] == ':') { + sscanf(buf, "%x:%x:%x.%d", &domain, &bus, &device, &function); + } else { + /* lspci without domain field */ + sscanf(buf, "%x:%x.%x", &bus, &device, &function); + domain = 0; + } + + WALK_UNTIL(' '); + + start = buf; + + WALK_UNTIL(':'); + end = buf + 1; + *buf = 0; + + buf = start + 1; + category = g_strdup(buf); + + buf = end; + + if (strstr(category, "RAM memory")) icon = "mem"; + else if (strstr(category, "Multimedia")) icon = "media"; + else if (strstr(category, "USB")) icon = "usb"; + else icon = "pci"; + + name = g_strdup(buf); + g_hash_table_insert(_pci_devices, + g_strdup_printf("0000:%02x:%02x.%x", bus, device, function), + name); + + strhash = g_strdup_printf("PCI%d", n); + strdevice = g_strdup_printf("[Device Information]\n" + "Name=%s\n" + "Class=%s\n" + "Domain=%d\n" + "Bus, device, function=%d, %d, %d\n", + name, category, domain, bus, + device, function); + + const gchar *url = vendor_get_url(name); + if (url) { + strdevice = h_strdup_cprintf("Vendor=%s (%s)\n", + strdevice, + vendor_get_name(name), + url); + } + + g_hash_table_insert(_pci_devices, + g_strdup_printf("0000:%02x:%02x.%x", bus, device, function), + g_strdup(name)); + + pci_list = h_strdup_cprintf("$PCI%d$%s=%s\n", pci_list, n, category, name); + + n++; + } + } + + if (pclose(lspci)) { +pci_error: + /* error (no pci, perhaps?) */ + pci_list = g_strconcat(pci_list, "No PCI devices found=\n", NULL); + } else if (strhash) { + /* insert the last device */ + g_hash_table_insert(moreinfo, strhash, strdevice); + g_free(category); + g_free(name); + } + + g_free(lspci_path); + g_free(command_line); +} diff --git a/hardinfo2/modules/devices/printers.c b/hardinfo2/modules/devices/printers.c new file mode 100644 index 00000000..80851a00 --- /dev/null +++ b/hardinfo2/modules/devices/printers.c @@ -0,0 +1,271 @@ +/* + * 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 <stdlib.h> +#include <time.h> + +#include "devices.h" + +typedef struct _CUPSDest CUPSDest; +typedef struct _CUPSOption CUPSOption; + +struct _CUPSOption { + char *name, *value; +}; + +struct _CUPSDest { + char *name, *instance; + int is_default; + int num_options; + CUPSOption *options; +}; + +static int (*cups_dests_get) (CUPSDest **dests) = NULL; +static int (*cups_dests_free) (int num_dests, CUPSDest *dests) = NULL; +static gboolean cups_init = FALSE; + +GModule *cups; + +static gboolean +remove_printer_devices(gpointer key, gpointer value, gpointer data) +{ + return g_str_has_prefix(key, "PRN"); +} + +void +init_cups(void) +{ + const char *libcups[] = { "libcups", "libcups.so", "libcups.so.1", "libcups.so.2", NULL }; + + if (!(cups_dests_get && cups_dests_free)) { + int i; + + for (i = 0; libcups[i] != NULL; i++) { + cups = g_module_open(libcups[i], G_MODULE_BIND_LAZY); + if (cups) + break; + } + + if (!cups) { + cups_init = FALSE; + return; + } + + if (!g_module_symbol(cups, "cupsGetDests", (gpointer) & cups_dests_get) + || !g_module_symbol(cups, "cupsFreeDests", (gpointer) & cups_dests_free)) { + g_module_close(cups); + cups_init = FALSE; + } + } + + cups_init = TRUE; +} + +gchar *__cups_callback_ptype(gchar *strvalue) +{ + if (strvalue) { + unsigned value = atoi(strvalue); + gchar *output = g_strdup("\n"); + + if (value & 0x0004) + output = h_strdup_cprintf("\342\232\254 Can do black and white printing=\n", output); + if (value & 0x0008) + output = h_strdup_cprintf("\342\232\254 Can do color printing=\n", output); + if (value & 0x0010) + output = h_strdup_cprintf("\342\232\254 Can do duplexing=\n", output); + if (value & 0x0020) + output = h_strdup_cprintf("\342\232\254 Can do staple output=\n", output); + if (value & 0x0040) + output = h_strdup_cprintf("\342\232\254 Can do copies=\n", output); + if (value & 0x0080) + output = h_strdup_cprintf("\342\232\254 Can collate copies=\n", output); + if (value & 0x80000) + output = h_strdup_cprintf("\342\232\254 Printer is rejecting jobs=\n", output); + if (value & 0x1000000) + output = h_strdup_cprintf("\342\232\254 Printer was automatically discovered and added=\n", output); + + return output; + } else { + return g_strdup("Unknown"); + } +} + +gchar *__cups_callback_state(gchar *value) +{ + if (!value) { + return g_strdup("Unknown"); + } + + if (g_str_equal(value, "3")) { + return g_strdup("Idle"); + } else if (g_str_equal(value, "4")) { + return g_strdup("Printing a Job"); + } else if (g_str_equal(value, "5")) { + return g_strdup("Stopped"); + } else { + return g_strdup("Unknown"); + } +} + +gchar *__cups_callback_state_change_time(gchar *value) +{ + struct tm tm; + char buf[255]; + + if (value) { + strptime(value, "%s", &tm); + strftime(buf, sizeof(buf), "%c", &tm); + + return g_strdup(buf); + } else { + return g_strdup("Unknown"); + } +} + +gchar *__cups_callback_boolean(gchar *value) +{ + if (value) { + return g_strdup(g_str_equal(value, "1") ? "Yes" : "No"); + } else { + return g_strdup("Unknown"); + } +} + +const struct { + char *key, *name; + gchar *(*callback)(gchar *value); +} cups_fields[] = { + { "Printer Information", NULL, NULL }, + { "printer-info", "Destination Name", NULL }, + { "printer-make-and-model", "Make and Model", NULL }, + + { "Capabilities", NULL, NULL }, + { "printer-type", "#", __cups_callback_ptype }, + + { "Printer State", NULL, NULL }, + { "printer-state", "State", __cups_callback_state }, + { "printer-state-change-time", "Change Time", __cups_callback_state_change_time }, + { "printer-state-reasons", "State Reasons" }, + + { "Sharing Information", NULL, NULL }, + { "printer-is-shared", "Shared?", __cups_callback_boolean }, + { "printer-location", "Physical Location" }, + { "auth-info-required", "Authentication Required", __cups_callback_boolean }, + + { "Jobs", NULL, NULL }, + { "job-hold-until", "Hold Until", NULL }, + { "job-priority", "Priority", NULL }, + { "printer-is-accepting-jobs", "Accepting Jobs", __cups_callback_boolean }, + + { "Media", NULL, NULL }, + { "media", "Media", NULL }, + { "finishings", "Finishings", NULL }, + { "copies", "Copies", NULL }, +}; + +void +scan_printers_do(void) +{ + int num_dests, i, j; + CUPSDest *dests; + gchar *prn_id, *prn_moreinfo; + + g_free(printer_list); + g_free(printer_icons); + + if (!cups_init) { + __init_cups(); + + printer_icons = g_strdup(""); + printer_list = g_strdup("[Printers]\n" + "No suitable CUPS library found="); + return; + } + + /* remove old devices from global device table */ + g_hash_table_foreach_remove(moreinfo, remove_printer_devices, NULL); + + num_dests = cups_dests_get(&dests); + if (num_dests > 0) { + printer_list = g_strdup_printf("[Printers (CUPS)]\n"); + printer_icons = g_strdup(""); + for (i = 0; i < num_dests; i++) { + GHashTable *options; + + options = g_hash_table_new(g_str_hash, g_str_equal); + + for (j = 0; j < dests[i].num_options; j++) { + g_hash_table_insert(options, + g_strdup(dests[i].options[j].name), + g_strdup(dests[i].options[j].value)); + } + + prn_id = g_strdup_printf("PRN%d", i); + + printer_list = h_strdup_cprintf("\n$%s$%s=%s\n", + printer_list, + prn_id, + dests[i].name, + dests[i].is_default ? "<i>Default</i>" : ""); + printer_icons = h_strdup_cprintf("\nIcon$%s$%s=printer.png", + printer_icons, + prn_id, + dests[i].name); + + prn_moreinfo = g_strdup(""); + for (j = 0; j < G_N_ELEMENTS(cups_fields); j++) { + if (!cups_fields[j].name) { + prn_moreinfo = h_strdup_cprintf("[%s]\n", + prn_moreinfo, + cups_fields[j].key); + } else { + gchar *temp; + + temp = g_hash_table_lookup(options, cups_fields[j].key); + + if (cups_fields[j].callback) { + temp = cups_fields[j].callback(temp); + } else { + if (temp) { + /* FIXME Do proper escaping */ + temp = g_strdup(strreplacechr(temp, "&=", ' ')); + } else { + temp = g_strdup("Unknown"); + } + } + + prn_moreinfo = h_strdup_cprintf("%s=%s\n", + prn_moreinfo, + cups_fields[j].name, + temp); + + g_free(temp); + } + } + + g_hash_table_insert(moreinfo, prn_id, prn_moreinfo); + g_hash_table_destroy(options); + } + + cups_dests_free(num_dests, dests); + } else { + printer_list = g_strdup("[Printers]\n" + "No printers found=\n"); + } +} diff --git a/hardinfo2/modules/devices/resources.c b/hardinfo2/modules/devices/resources.c new file mode 100644 index 00000000..270000dd --- /dev/null +++ b/hardinfo2/modules/devices/resources.c @@ -0,0 +1,105 @@ +/* + * 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 "devices.h" + +gchar *_resources = NULL; + +#if GLIB_CHECK_VERSION(2,14,0) +static GRegex *_regex_pci = NULL, + *_regex_module = NULL; + +static gchar *_resource_obtain_name(gchar *name) +{ + gchar *temp; + + if (!_regex_pci && !_regex_module) { + _regex_pci = g_regex_new("^[0-9a-fA-F]{4}:[0-9a-fA-F]{2}:" + "[0-9a-fA-F]{2}\\.[0-9a-fA-F]{1}$", + 0, 0, NULL); + _regex_module = g_regex_new("^[0-9a-zA-Z\\_\\-]+$", 0, 0, NULL); + } + + name = g_strstrip(name); + + if (g_regex_match(_regex_pci, name, 0, NULL)) { + temp = module_call_method_param("devices::getPCIDeviceDescription", name); + if (temp) { + return g_strdup_printf("<b><small>PCI</small></b> %s", (gchar *)idle_free(temp)); + } + } else if (g_regex_match(_regex_module, name, 0, NULL)) { + temp = module_call_method_param("computer::getKernelModuleDescription", name); + if (temp) { + return g_strdup_printf("<b><small>Module</small></b> %s", (gchar *)idle_free(temp)); + } + } + + return g_strdup(name); +} +#else +static gchar *_resource_obtain_name(gchar *name) +{ + return g_strdup(name); +} +#endif + +void scan_device_resources(gboolean reload) +{ + SCAN_START(); + FILE *io; + gchar buffer[256]; + gint i; + + struct { + gchar *file; + gchar *description; + } resources[] = { + { "/proc/ioports", "[I/O Ports]\n" }, + { "/proc/iomem", "[Memory]\n" }, + { "/proc/dma", "[DMA]\n" } + }; + + g_free(_resources); + _resources = g_strdup(""); + + for (i = 0; i < G_N_ELEMENTS(resources); i++) { + if ((io = fopen(resources[i].file, "r"))) { + _resources = h_strconcat(_resources, resources[i].description, NULL); + + while (fgets(buffer, 256, io)) { + gchar **temp = g_strsplit(buffer, ":", 2); + gchar *name = _resource_obtain_name(temp[1]); + + _resources = h_strdup_cprintf("<tt>%s</tt>=%s\n", _resources, + temp[0], name); + + g_strfreev(temp); + g_free(name); + } + + fclose(io); + } + } + + SCAN_END(); +} + +gchar *callback_device_resources(void) +{ + return g_strdup(_resources); +} diff --git a/hardinfo2/modules/devices/sensors.c b/hardinfo2/modules/devices/sensors.c new file mode 100644 index 00000000..9f02566d --- /dev/null +++ b/hardinfo2/modules/devices/sensors.c @@ -0,0 +1,383 @@ +/* + * 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 "devices.h" +#include "expr.h" +#include "hardinfo.h" +#include "socket.h" + +gchar *sensors = NULL; +GHashTable *sensor_compute = NULL; +GHashTable *sensor_labels = NULL; + +static void read_sensor_labels(gchar * driver) +{ + FILE *conf; + gchar buf[256], *line, *p; + gboolean lock = FALSE; + gint i; + + sensor_labels = g_hash_table_new_full(g_str_hash, g_str_equal, + g_free, g_free); + sensor_compute = g_hash_table_new(g_str_hash, g_str_equal); + + /* Try to open lm-sensors config file sensors3.conf */ + conf = fopen("/etc/sensors3.conf", "r"); + + /* If it fails, try to open sensors.conf */ + if (!conf) conf = fopen("/etc/sensors.conf", "r"); + + if (!conf) { + /* Cannot open config file. */ + return; + } + + while (fgets(buf, 256, conf)) { + line = buf; + + remove_linefeed(line); + strend(line, '#'); + + if (*line == '\0') { + continue; + } else if (lock && strstr(line, "label")) { /* label lines */ + gchar **names = g_strsplit(strstr(line, "label") + 5, " ", 0); + gchar *name = NULL, *value = NULL; + + for (i = 0; names[i]; i++) { + if (names[i][0] == '\0') + continue; + + if (!name) + name = g_strdup(names[i]); + else if (!value) + value = g_strdup(names[i]); + else + value = g_strconcat(value, " ", names[i], NULL); + } + + remove_quotes(value); + g_hash_table_insert(sensor_labels, name, value); + + g_strfreev(names); + } else if (lock && strstr(line, "ignore")) { /* ignore lines */ + p = strstr(line, "ignore") + 6; + if (!strchr(p, ' ')) + continue; + + while (*p == ' ') + p++; + g_hash_table_insert(sensor_labels, g_strdup(p), "ignore"); + } else if (lock && strstr(line, "compute")) { /* compute lines */ + gchar **formulas = + g_strsplit(strstr(line, "compute") + 7, " ", 0); + gchar *name = NULL, *formula = NULL; + + for (i = 0; formulas[i]; i++) { + if (formulas[i][0] == '\0') + continue; + if (formulas[i][0] == ',') + break; + + if (!name) + name = g_strdup(formulas[i]); + else if (!formula) + formula = g_strdup(formulas[i]); + else + formula = g_strconcat(formula, formulas[i], NULL); + } + + g_strfreev(formulas); + g_hash_table_insert(sensor_compute, name, + math_string_to_postfix(formula)); + } else if (g_str_has_prefix(line, "chip")) { /* chip lines (delimiter) */ + if (lock == FALSE) { + gchar **chips = g_strsplit(line, " ", 0); + + for (i = 1; chips[i]; i++) { + strend(chips[i], '*'); + + if (g_str_has_prefix(chips[i] + 1, driver)) { + lock = TRUE; + break; + } + } + + g_strfreev(chips); + } else { + break; + } + } + } + + fclose(conf); +} + +static gchar *get_sensor_label(gchar * sensor) +{ + gchar *ret; + + ret = g_hash_table_lookup(sensor_labels, sensor); + if (!ret) + ret = g_strdup(sensor); + else + ret = g_strdup(ret); + + return ret; +} + +static float adjust_sensor(gchar * name, float value) +{ + GSList *postfix; + + postfix = g_hash_table_lookup(sensor_compute, name); + if (!postfix) + return value; + + return math_postfix_eval(postfix, value); +} + + +static void read_sensors_hwmon(void) +{ + int hwmon, count; + gchar *path_hwmon, *path_sensor, *tmp, *driver, *name, *mon; + hwmon = 0; + + path_hwmon = g_strdup_printf("/sys/class/hwmon/hwmon%d/device/", hwmon); + while (g_file_test(path_hwmon, G_FILE_TEST_EXISTS)) { + tmp = g_strdup_printf("%sdriver", path_hwmon); + driver = g_file_read_link(tmp, NULL); + g_free(tmp); + + tmp = g_path_get_basename(driver); + g_free(driver); + driver = tmp; + + if (!sensor_labels) { + read_sensor_labels(driver); + } + + sensors = g_strconcat(sensors, "[Cooling Fans]\n", NULL); + for (count = 1;; count++) { + path_sensor = + g_strdup_printf("%sfan%d_input", path_hwmon, count); + if (!g_file_get_contents(path_sensor, &tmp, NULL, NULL)) { + g_free(path_sensor); + break; + } + + mon = g_strdup_printf("fan%d", count); + name = get_sensor_label(mon); + if (!g_str_equal(name, "ignore")) { + sensors = h_strdup_cprintf("%s=%.0fRPM\n", + sensors, name, + adjust_sensor(mon, atof(tmp))); + } + + g_free(name); + g_free(mon); + g_free(tmp); + g_free(path_sensor); + } + + sensors = g_strconcat(sensors, "[Temperatures]\n", NULL); + for (count = 1;; count++) { + path_sensor = + g_strdup_printf("%stemp%d_input", path_hwmon, count); + if (!g_file_get_contents(path_sensor, &tmp, NULL, NULL)) { + g_free(path_sensor); + break; + } + + mon = g_strdup_printf("temp%d", count); + name = get_sensor_label(mon); + if (!g_str_equal(name, "ignore")) { + sensors = h_strdup_cprintf("%s=%.2f\302\260C\n", + sensors, name, + adjust_sensor(mon, + atof(tmp) / + 1000.0)); + } + + g_free(tmp); + g_free(name); + g_free(path_sensor); + g_free(mon); + } + + sensors = g_strconcat(sensors, "[Voltage Values]\n", NULL); + for (count = 0;; count++) { + path_sensor = + g_strdup_printf("%sin%d_input", path_hwmon, count); + if (!g_file_get_contents(path_sensor, &tmp, NULL, NULL)) { + g_free(path_sensor); + break; + } + + + mon = g_strdup_printf("in%d", count); + name = get_sensor_label(mon); + if (!g_str_equal(name, "ignore")) { + sensors = h_strdup_cprintf("%s=%.3fV\n", + sensors, name, + adjust_sensor(mon, + atof(tmp) / + 1000.0)); + } + + g_free(tmp); + g_free(mon); + g_free(name); + g_free(path_sensor); + } + + g_free(path_hwmon); + g_free(driver); + path_hwmon = + g_strdup_printf("/sys/class/hwmon/hwmon%d/device/", ++hwmon); + } + + g_free(path_hwmon); + +} + +static void read_sensors_acpi(void) +{ + const gchar *path_tz = "/proc/acpi/thermal_zone"; + + if (g_file_test(path_tz, G_FILE_TEST_EXISTS)) { + GDir *tz; + + if ((tz = g_dir_open(path_tz, 0, NULL))) { + const gchar *entry; + gchar *temp = g_strdup(""); + + while ((entry = g_dir_read_name(tz))) { + gchar *path = + g_strdup_printf("%s/%s/temperature", path_tz, entry); + gchar *contents; + + if (g_file_get_contents(path, &contents, NULL, NULL)) { + int temperature; + + sscanf(contents, "temperature: %d C", &temperature); + + temp = h_strdup_cprintf("\n%s=%d\302\260C\n", + temp, entry, temperature); + + g_free(contents); + } + } + + if (*temp != '\0') + sensors = + h_strdup_cprintf("\n[ACPI Thermal Zone]\n%s", + sensors, temp); + + g_dir_close(tz); + } + } + +} + +static void read_sensors_omnibook(void) +{ + const gchar *path_ob = "/proc/omnibook/temperature"; + gchar *contents; + + if (g_file_get_contents(path_ob, &contents, NULL, NULL)) { + int temperature; + + sscanf(contents, "CPU temperature: %d C", &temperature); + + sensors = h_strdup_cprintf("\n[Omnibook]\n" + "CPU temperature=%d\302\260C\n", + sensors, temperature); + + g_free(contents); + } +} + +static void read_sensors_hddtemp(void) +{ + Socket *s; + static gchar *old = NULL; + gchar buffer[1024]; + gint len = 0; + + if ((s = sock_connect("127.0.0.1", 7634))) { + while (!len) + len = sock_read(s, buffer, sizeof(buffer)); + sock_close(s); + + if (len > 2 && buffer[0] == '|' && buffer[1] == '/') { + gchar **disks; + int i; + + if (old) + g_free(old); + + old = g_strdup("[Hard Disk Temperature]\n"); + + disks = g_strsplit(buffer, "\n", 0); + for (i = 0; disks[i]; i++) { + gchar **fields = g_strsplit(disks[i] + 1, "|", 5); + + /* + * 0 -> /dev/hda + * 1 -> FUJITSU MHV2080AH + * 2 -> 41 + * 3 -> C + */ + old = h_strdup_cprintf("\n%s (%s)=%s\302\260%s\n", + old, + fields[1], fields[0], + fields[2], fields[3]); + + g_strfreev(fields); + } + + g_strfreev(disks); + } + } else { + g_free(old); + old = NULL; + } + + if (old) { + sensors = g_strconcat(sensors, "\n", old, NULL); + } +} + +void scan_sensors_do(void) +{ + if (sensors) + g_free(sensors); + + sensors = g_strdup(""); + + read_sensors_hwmon(); + read_sensors_acpi(); + read_sensors_omnibook(); + read_sensors_hddtemp(); + + /* FIXME: Add support for ibm acpi and more sensors */ +} diff --git a/hardinfo2/modules/devices/storage.c b/hardinfo2/modules/devices/storage.c new file mode 100644 index 00000000..23ab1de2 --- /dev/null +++ b/hardinfo2/modules/devices/storage.c @@ -0,0 +1,377 @@ +/* + * 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 "devices.h" + +gchar *storage_icons = NULL; + +static gboolean +remove_scsi_devices(gpointer key, gpointer value, gpointer data) +{ + return g_str_has_prefix(key, "SCSI"); +} + +/* SCSI support by Pascal F.Martin <pascalmartin@earthlink.net> */ +void +__scan_scsi_devices(void) +{ + FILE *proc_scsi; + gchar buffer[256], *buf; + gint n = 0; + gint scsi_controller; + gint scsi_channel; + gint scsi_id; + gint scsi_lun; + gchar *vendor = NULL, *revision = NULL, *model = NULL; + gchar *scsi_storage_list; + + /* remove old devices from global device table */ + g_hash_table_foreach_remove(moreinfo, remove_scsi_devices, NULL); + + if (!g_file_test("/proc/scsi/scsi", G_FILE_TEST_EXISTS)) + return; + + scsi_storage_list = g_strdup("\n[SCSI Disks]\n"); + + if ((proc_scsi = fopen("/proc/scsi/scsi", "r"))) { + while (fgets(buffer, 256, proc_scsi)) { + buf = g_strstrip(buffer); + if (!strncmp(buf, "Host: scsi", 10)) { + sscanf(buf, + "Host: scsi%d Channel: %d Id: %d Lun: %d", + &scsi_controller, &scsi_channel, &scsi_id, &scsi_lun); + + n++; + } else if (!strncmp(buf, "Vendor: ", 8)) { + buf[17] = '\0'; + buf[41] = '\0'; + buf[53] = '\0'; + + vendor = g_strdup(g_strstrip(buf + 8)); + model = g_strdup_printf("%s %s", vendor, g_strstrip(buf + 24)); + revision = g_strdup(g_strstrip(buf + 46)); + } else if (!strncmp(buf, "Type: ", 8)) { + char *p; + gchar *type = NULL, *icon = NULL; + + if (!(p = strstr(buf, "ANSI SCSI revision"))) { + p = strstr(buf, "ANSI SCSI revision"); + } + + if (p != NULL) { + while (*(--p) == ' '); + *(++p) = 0; + + static struct { + char *type; + char *label; + char *icon; + } type2icon[] = { + { "Direct-Access", "Disk", "hdd"}, + { "Sequential-Access", "Tape", "tape"}, + { "Printer", "Printer", "lpr"}, + { "WORM", "CD-ROM", "cdrom"}, + { "CD-ROM", "CD-ROM", "cdrom"}, + { "Scanner", "Scanner", "scanner"}, + { "Flash Disk", "USB Flash Disk", "usbfldisk" }, + { NULL, "Generic", "scsi"} + }; + int i; + + if (strstr(model, "Flash Disk")) { + type = "Flash Disk"; + icon = "usbfldisk"; + } else { + for (i = 0; type2icon[i].type != NULL; i++) + if (g_str_equal(buf + 8, type2icon[i].type)) + break; + + type = type2icon[i].label; + icon = type2icon[i].icon; + } + } + + gchar *devid = g_strdup_printf("SCSI%d", n); + scsi_storage_list = h_strdup_cprintf("$%s$%s=\n", scsi_storage_list, devid, model); + storage_icons = h_strdup_cprintf("Icon$%s$%s=%s.png\n", storage_icons, devid, model, icon); + + gchar *strhash = g_strdup_printf("[Device Information]\n" + "Model=%s\n", model); + + const gchar *url = vendor_get_url(model); + if (url) { + strhash = h_strdup_cprintf("Vendor=%s (%s)\n", + strhash, + vendor_get_name(model), + url); + } else { + strhash = h_strdup_cprintf("Vendor=%s\n", + strhash, + vendor_get_name(model)); + } + + strhash = h_strdup_cprintf("Type=%s\n" + "Revision=%s\n" + "[SCSI Controller]\n" + "Controller=scsi%d\n" + "Channel=%d\n" + "ID=%d\n" "LUN=%d\n", + strhash, + type, + revision, + scsi_controller, + scsi_channel, + scsi_id, + scsi_lun); + g_hash_table_insert(moreinfo, devid, strhash); + + g_free(model); + g_free(revision); + g_free(vendor); + } + } + fclose(proc_scsi); + } + + if (n) { + storage_list = h_strconcat(storage_list, scsi_storage_list, NULL); + g_free(scsi_storage_list); + } +} + +static gboolean +remove_ide_devices(gpointer key, gpointer value, gpointer data) +{ + return g_str_has_prefix(key, "IDE"); +} + +void +__scan_ide_devices(void) +{ + FILE *proc_ide; + gchar *device, iface, *model, *media, *pgeometry = NULL, *lgeometry = + NULL; + gint n = 0, i = 0, cache, nn = 0; + gchar *capab = NULL, *speed = NULL, *driver = NULL, *ide_storage_list; + + /* remove old devices from global device table */ + g_hash_table_foreach_remove(moreinfo, remove_ide_devices, NULL); + + ide_storage_list = g_strdup("\n[IDE Disks]\n"); + + iface = 'a'; + for (i = 0; i <= 16; i++) { + device = g_strdup_printf("/proc/ide/hd%c/model", iface); + if (g_file_test(device, G_FILE_TEST_EXISTS)) { + gchar buf[128]; + + cache = 0; + + proc_ide = fopen(device, "r"); + (void)fgets(buf, 128, proc_ide); + fclose(proc_ide); + + buf[strlen(buf) - 1] = 0; + + model = g_strdup(buf); + + g_free(device); + + device = g_strdup_printf("/proc/ide/hd%c/media", iface); + proc_ide = fopen(device, "r"); + (void)fgets(buf, 128, proc_ide); + fclose(proc_ide); + buf[strlen(buf) - 1] = 0; + + media = g_strdup(buf); + if (g_str_equal(media, "cdrom")) { + /* obtain cd-rom drive information from cdrecord */ + GTimer *timer; + gchar *tmp = g_strdup_printf("cdrecord dev=/dev/hd%c -prcap 2>/dev/stdout", iface); + FILE *prcap; + + if ((prcap = popen(tmp, "r"))) { + /* we need a timeout so cdrecord does not try to get information on cd drives + with inserted media, which is not possible currently. half second should be + enough. */ + timer = g_timer_new(); + g_timer_start(timer); + + while (fgets(buf, 128, prcap) && g_timer_elapsed(timer, NULL) < 0.5) { + if (g_str_has_prefix(buf, " Does")) { + if (g_str_has_suffix(buf, "media\n") && !strstr(buf, "speed")) { + gchar *media_type = g_strstrip(strstr(buf, "Does ")); + gchar **ttmp = g_strsplit(media_type, " ", 0); + + capab = h_strdup_cprintf("\nCan %s#%d=%s\n", + capab, + ttmp[1], ++nn, ttmp[2]); + + g_strfreev(ttmp); + } else if (strstr(buf, "Buffer-Underrun-Free")) { + capab = h_strdup_cprintf("\nSupports BurnProof=%s\n", + capab, + strstr(buf, "Does not") ? "No" : "Yes"); + } else if (strstr(buf, "multi-session")) { + capab = h_strdup_cprintf("\nCan read multi-session CDs=%s\n", + capab, + strstr(buf, "Does not") ? "No" : "Yes"); + } else if (strstr(buf, "audio CDs")) { + capab = h_strdup_cprintf("\nCan play audio CDs=%s\n", + capab, + strstr(buf, "Does not") ? "No" : "Yes"); + } else if (strstr(buf, "PREVENT/ALLOW")) { + capab = h_strdup_cprintf("\nCan lock media=%s\n", + capab, + strstr(buf, "Does not") ? "No" : "Yes"); + } + } else if ((strstr(buf, "read") || strstr(buf, "write")) && strstr(buf, "kB/s")) { + speed = g_strconcat(speed ? speed : "", + strreplacechr(g_strstrip(buf), ":", '='), + "\n", NULL); + } else if (strstr(buf, "Device seems to be")) { + driver = g_strdup_printf("Driver=%s\n", strchr(buf, ':') + 1); + } + } + + pclose(prcap); + g_timer_destroy(timer); + } + + g_free(tmp); + } + g_free(device); + + device = g_strdup_printf("/proc/ide/hd%c/cache", iface); + if (g_file_test(device, G_FILE_TEST_EXISTS)) { + proc_ide = fopen(device, "r"); + (void)fscanf(proc_ide, "%d", &cache); + fclose(proc_ide); + } + g_free(device); + + device = g_strdup_printf("/proc/ide/hd%c/geometry", iface); + if (g_file_test(device, G_FILE_TEST_EXISTS)) { + gchar *tmp; + + proc_ide = fopen(device, "r"); + + (void)fgets(buf, 64, proc_ide); + for (tmp = buf; *tmp; tmp++) { + if (*tmp >= '0' && *tmp <= '9') + break; + } + + pgeometry = g_strdup(g_strstrip(tmp)); + + (void)fgets(buf, 64, proc_ide); + for (tmp = buf; *tmp; tmp++) { + if (*tmp >= '0' && *tmp <= '9') + break; + } + lgeometry = g_strdup(g_strstrip(tmp)); + + fclose(proc_ide); + } + g_free(device); + + n++; + + gchar *devid = g_strdup_printf("IDE%d", n); + + ide_storage_list = h_strdup_cprintf("$%s$%s=\n", ide_storage_list, + devid, model); + storage_icons = h_strdup_cprintf("Icon$%s$%s=%s.png\n", storage_icons, devid, + model, g_str_equal(media, "cdrom") ? \ + "cdrom" : "hdd"); + + gchar *strhash = g_strdup_printf("[Device Information]\n" + "Model=%s\n", + model); + + const gchar *url = vendor_get_url(model); + + if (url) { + strhash = h_strdup_cprintf("Vendor=%s (%s)\n", + strhash, + vendor_get_name(model), + url); + } else { + strhash = h_strdup_cprintf("Vendor=%s\n", + strhash, + vendor_get_name(model)); + } + + strhash = h_strdup_cprintf("Device Name=hd%c\n" + "Media=%s\n" + "Cache=%dkb\n", + strhash, + iface, + media, + cache); + if (driver) { + strhash = h_strdup_cprintf("%s\n", strhash, driver); + + g_free(driver); + driver = NULL; + } + + if (pgeometry && lgeometry) { + strhash = h_strdup_cprintf("[Geometry]\n" + "Physical=%s\n" + "Logical=%s\n", + strhash, pgeometry, lgeometry); + + g_free(pgeometry); + pgeometry = NULL; + g_free(lgeometry); + lgeometry = NULL; + } + + if (capab) { + strhash = h_strdup_cprintf("[Capabilities]\n%s", strhash, capab); + + g_free(capab); + capab = NULL; + } + + if (speed) { + strhash = h_strdup_cprintf("[Speeds]\n%s", strhash, speed); + + g_free(speed); + speed = NULL; + } + + g_hash_table_insert(moreinfo, devid, strhash); + + g_free(model); + model = g_strdup(""); + } else + g_free(device); + + iface++; + } + + if (n) { + storage_list = h_strconcat(storage_list, ide_storage_list, NULL); + g_free(ide_storage_list); + } +} diff --git a/hardinfo2/modules/devices/usb.c b/hardinfo2/modules/devices/usb.c new file mode 100644 index 00000000..39914dd0 --- /dev/null +++ b/hardinfo2/modules/devices/usb.c @@ -0,0 +1,349 @@ +/* + * 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 + */ +/* + * FIXME: + * - listing with sysfs does not generate device hierarchy + */ + +#include <string.h> + +#include "hardinfo.h" +#include "devices.h" + +gchar *usb_list = NULL; + +static gboolean +remove_usb_devices(gpointer key, gpointer value, gpointer data) +{ + return g_str_has_prefix(key, "USB"); +} + +void __scan_usb_sysfs_add_device(gchar * endpoint, int n) +{ + gchar *manufacturer, *product, *mxpwr, *tmp, *strhash; + gint bus, classid, vendor, prodid; + gfloat version, speed; + + classid = h_sysfs_read_int(endpoint, "bDeviceClass"); + vendor = h_sysfs_read_int(endpoint, "idVendor"); + prodid = h_sysfs_read_int(endpoint, "idProduct"); + bus = h_sysfs_read_int(endpoint, "busnum"); + speed = h_sysfs_read_float(endpoint, "speed"); + version = h_sysfs_read_float(endpoint, "version"); + + if (!(mxpwr = h_sysfs_read_string(endpoint, "bMaxPower"))) { + mxpwr = g_strdup("0 mA"); + } + + if (!(manufacturer = h_sysfs_read_string(endpoint, "manufacturer"))) { + manufacturer = g_strdup("Unknown"); + } + + if (!(product = h_sysfs_read_string(endpoint, "product"))) { + if (classid == 9) { + product = g_strdup_printf("USB %.2f Hub", version); + } else { + product = g_strdup_printf("Unknown USB %.2f Device (class %d)", version, classid); + } + } + + const gchar *url = vendor_get_url(manufacturer); + if (url) { + tmp = g_strdup_printf("%s (%s)", vendor_get_name(manufacturer), url); + + g_free(manufacturer); + manufacturer = tmp; + } + + tmp = g_strdup_printf("USB%d", n); + usb_list = h_strdup_cprintf("$%s$%s=\n", usb_list, tmp, product); + + strhash = g_strdup_printf("[Device Information]\n" + "Product=%s\n" + "Manufacturer=%s\n" + "Speed=%.2fMbit/s\n" + "Max Current=%s\n" + "[Misc]\n" + "USB Version=%.2f\n" + "Class=0x%x\n" + "Vendor=0x%x\n" + "Product ID=0x%x\n" + "Bus=%d\n", + product, + manufacturer, + speed, + mxpwr, + version, classid, vendor, prodid, bus); + + g_hash_table_insert(moreinfo, tmp, strhash); + + g_free(manufacturer); + g_free(product); + g_free(mxpwr); +} + +gboolean __scan_usb_sysfs(void) +{ + GDir *sysfs; + gchar *filename; + const gchar *sysfs_path = "/sys/class/usb_endpoint"; + gint usb_device_number = 0; + + if (!(sysfs = g_dir_open(sysfs_path, 0, NULL))) { + return FALSE; + } + + if (usb_list) { + g_hash_table_foreach_remove(moreinfo, remove_usb_devices, NULL); + g_free(usb_list); + } + usb_list = g_strdup("[USB Devices]\n"); + + while ((filename = (gchar *) g_dir_read_name(sysfs))) { + gchar *endpoint = + g_build_filename(sysfs_path, filename, "device", NULL); + gchar *temp; + + temp = g_build_filename(endpoint, "idVendor", NULL); + if (g_file_test(temp, G_FILE_TEST_EXISTS)) { + __scan_usb_sysfs_add_device(endpoint, ++usb_device_number); + } + + g_free(temp); + g_free(endpoint); + } + + g_dir_close(sysfs); + + return usb_device_number > 0; +} + +gboolean __scan_usb_procfs(void) +{ + FILE *dev; + gchar buffer[128]; + gchar *tmp, *manuf = NULL, *product = NULL, *mxpwr; + gint bus, level, port, classid, trash; + gint vendor, prodid; + gfloat ver, rev, speed; + int n = 0; + + dev = fopen("/proc/bus/usb/devices", "r"); + if (!dev) + return 0; + + if (usb_list) { + g_hash_table_foreach_remove(moreinfo, remove_usb_devices, NULL); + g_free(usb_list); + } + usb_list = g_strdup("[USB Devices]\n"); + + while (fgets(buffer, 128, dev)) { + tmp = buffer; + + switch (*tmp) { + case 'T': + sscanf(tmp, + "T: Bus=%d Lev=%d Prnt=%d Port=%d Cnt=%d Dev#=%d Spd=%f", + &bus, &level, &trash, &port, &trash, &trash, &speed); + break; + case 'D': + sscanf(tmp, "D: Ver=%f Cls=%x", &ver, &classid); + break; + case 'P': + sscanf(tmp, "P: Vendor=%x ProdID=%x Rev=%f", + &vendor, &prodid, &rev); + break; + case 'S': + if (strstr(tmp, "Manufacturer=")) { + manuf = g_strdup(strchr(tmp, '=') + 1); + remove_linefeed(manuf); + } else if (strstr(tmp, "Product=")) { + product = g_strdup(strchr(tmp, '=') + 1); + remove_linefeed(product); + } + break; + case 'C': + mxpwr = strstr(buffer, "MxPwr=") + 6; + + tmp = g_strdup_printf("USB%d", ++n); + + if (*product == '\0') { + g_free(product); + if (classid == 9) { + product = g_strdup_printf("USB %.2f Hub", ver); + } else { + product = + g_strdup_printf + ("Unknown USB %.2f Device (class %d)", ver, + classid); + } + } + + + if (classid == 9) { /* hub */ + usb_list = h_strdup_cprintf("[%s#%d]\n", + usb_list, product, n); + } else { /* everything else */ + usb_list = h_strdup_cprintf("$%s$%s=\n", + usb_list, tmp, product); + + const gchar *url = vendor_get_url(manuf); + if (url) { + gchar *tmp = + g_strdup_printf("%s (%s)", vendor_get_name(manuf), + url); + g_free(manuf); + manuf = tmp; + } + + gchar *strhash = g_strdup_printf("[Device Information]\n" + "Product=%s\n", + product); + if (manuf && strlen(manuf)) + strhash = h_strdup_cprintf("Manufacturer=%s\n", + strhash, manuf); + + strhash = h_strdup_cprintf("[Port #%d]\n" + "Speed=%.2fMbit/s\n" + "Max Current=%s\n" + "[Misc]\n" + "USB Version=%.2f\n" + "Revision=%.2f\n" + "Class=0x%x\n" + "Vendor=0x%x\n" + "Product ID=0x%x\n" + "Bus=%d\n" "Level=%d\n", + strhash, + port, speed, mxpwr, + ver, rev, classid, + vendor, prodid, bus, level); + + g_hash_table_insert(moreinfo, tmp, strhash); + } + + g_free(manuf); + g_free(product); + manuf = g_strdup(""); + product = g_strdup(""); + } + } + + fclose(dev); + + return n > 0; +} + +void __scan_usb_lsusb_add_device(char *buffer, FILE *lsusb, int usb_device_number) +{ + gint bus, device, vendor_id, product_id; + gchar *product, *vendor, *max_power, *tmp, *strhash; + + sscanf(buffer, "Bus %d Device %d: ID %x:%x", + &bus, &device, &vendor_id, &product_id); + + while (fgets(buffer, 512, lsusb)) { + if (g_str_has_prefix(buffer, " idVendor")) { + vendor = g_strstrip(g_strdup(buffer + 28)); + } else if (g_str_has_prefix(buffer, " idProduct")) { + product = g_strstrip(g_strdup(buffer + 28)); + } else if (g_str_has_prefix(buffer, " MaxPower")) { + max_power = g_strstrip(g_strdup(buffer + 26)); + } else if (g_str_has_prefix(buffer, "\n")) { + /* device separator */ + break; + } + } + + tmp = g_strdup_printf("USB%d", usb_device_number); + usb_list = h_strdup_cprintf("$%s$%s=\n", usb_list, tmp, product); + + strhash = g_strdup_printf("[Device Information]\n" + "Product=%s\n" + "Manufacturer=%s\n" + "Max Current=%s\n" + "[Misc]\n" + "USB Version=%.2f\n" + "Class=0x%x\n" + "Vendor=0x%x\n" + "Product ID=0x%x\n" + "Bus=%d\n", + product, + vendor, + max_power, + 0.0f /* FIXME */, + 0 /* FIXME */, + vendor_id, product_id, bus); + + g_hash_table_insert(moreinfo, tmp, strhash); + + g_free(vendor); + g_free(product); + g_free(max_power); +} + +gboolean __scan_usb_lsusb(void) +{ + static gchar *lsusb_path = NULL; + int usb_device_number = 0; + FILE *lsusb; + char buffer[512], *temp; + + if (!lsusb_path) { + if (!(lsusb_path = find_program("lsusb"))) { + DEBUG("lsusb not found"); + + return FALSE; + } + } + + temp = g_strdup_printf("%s -v", lsusb_path); + if (!(lsusb = popen(temp, "r"))) { + DEBUG("cannot run %s", lsusb_path); + + g_free(temp); + return FALSE; + } + + g_free(temp); + + if (usb_list) { + g_hash_table_foreach_remove(moreinfo, remove_usb_devices, NULL); + g_free(usb_list); + } + usb_list = g_strdup("[USB Devices]\n"); + + while (fgets(buffer, sizeof(buffer), lsusb)) { + if (g_str_has_prefix(buffer, "Bus ")) { + __scan_usb_lsusb_add_device(buffer, lsusb, ++usb_device_number); + } + } + + pclose(lsusb); + + return usb_device_number > 0; +} + +void __scan_usb(void) +{ + if (!__scan_usb_procfs()) { + if (!__scan_usb_sysfs()) { + __scan_usb_lsusb(); + } + } +} diff --git a/hardinfo2/modules/devices/x86/processor.c b/hardinfo2/modules/devices/x86/processor.c new file mode 100644 index 00000000..aee409f1 --- /dev/null +++ b/hardinfo2/modules/devices/x86/processor.c @@ -0,0 +1,562 @@ +/* + * 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 "devices.h" + +/* + * This function is partly based on x86cpucaps + * by Osamu Kayasono <jacobi@jcom.home.ne.jp> + */ +void get_processor_strfamily(Processor * processor) +{ + gint family = processor->family; + gint model = processor->model; + + if (g_str_equal(processor->vendor_id, "GenuineIntel")) { + if (family == 4) { + processor->strmodel = g_strdup("i486 series"); + } else if (family == 5) { + if (model < 4) { + processor->strmodel = g_strdup("Pentium Classic"); + } else { + processor->strmodel = g_strdup("Pentium MMX"); + } + } else if (family == 6) { + if (model <= 1) { + processor->strmodel = g_strdup("Pentium Pro"); + } else if (model < 7) { + processor->strmodel = g_strdup("Pentium II/Pentium II Xeon/Celeron"); + } else if (model == 9) { + processor->strmodel = g_strdup("Pentium M"); + } else { + processor->strmodel = g_strdup("Pentium III/Pentium III Xeon/Celeron/Core Duo/Core Duo 2"); + } + } else if (family > 6) { + processor->strmodel = g_strdup("Pentium 4"); + } else { + processor->strmodel = g_strdup("i386 class"); + } + } else if (g_str_equal(processor->vendor_id, "AuthenticAMD")) { + if (family == 4) { + if (model <= 9) { + processor->strmodel = g_strdup("AMD i80486 series"); + } else { + processor->strmodel = g_strdup("AMD 5x86"); + } + } else if (family == 5) { + if (model <= 3) { + processor->strmodel = g_strdup("AMD K5"); + } else if (model <= 7) { + processor->strmodel = g_strdup("AMD K6"); + } else if (model == 8) { + processor->strmodel = g_strdup("AMD K6-2"); + } else if (model == 9) { + processor->strmodel = g_strdup("AMD K6-III"); + } else { + processor->strmodel = g_strdup("AMD K6-2+/III+"); + } + } else if (family == 6) { + if (model == 1) { + processor->strmodel = g_strdup("AMD Athlon (K7)"); + } else if (model == 2) { + processor->strmodel = g_strdup("AMD Athlon (K75)"); + } else if (model == 3) { + processor->strmodel = g_strdup("AMD Duron (Spitfire)"); + } else if (model == 4) { + processor->strmodel = g_strdup("AMD Athlon (Thunderbird)"); + } else if (model == 6) { + processor->strmodel = g_strdup("AMD Athlon XP/MP/4 (Palomino)"); + } else if (model == 7) { + processor->strmodel = g_strdup("AMD Duron (Morgan)"); + } else if (model == 8) { + processor->strmodel = g_strdup("AMD Athlon XP/MP (Thoroughbred)"); + } else if (model == 10) { + processor->strmodel = g_strdup("AMD Athlon XP/MP (Barton)"); + } else { + processor->strmodel = g_strdup("AMD Athlon (unknown)"); + } + } else if (family > 6) { + processor->strmodel = g_strdup("AMD Opteron/Athlon64/FX"); + } else { + processor->strmodel = g_strdup("AMD i386 class"); + } + } else if (g_str_equal(processor->vendor_id, "CyrixInstead")) { + if (family == 4) { + processor->strmodel = g_strdup("Cyrix 5x86"); + } else if (family == 5) { + processor->strmodel = g_strdup("Cyrix M1 (6x86)"); + } else if (family == 6) { + if (model == 0) { + processor->strmodel = g_strdup("Cyrix M2 (6x86MX)"); + } else if (model <= 5) { + processor->strmodel = g_strdup("VIA Cyrix III (M2 core)"); + } else if (model == 6) { + processor->strmodel = g_strdup("VIA Cyrix III (WinChip C5A)"); + } else if (model == 7) { + processor->strmodel = g_strdup("VIA Cyrix III (WinChip C5B/C)"); + } else { + processor->strmodel = g_strdup("VIA Cyrix III (WinChip C5C-T)"); + } + } else { + processor->strmodel = g_strdup("Cyrix i386 class"); + } + } else if (g_str_equal(processor->vendor_id, "CentaurHauls")) { + if (family == 5) { + if (model <= 4) { + processor->strmodel = g_strdup("Centaur WinChip C6"); + } else if (model <= 8) { + processor->strmodel = g_strdup("Centaur WinChip 2"); + } else { + processor->strmodel = g_strdup("Centaur WinChip 2A"); + } + } else { + processor->strmodel = g_strdup("Centaur i386 class"); + } + } else if (g_str_equal(processor->vendor_id, "GenuineTMx86")) { + processor->strmodel = g_strdup("Transmeta Crusoe TM3x00/5x00"); + } else { + processor->strmodel = g_strdup("Unknown"); + } +} + +static gchar *__cache_get_info_as_string(Processor *processor) +{ + gchar *result = g_strdup(""); + GSList *cache_list; + ProcessorCache *cache; + + if (!processor->cache) { + return g_strdup("Cache information not available=\n"); + } + + for (cache_list = processor->cache; cache_list; cache_list = cache_list->next) { + cache = (ProcessorCache *)cache_list->data; + + result = h_strdup_cprintf("Level %d (%s)=%d-way set-associative, %d sets, %dKB size\n", + result, + cache->level, + cache->type, + cache->ways_of_associativity, + cache->number_of_sets, + cache->size); + } + + return result; +} + +static void __cache_obtain_info(Processor *processor, gint processor_number) +{ + ProcessorCache *cache; + gchar *endpoint, *entry, *index; + gint i; + + endpoint = g_strdup_printf("/sys/devices/system/cpu/cpu%d/cache", processor_number); + + for (i = 0; ; i++) { + cache = g_new0(ProcessorCache, 1); + + index = g_strdup_printf("index%d/", i); + + entry = g_strconcat(index, "type", NULL); + cache->type = h_sysfs_read_string(endpoint, entry); + g_free(entry); + + if (!cache->type) { + g_free(cache); + g_free(index); + goto fail; + } + + entry = g_strconcat(index, "level", NULL); + cache->level = h_sysfs_read_int(endpoint, entry); + g_free(entry); + + entry = g_strconcat(index, "number_of_sets", NULL); + cache->number_of_sets = h_sysfs_read_int(endpoint, entry); + g_free(entry); + + entry = g_strconcat(index, "physical_line_partition", NULL); + cache->physical_line_partition = h_sysfs_read_int(endpoint, entry); + g_free(entry); + + entry = g_strconcat(index, "size", NULL); + cache->size = h_sysfs_read_int(endpoint, entry); + g_free(entry); + + + entry = g_strconcat(index, "ways_of_associativity", NULL); + cache->ways_of_associativity = h_sysfs_read_int(endpoint, entry); + g_free(entry); + + g_free(index); + + processor->cache = g_slist_append(processor->cache, cache); + } + +fail: + g_free(endpoint); +} + +GSList *processor_scan(void) +{ + GSList *procs = NULL; + Processor *processor = NULL; + FILE *cpuinfo; + gchar buffer[512]; + gint processor_number = 0; + + cpuinfo = fopen("/proc/cpuinfo", "r"); + if (!cpuinfo) + return NULL; + + while (fgets(buffer, 512, cpuinfo)) { + gchar **tmp = g_strsplit(buffer, ":", 2); + + if (g_str_has_prefix(tmp[0], "processor")) { + if (processor) { + get_processor_strfamily(processor); + procs = g_slist_append(procs, processor); + } + + processor = g_new0(Processor, 1); + + __cache_obtain_info(processor, processor_number++); + } + + if (tmp[0] && tmp[1]) { + tmp[0] = g_strstrip(tmp[0]); + tmp[1] = g_strstrip(tmp[1]); + + get_str("model name", processor->model_name); + get_str("vendor_id", processor->vendor_id); + get_str("flags", processor->flags); + get_int("cache size", processor->cache_size); + get_float("cpu MHz", processor->cpu_mhz); + get_float("bogomips", processor->bogomips); + + get_str("fpu", processor->has_fpu); + + get_str("fdiv_bug", processor->bug_fdiv); + get_str("hlt_bug", processor->bug_hlt); + get_str("f00f_bug", processor->bug_f00f); + get_str("coma_bug", processor->bug_coma); + + get_int("model", processor->model); + get_int("cpu family", processor->family); + get_int("stepping", processor->stepping); + + get_int("processor", processor->id); + } + g_strfreev(tmp); + } + + if (processor) { + get_processor_strfamily(processor); + procs = g_slist_append(procs, processor); + } + + fclose(cpuinfo); + + return procs; +} + +/* + * Sources: + * - Linux' cpufeature.h + * - http://gentoo-wiki.com/Cpuinfo + * - Intel IA-32 Architecture Software Development Manual + */ +static struct { + char *name, *meaning; +} flag_meaning[] = { + { "3dnow", "3DNow! Technology" }, + { "3dnowext", "Extended 3DNow! Technology" }, + { "fpu", "Floating Point Unit" }, + { "vme", "Virtual 86 Mode Extension" }, + { "de", "Debug Extensions - I/O breakpoints" }, + { "pse", "Page Size Extensions (4MB pages)" }, + { "tsc", "Time Stamp Counter and RDTSC instruction" }, + { "msr", "Model Specific Registers" }, + { "pae", "Physical Address Extensions" }, + { "mce", "Machine Check Architeture" }, + { "cx8", "CMPXCHG8 instruction" }, + { "apic", "Advanced Programmable Interrupt Controller" }, + { "sep", "Fast System Call (SYSENTER/SYSEXIT)" }, + { "mtrr", "Memory Type Range Registers" }, + { "pge", "Page Global Enable" }, + { "mca", "Machine Check Architecture" }, + { "cmov", "Conditional Move instruction" }, + { "pat", "Page Attribute Table" }, + { "pse36", "36bit Page Size Extensions" }, + { "psn", "96 bit Processor Serial Number" }, + { "mmx", "MMX technology" }, + { "mmxext", "Extended MMX Technology" }, + { "cflush", "Cache Flush" }, + { "dtes", "Debug Trace Store" }, + { "fxsr", "FXSAVE and FXRSTOR instructions" }, + { "kni", "Streaming SIMD instructions" }, + { "xmm", "Streaming SIMD instructions" }, + { "ht", "HyperThreading" }, + { "mp", "Multiprocessing Capable" }, + { "sse", "SSE instructions" }, + { "sse2", "SSE2 (WNI) instructions" }, + { "acc", "Automatic Clock Control" }, + { "ia64", "IA64 Instructions" }, + { "syscall", "SYSCALL and SYSEXIT instructions" }, + { "nx", "No-execute Page Protection" }, + { "xd", "Execute Disable" }, + { "clflush", "Cache Line Flush instruction" }, + { "acpi", "Thermal Monitor and Software Controlled Clock" }, + { "dts", "Debug Store" }, + { "ss", "Self Snoop" }, + { "tm", "Thermal Monitor" }, + { "pbe", "Pending Break Enable" }, + { "pb", "Pending Break Enable" }, + { "pn", "Processor serial number" }, + { "ds", "Debug Store" }, + { "xmm2", "Streaming SIMD Extensions-2" }, + { "xmm3", "Streaming SIMD Extensions-3" }, + { "selfsnoop", "CPU self snoop" }, + { "rdtscp", "RDTSCP" }, + { "recovery", "CPU in recovery mode" }, + { "longrun", "Longrun power control" }, + { "lrti", "LongRun table interface" }, + { "cxmmx", "Cyrix MMX extensions" }, + { "k6_mtrr", "AMD K6 nonstandard MTRRs" }, + { "cyrix_arr", "Cyrix ARRs (= MTRRs)" }, + { "centaur_mcr","Centaur MCRs (= MTRRs)" }, + { "constant_tsc","TSC ticks at a constant rate" }, + { "up", "smp kernel running on up" }, + { "fxsave_leak","FXSAVE leaks FOP/FIP/FOP" }, + { "arch_perfmon","Intel Architectural PerfMon" }, + { "pebs", "Precise-Event Based Sampling" }, + { "bts", "Branch Trace Store" }, + { "sync_rdtsc", "RDTSC synchronizes the CPU" }, + { "rep_good", "rep microcode works well on this CPU" }, + { "mwait", "Monitor/Mwait support" }, + { "ds_cpl", "CPL Qualified Debug Store" }, + { "est", "Enhanced SpeedStep" }, + { "tm2", "Thermal Monitor 2" }, + { "cid", "Context ID" }, + { "xtpr", "Send Task Priority Messages" }, + { "xstore", "on-CPU RNG present (xstore insn)" }, + { "xstore_en", "on-CPU RNG enabled" }, + { "xcrypt", "on-CPU crypto (xcrypt insn)" }, + { "xcrypt_en", "on-CPU crypto enabled" }, + { "ace2", "Advanced Cryptography Engine v2" }, + { "ace2_en", "ACE v2 enabled" }, + { "phe", "PadLock Hash Engine" }, + { "phe_en", "PHE enabled" }, + { "pmm", "PadLock Montgomery Multiplier" }, + { "pmm_en", "PMM enabled" }, + { "lahf_lm", "LAHF/SAHF in long mode" }, + { "cmp_legacy", "HyperThreading not valid" }, + { "lm", "LAHF/SAHF in long mode" }, + { "ds_cpl", "CPL Qualified Debug Store" }, + { "vmx", "Virtualization support (Intel)" }, + { "svm", "Virtualization support (AMD)" }, + { "est", "Enhanced SpeedStep" }, + { "tm2", "Thermal Monitor 2" }, + { "ssse3", "Supplemental Streaming SIMD Extension 3" }, + { "cx16", "CMPXCHG16B instruction" }, + { "xptr", "Send Task Priority Messages" }, + { "pebs", "Precise Event Based Sampling" }, + { "bts", "Branch Trace Store" }, + { "ida", "Intel Dynamic Acceleration" }, + { "arch_perfmon","Intel Architectural PerfMon" }, + { "pni", "Streaming SIMD Extension 3 (Prescott New Instruction)" }, + { "rep_good", "rep microcode works well on this CPU" }, + { "ts", "Thermal Sensor" }, + { "sse3", "Streaming SIMD Extension 3" }, + { "sse4", "Streaming SIMD Extension 4" }, + { "tni", "Tejas New Instruction" }, + { "nni", "Nehalem New Instruction" }, + { "tpr", "Task Priority Register" }, + { "vid", "Voltage Identifier" }, + { "fid", "Frequency Identifier" }, + { "dtes64", "64-bit Debug Store" }, + { "monitor", "Monitor/Mwait support" }, + { NULL, NULL }, +}; + +GHashTable *cpu_flags = NULL; + +void cpu_flags_init(void) +{ + gint i; + gchar *path; + + cpu_flags = g_hash_table_new(g_str_hash, g_str_equal); + + path = g_build_filename(g_get_home_dir(), ".hardinfo", "cpuflags.conf", NULL); + if (!g_file_test(path, G_FILE_TEST_EXISTS)) { + DEBUG("using internal CPU flags database"); + + for (i = 0; flag_meaning[i].name != NULL; i++) { + g_hash_table_insert(cpu_flags, flag_meaning[i].name, + flag_meaning[i].meaning); + } + } else { + GKeyFile *flags_file; + + DEBUG("using %s as CPU flags database", path); + + flags_file = g_key_file_new(); + if (g_key_file_load_from_file(flags_file, path, 0, NULL)) { + gchar **flag_keys; + + flag_keys = g_key_file_get_keys(flags_file, "flags", + NULL, NULL); + for (i = 0; flag_keys[i]; i++) { + gchar *meaning; + + meaning = g_key_file_get_string(flags_file, "flags", + flag_keys[i], NULL); + + g_hash_table_insert(cpu_flags, g_strdup(flag_keys[i]), meaning); + + /* can't free meaning */ + } + + g_strfreev(flag_keys); + } + + g_key_file_free(flags_file); + } + + g_free(path); +} + +gchar *processor_get_capabilities_from_flags(gchar * strflags) +{ + /* FIXME: + * - Separate between processor capabilities, additional instructions and whatnot. + */ + gchar **flags, **old; + gchar *tmp = NULL; + gint j = 0; + + if (!cpu_flags) { + cpu_flags_init(); + } + + flags = g_strsplit(strflags, " ", 0); + old = flags; + + while (flags[j]) { + gchar *meaning = g_hash_table_lookup(cpu_flags, flags[j]); + + if (meaning) { + tmp = h_strdup_cprintf("%s=%s\n", tmp, flags[j], meaning); + } else { + tmp = h_strdup_cprintf("%s=\n", tmp, flags[j]); + } + j++; + } + + g_strfreev(old); + return tmp; +} + +gchar *processor_get_detailed_info(Processor * processor) +{ + gchar *tmp, *ret, *cache_info; + + tmp = processor_get_capabilities_from_flags(processor->flags); + cache_info = __cache_get_info_as_string(processor); + + ret = g_strdup_printf("[Processor]\n" + "Name=%s\n" + "Family, model, stepping=%d, %d, %d (%s)\n" + "Vendor=%s\n" + "[Configuration]\n" + "Cache Size=%dkb\n" + "Frequency=%.2fMHz\n" + "BogoMIPS=%.2f\n" + "Byte Order=%s\n" + "[Features]\n" + "FDIV Bug=%s\n" + "HLT Bug=%s\n" + "F00F Bug=%s\n" + "Coma Bug=%s\n" + "Has FPU=%s\n" + "[Cache]\n" + "%s\n" + "[Capabilities]\n" + "%s", + processor->model_name, + processor->family, + processor->model, + processor->stepping, + processor->strmodel, + vendor_get_name(processor->vendor_id), + processor->cache_size, + processor->cpu_mhz, processor->bogomips, +#if G_BYTE_ORDER == G_LITTLE_ENDIAN + "Little Endian", +#else + "Big Endian", +#endif + processor->bug_fdiv ? processor->bug_fdiv : "no", + processor->bug_hlt ? processor->bug_hlt : "no", + processor->bug_f00f ? processor->bug_f00f : "no", + processor->bug_coma ? processor->bug_coma : "no", + processor->has_fpu ? processor->has_fpu : "no", + cache_info, + tmp); + g_free(tmp); + g_free(cache_info); + + return ret; +} + +gchar *processor_get_info(GSList * processors) +{ + Processor *processor; + + if (g_slist_length(processors) > 1) { + gchar *ret, *tmp, *hashkey; + GSList *l; + + tmp = g_strdup(""); + + for (l = processors; l; l = l->next) { + processor = (Processor *) l->data; + + tmp = g_strdup_printf("%s$CPU%d$%s=%.2fMHz\n", + tmp, processor->id, + processor->model_name, + processor->cpu_mhz); + + hashkey = g_strdup_printf("CPU%d", processor->id); + g_hash_table_insert(moreinfo, hashkey, + processor_get_detailed_info(processor)); + } + + ret = g_strdup_printf("[$ShellParam$]\n" + "ViewType=1\n" + "[Processors]\n" + "%s", tmp); + g_free(tmp); + + return ret; + } + + processor = (Processor *) processors->data; + return processor_get_detailed_info(processor); +} diff --git a/hardinfo2/network.c b/hardinfo2/modules/network.c index 243b7706..168e04a9 100644 --- a/hardinfo2/network.c +++ b/hardinfo2/modules/network.c @@ -35,7 +35,9 @@ #include <vendor.h> -static GHashTable *moreinfo = NULL; +#include "network.h" + +GHashTable *moreinfo = NULL; /* Callbacks */ gchar *callback_network(); @@ -66,10 +68,6 @@ static ModuleEntry entries[] = { {NULL}, }; -#include <arch/this/samba.h> -#include <arch/this/nfs.h> -#include <arch/this/net.h> - void scan_shares(gboolean reload) { SCAN_START(); diff --git a/hardinfo2/modules/network/net.c b/hardinfo2/modules/network/net.c new file mode 100644 index 00000000..c470bc37 --- /dev/null +++ b/hardinfo2/modules/network/net.c @@ -0,0 +1,454 @@ +/* + * 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 + */ +/* + * Wireless Extension Example + * http://www.krugle.org/examples/p-OZYzuisV6gyQIaTu/iwconfig.c + */ + +#include "config.h" + +#include <stdio.h> +#include <unistd.h> +#include <string.h> + +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/socket.h> + +#include <netinet/in.h> +#include <linux/sockios.h> + +#include <arpa/inet.h> + +#ifdef HAS_LINUX_WE +#include <linux/if.h> +#include <linux/wireless.h> +#else +#include <net/if.h> +#endif /* HAS_LINUX_WE */ + +#include "hardinfo.h" +#include "network.h" + +gchar *network_interfaces = NULL, *network_icons = NULL; + +typedef struct _NetInfo NetInfo; +struct _NetInfo { + char name[16]; + int mtu; + unsigned char mac[8]; + char ip[16]; + char mask[16]; + char broadcast[16]; + +#ifdef HAS_LINUX_WE + char wi_essid[IW_ESSID_MAX_SIZE + 1]; + int wi_rate; + int wi_mode, wi_status; + gboolean wi_has_txpower; + struct iw_param wi_txpower; + int wi_quality_level, wi_signal_level, wi_noise_level; + gboolean is_wireless; +#endif +}; + +#ifdef HAS_LINUX_WE +const gchar *wi_operation_modes[] = { "Auto", "Ad-Hoc", "Managed", "Master", "Repeater", "Secondary", "Unknown" }; + +void get_wireless_info(int fd, NetInfo *netinfo) +{ + FILE *wrls; + char wbuf[256]; + struct iwreq wi_req; + int r, trash; + + netinfo->is_wireless = FALSE; + + if ((wrls = fopen("/proc/net/wireless", "r"))) { + while (fgets(wbuf, 256, wrls)) { + if (strchr(wbuf, ':') && strstr(wbuf, netinfo->name)) { + gchar *buf1 = wbuf; + + netinfo->is_wireless = TRUE; + + buf1 = strchr(buf1, ':') + 1; + + if (strstr(buf1, ".")) { + sscanf(buf1, "%d %d. %d %d %d %d %d %d %d %d", + &(netinfo->wi_status), + &(netinfo->wi_quality_level), + &(netinfo->wi_signal_level), + &(netinfo->wi_noise_level), + &trash, &trash, &trash, &trash, &trash, &trash); + } else { + sscanf(buf1, "%d %d %d %d %d %d %d %d %d %d", + &(netinfo->wi_status), + &(netinfo->wi_quality_level), + &(netinfo->wi_signal_level), + &(netinfo->wi_noise_level), + &trash, &trash, &trash, &trash, &trash, + &trash); + } + + break; + } + } + fclose(wrls); + } + + if (!netinfo->is_wireless) + return; + + strncpy(wi_req.ifr_name, netinfo->name, 16); + + /* obtain essid */ + wi_req.u.essid.pointer = netinfo->wi_essid; + wi_req.u.essid.length = IW_ESSID_MAX_SIZE + 1; + wi_req.u.essid.flags = 0; + + if ((r = ioctl(fd, SIOCGIWESSID, &wi_req) < 0)) { + strcpy(netinfo->wi_essid, ""); + } else { + netinfo->wi_essid[wi_req.u.essid.length] = '\0'; + } + + /* obtain bit rate */ + if ((r = ioctl(fd, SIOCGIWRATE, &wi_req) < 0)) { + netinfo->wi_rate = 0; + } else { + netinfo->wi_rate = wi_req.u.bitrate.value; + } + + /* obtain operation mode */ + if ((r = ioctl(fd, SIOCGIWMODE, &wi_req) < 0)) { + netinfo->wi_mode = 0; + } else { + if (wi_req.u.mode >= 0 && wi_req.u.mode < 6) { + netinfo->wi_mode = wi_req.u.mode; + } else { + netinfo->wi_mode = 6; + } + } + +#if WIRELESS_EXT >= 10 + /* obtain txpower */ + if ((r = ioctl(fd, SIOCGIWTXPOW, &wi_req) < 0)) { + netinfo->wi_has_txpower = FALSE; + } else { + netinfo->wi_has_txpower = TRUE; + + memcpy(&netinfo->wi_txpower, &wi_req.u.txpower, sizeof(struct iw_param)); + } +#else + netinfo->wi_has_txpower = FALSE; +#endif /* WIRELESS_EXT >= 10 */ +} +#endif /* HAS_LINUX_WE */ + +void get_net_info(char *if_name, NetInfo * netinfo) +{ + struct ifreq ifr; + int fd; + + fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); + + /* IPv4 */ + ifr.ifr_addr.sa_family = AF_INET; + strcpy(netinfo->name, if_name); + + /* MTU */ + strcpy(ifr.ifr_name, if_name); + if (ioctl(fd, SIOCGIFMTU, &ifr) < 0) { + netinfo->mtu = 0; + } else { + netinfo->mtu = ifr.ifr_mtu; + } + + /* HW Address */ + strcpy(ifr.ifr_name, if_name); + if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) { + memset(netinfo->mac, 0, 8); + } else { + memcpy(netinfo->mac, ifr.ifr_ifru.ifru_hwaddr.sa_data, 8); + } + + /* IP Address */ + strcpy(ifr.ifr_name, if_name); + if (ioctl(fd, SIOCGIFADDR, &ifr) < 0) { + netinfo->ip[0] = 0; + } else { + sprintf(netinfo->ip, "%s", + inet_ntoa(((struct sockaddr_in *) &ifr.ifr_addr)-> + sin_addr)); + } + + /* Mask Address */ + strcpy(ifr.ifr_name, if_name); + if (ioctl(fd, SIOCGIFNETMASK, &ifr) < 0) { + netinfo->mask[0] = 0; + } else { + sprintf(netinfo->mask, "%s", + inet_ntoa(((struct sockaddr_in *) &ifr.ifr_addr)-> + sin_addr)); + } + + /* Broadcast Address */ + strcpy(ifr.ifr_name, if_name); + if (ioctl(fd, SIOCGIFBRDADDR, &ifr) < 0) { + netinfo->broadcast[0] = 0; + } else { + sprintf(netinfo->broadcast, "%s", + inet_ntoa(((struct sockaddr_in *) &ifr.ifr_addr)-> + sin_addr)); + } + +#ifdef HAS_LINUX_WE + get_wireless_info(fd, netinfo); +#endif + + shutdown(fd, 0); + close(fd); +} + +static struct { + char *type; + char *label; + char *icon; +} netdev2type[] = { + { "eth", "Ethernet", "network-interface" }, + { "lo", "Loopback", "network" }, + { "ppp", "Point-to-Point", "modem" }, + { "ath", "Wireless", "wireless" }, + { "wlan", "Wireless", "wireless" }, + { "ra", "Wireless", "wireless" }, + { "wl", "Wireless", "wireless" }, + { "wmaster", "Wireless", "wireless" }, + { "tun", "Virtual Point-to-Point (TUN)", "network" }, + { "tap", "Ethernet (TAP)", "network" }, + { "plip", "Parallel Line Internet Protocol", "network" }, + { "irlan", "Infrared", "network" }, + { "slip", "Serial Line Internet Protocol", "network" }, + { "isdn", "Integrated Services Digital Network", "modem" }, + { "sit", "IPv6-over-IPv4 Tunnel", "network" }, + { "vmnet8", "VMWare Virtual Network Interface (NAT)", "computer" }, + { "vmnet", "VMWare Virtual Network Interface", "computer" }, + { "pan", "Personal Area Network (PAN)", "bluetooth" }, + { "bnep", "Bluetooth", "bluetooth" }, + { "br", "Bridge Interface", "network" }, + { "ham", "Hamachi Virtual Personal Network", "network"}, + { "net", "Ethernet", "network-interface" }, + { "ifb", "Intermediate Functional Block", "network" }, + { "gre", "GRE Network Tunnel", "network" }, + { "msh", "Mesh Network", "wireless" }, + { "wmaster", "Wireless Master Interface", "wireless" }, + { NULL, "Unknown", "network" }, +}; + +static void net_get_iface_type(gchar * name, gchar ** type, gchar ** icon, NetInfo *ni) +{ + int i; + +#ifdef HAS_LINUX_WE + if (ni->is_wireless) { + *type = "Wireless"; + *icon = "wireless"; + + return; + } +#endif + + for (i = 0; netdev2type[i].type; i++) { + if (g_str_has_prefix(name, netdev2type[i].type)) + break; + } + + *type = netdev2type[i].label; + *icon = netdev2type[i].icon; +} + +static gboolean +remove_net_devices(gpointer key, gpointer value, gpointer data) +{ + return g_str_has_prefix(key, "NET"); +} + +static void scan_net_interfaces_24(void) +{ + FILE *proc_net; + NetInfo ni; + gchar buffer[256]; + gchar *devid, *detailed; + gdouble recv_bytes; + gdouble recv_errors; + gdouble recv_packets; + + gdouble trans_bytes; + gdouble trans_errors; + gdouble trans_packets; + + if (!g_file_test("/proc/net/dev", G_FILE_TEST_EXISTS)) { + if (network_interfaces) { + g_free(network_interfaces); + network_interfaces = g_strdup("[Network Interfaces]\n" + "None found=\n"); + } + + return; + } + + if (network_interfaces) { + g_free(network_interfaces); + } + + if (network_icons) { + g_free(network_icons); + } + + network_interfaces = g_strdup("[Network Interfaces]\n"); + network_icons = g_strdup(""); + + proc_net = fopen("/proc/net/dev", "r"); + if (!proc_net) + return; + + while (fgets(buffer, 256, proc_net)) { + if (strchr(buffer, ':')) { + gint trash; + gchar ifacename[16]; + gchar *buf = buffer; + gchar *iface_type, *iface_icon; + gint i; + + buf = g_strstrip(buf); + + memset(ifacename, 0, 16); + + for (i = 0; buffer[i] != ':' && i < 16; i++) { + ifacename[i] = buffer[i]; + } + + buf = strchr(buf, ':') + 1; + + /* iface: bytes packets errs drop fifo frame compressed multicast */ + sscanf(buf, "%lf %lf %lf %d %d %d %d %d %lf %lf %lf", + &recv_bytes, &recv_packets, + &recv_errors, &trash, &trash, &trash, &trash, + &trash, &trans_bytes, &trans_packets, &trans_errors); + + gdouble recv_mb = recv_bytes / 1048576.0; + gdouble trans_mb = trans_bytes / 1048576.0; + + get_net_info(ifacename, &ni); + + devid = g_strdup_printf("NET%s", ifacename); + + network_interfaces = + h_strdup_cprintf + ("$%s$%s=%s|%.2lfMiB|%.2lfMiB\n", + network_interfaces, devid, ifacename, ni.ip[0] ? ni.ip : "", + trans_mb, recv_mb); + net_get_iface_type(ifacename, &iface_type, &iface_icon, &ni); + + network_icons = h_strdup_cprintf("Icon$%s$%s=%s.png\n", + network_icons, devid, + ifacename, iface_icon); + + detailed = g_strdup_printf("[Network Adapter Properties]\n" + "Interface Type=%s\n" + "Hardware Address (MAC)=%02x:%02x:%02x:%02x:%02x:%02x\n" + "MTU=%d\n" + "[Transfer Details]\n" + "Bytes Received=%.0lf (%.2fMiB)\n" + "Bytes Sent=%.0lf (%.2fMiB)\n", + iface_type, + ni.mac[0], ni.mac[1], + ni.mac[2], ni.mac[3], + ni.mac[4], ni.mac[5], + ni.mtu, + recv_bytes, recv_mb, + trans_bytes, trans_mb); + +#ifdef HAS_LINUX_WE + if (ni.is_wireless) { + gchar *txpower; + + if (ni.wi_has_txpower) { + gint mw, dbm; + + if (ni.wi_txpower.flags & IW_TXPOW_MWATT) { + mw = ni.wi_txpower.value; + dbm = (int) ceil(10.0 * log10((double) ni.wi_txpower.value)); + } else { + dbm = ni.wi_txpower.value; + mw = (int) floor(pow(10.0, ((double) dbm / 10.0))); + } + + txpower = g_strdup_printf("%ddBm (%dmW)", dbm, mw); + } else { + txpower = g_strdup("Unknown"); + } + + detailed = h_strdup_cprintf("\n[Wireless Properties]\n" + "Network Name (SSID)=%s\n" + "Bit Rate=%dMb/s\n" + "Transmission Power=%s\n" + "Mode=%s\n" + "Status=%d\n" + "Link Quality=%d\n" + "Signal / Noise=%d / %d\n", + detailed, + ni.wi_essid, + ni.wi_rate / 1000000, + txpower, + wi_operation_modes[ni.wi_mode], + ni.wi_status, + ni.wi_quality_level, + ni.wi_signal_level, + ni.wi_noise_level); + + g_free(txpower); + } +#endif + + if (ni.ip[0] || ni.mask[0] || ni.broadcast[0]) { + detailed = + h_strdup_cprintf("\n[Internet Protocol (IPv4)]\n" + "IP Address=%s\n" "Mask=%s\n" + "Broadcast Address=%s\n", detailed, + ni.ip[0] ? ni.ip : "Not set", + ni.mask[0] ? ni.mask : "Not set", + ni.broadcast[0] ? ni. + broadcast : "Not set"); + } + + g_hash_table_insert(moreinfo, devid, detailed); + } + } + fclose(proc_net); +} + +void scan_net_interfaces(void) +{ + /* FIXME: See if we're running Linux 2.6 and if /sys is mounted, then use + that instead of /proc/net/dev */ + + /* remove old devices from global device table */ + g_hash_table_foreach_remove(moreinfo, remove_net_devices, NULL); + + scan_net_interfaces_24(); +} diff --git a/hardinfo2/modules/network/nfs.c b/hardinfo2/modules/network/nfs.c new file mode 100644 index 00000000..63b2a2e6 --- /dev/null +++ b/hardinfo2/modules/network/nfs.c @@ -0,0 +1,61 @@ +/* + * 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 <string.h> + +#include "hardinfo.h" +#include "network.h" + +gchar *nfs_shares_list = NULL; + +void +scan_nfs_shared_directories(void) +{ + FILE *exports; + gint count = 0; + gchar buf[512]; + + if (nfs_shares_list) { + g_free(nfs_shares_list); + } + + nfs_shares_list = g_strdup(""); + + if ((exports = fopen("/etc/exports", "r"))) { + while (fgets(buf, 512, exports)) { + if (buf[0] != '/') + continue; + + strend(buf, ' '); + strend(buf, '\t'); + + nfs_shares_list = h_strdup_cprintf("%s=\n", + buf, nfs_shares_list); + count++; + } + + fclose(exports); + } + + if (!count) { + g_free(nfs_shares_list); + + nfs_shares_list = g_strdup("No NFS exports=\n"); + } +} + diff --git a/hardinfo2/modules/network/samba.c b/hardinfo2/modules/network/samba.c new file mode 100644 index 00000000..71ba6ab6 --- /dev/null +++ b/hardinfo2/modules/network/samba.c @@ -0,0 +1,124 @@ +/* + * 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 <string.h> + +#include "hardinfo.h" +#include "network.h" + +gchar *smb_shares_list = NULL; + +void scan_samba_from_string(gchar *str, gsize length); +void scan_samba_usershares(void); + +void +scan_samba(void) +{ + gchar *str; + gsize length; + + if (smb_shares_list) { + g_free(smb_shares_list); + smb_shares_list = g_strdup(""); + } + + if (g_file_get_contents("/etc/samba/smb.conf", + &str, &length, NULL)) { + shell_status_update("Scanning SAMBA shares..."); + scan_samba_from_string(str, length); + g_free(str); + } + + scan_samba_usershares(); +} + +void +scan_samba_usershares(void) +{ + FILE *usershare_list; + + if ((usershare_list = popen("net usershare list", "r"))) { + char buffer[512]; + + shell_status_update("Scanning SAMBA user shares..."); + + while (fgets(buffer, 512, usershare_list)) { + gchar *usershare, *cmdline; + gsize length; + + cmdline = g_strdup_printf("net usershare info '%s'", + strend(buffer, '\n')); + if (g_spawn_command_line_sync(cmdline, + &usershare, NULL, + NULL, NULL)) { + length = strlen(usershare); + scan_samba_from_string(usershare, length); + g_free(usershare); + } + + g_free(cmdline); + + shell_status_pulse(); + } + + pclose(usershare_list); + } +} + +void +scan_samba_from_string(gchar *str, gsize length) +{ + GKeyFile *keyfile; + GError *error = NULL; + gchar **groups; + gint i = 0; + + keyfile = g_key_file_new(); + + gchar *_smbconf = str; + for (; *_smbconf; _smbconf++) + if (*_smbconf == ';') *_smbconf = '\0'; + + if (!g_key_file_load_from_data(keyfile, str, length, 0, &error)) { + smb_shares_list = g_strdup("Cannot parse smb.conf=\n"); + if (error) + g_error_free(error); + goto cleanup; + } + + groups = g_key_file_get_groups(keyfile, NULL); + while (groups[i]) { + shell_status_pulse(); + + if (g_key_file_has_key(keyfile, groups[i], "path", NULL)) { + gchar *path = g_key_file_get_string(keyfile, groups[i], "path", NULL); + smb_shares_list = h_strdup_cprintf("%s=%s\n", + smb_shares_list, + groups[i], path); + g_free(path); + } + + i++; + } + + g_strfreev(groups); + + cleanup: + g_key_file_free(keyfile); +} + diff --git a/hardinfo2/remote.c b/hardinfo2/remote/remote.c index d266735d..d266735d 100644 --- a/hardinfo2/remote.c +++ b/hardinfo2/remote/remote.c diff --git a/hardinfo2/ssh-conn.c b/hardinfo2/remote/ssh-conn.c index 7f099d35..7f099d35 100644 --- a/hardinfo2/ssh-conn.c +++ b/hardinfo2/remote/ssh-conn.c diff --git a/hardinfo2/xmlrpc-client.c b/hardinfo2/remote/xmlrpc-client.c index d363729b..d363729b 100644 --- a/hardinfo2/xmlrpc-client.c +++ b/hardinfo2/remote/xmlrpc-client.c diff --git a/hardinfo2/xmlrpc-server.c b/hardinfo2/remote/xmlrpc-server.c index e953cfd1..e953cfd1 100644 --- a/hardinfo2/xmlrpc-server.c +++ b/hardinfo2/remote/xmlrpc-server.c diff --git a/hardinfo2/callbacks.c b/hardinfo2/shell/callbacks.c index 021560e2..021560e2 100644 --- a/hardinfo2/callbacks.c +++ b/hardinfo2/shell/callbacks.c diff --git a/hardinfo2/iconcache.c b/hardinfo2/shell/iconcache.c index c927ca5e..74b19b0c 100644 --- a/hardinfo2/iconcache.c +++ b/hardinfo2/shell/iconcache.c @@ -23,11 +23,9 @@ static GHashTable *cache = NULL; void icon_cache_init(void) { - DEBUG("initializing icon cache"); if (!cache) { + DEBUG("initializing icon cache"); cache = g_hash_table_new(g_str_hash, g_str_equal); - } else { - DEBUG("already initialized? huh?"); } } diff --git a/hardinfo2/loadgraph.c b/hardinfo2/shell/loadgraph.c index c8503072..c8503072 100644 --- a/hardinfo2/loadgraph.c +++ b/hardinfo2/shell/loadgraph.c diff --git a/hardinfo2/menu.c b/hardinfo2/shell/menu.c index 6b96e271..6b96e271 100644 --- a/hardinfo2/menu.c +++ b/hardinfo2/shell/menu.c diff --git a/hardinfo2/report.c b/hardinfo2/shell/report.c index fb87ee23..fb87ee23 100644 --- a/hardinfo2/report.c +++ b/hardinfo2/shell/report.c diff --git a/hardinfo2/shell.c b/hardinfo2/shell/shell.c index 1119c9cf..1119c9cf 100644 --- a/hardinfo2/shell.c +++ b/hardinfo2/shell/shell.c diff --git a/hardinfo2/stock.c b/hardinfo2/shell/stock.c index ad1a0135..ad1a0135 100644 --- a/hardinfo2/stock.c +++ b/hardinfo2/shell/stock.c diff --git a/hardinfo2/syncmanager.c b/hardinfo2/shell/syncmanager.c index 496dc348..496dc348 100644 --- a/hardinfo2/syncmanager.c +++ b/hardinfo2/shell/syncmanager.c diff --git a/hardinfo2/binreloc.c b/hardinfo2/util/binreloc.c index 1d1acfe6..1d1acfe6 100644 --- a/hardinfo2/binreloc.c +++ b/hardinfo2/util/binreloc.c diff --git a/hardinfo2/expr.c b/hardinfo2/util/expr.c index 32e303d7..32e303d7 100644 --- a/hardinfo2/expr.c +++ b/hardinfo2/util/expr.c diff --git a/hardinfo2/socket.c b/hardinfo2/util/socket.c index 339df30e..339df30e 100644 --- a/hardinfo2/socket.c +++ b/hardinfo2/util/socket.c diff --git a/hardinfo2/util.c b/hardinfo2/util/util.c index 54015b34..fb995406 100644 --- a/hardinfo2/util.c +++ b/hardinfo2/util/util.c @@ -546,13 +546,15 @@ static void module_register_methods(ShellModule * module) for (methods = get_methods(); methods->name; methods++) { ShellModuleMethod method = *methods; gchar *name = g_path_get_basename(g_module_name(module->dll)); + gchar *simple_name = strreplace(name, "lib", ""); + + strend(simple_name, '.'); - strend(name, '.'); - - method_name = g_strdup_printf("%s::%s", name, method.name); + method_name = g_strdup_printf("%s::%s", simple_name, method.name); g_hash_table_insert(__module_methods, method_name, method.function); g_free(name); + g_free(simple_name); } } @@ -661,18 +663,21 @@ static ShellModule *module_load(gchar * filename) module = g_new0(ShellModule, 1); if (params.gui_running) { - gchar *tmpicon; + gchar *tmpicon, *dot, *simple_name; tmpicon = g_strdup(filename); - gchar *dot = g_strrstr(tmpicon, "." G_MODULE_SUFFIX); + dot = g_strrstr(tmpicon, "." G_MODULE_SUFFIX); *dot = '\0'; - tmp = g_strdup_printf("%s.png", tmpicon); + simple_name = strreplace(tmpicon, "lib", ""); + + tmp = g_strdup_printf("%s.png", simple_name); module->icon = icon_cache_get_pixbuf(tmp); g_free(tmp); g_free(tmpicon); + g_free(simple_name); } tmp = g_build_filename(params.path_lib, "modules", filename, NULL); @@ -744,7 +749,7 @@ static ShellModule *module_load(gchar * filename) } else { DEBUG("cannot g_module_open(``%s''). permission problem?", filename); failed: - DEBUG("loading module %s failed", filename); + DEBUG("loading module %s failed: %s", filename, g_module_error()); g_free(module->name); g_free(module); diff --git a/hardinfo2/vendor.c b/hardinfo2/util/vendor.c index 86dba97a..86dba97a 100644 --- a/hardinfo2/vendor.c +++ b/hardinfo2/util/vendor.c |