From 72f82d096c05dc97b26f9ca30093343161dc4444 Mon Sep 17 00:00:00 2001 From: TingPing Date: Thu, 11 Dec 2014 09:57:11 -0500 Subject: [PATCH] Fix some warnings in xsys - Remove unused code - Fix leak --- plugins/sysinfo/Makefile.am | 2 +- plugins/sysinfo/hwmon.c | 64 ------------------------------------- plugins/sysinfo/hwmon.h | 28 ---------------- plugins/sysinfo/parse.c | 29 ++--------------- plugins/sysinfo/parse.h | 2 -- plugins/sysinfo/xsys.c | 5 ++- 6 files changed, 7 insertions(+), 123 deletions(-) delete mode 100644 plugins/sysinfo/hwmon.c delete mode 100644 plugins/sysinfo/hwmon.h diff --git a/plugins/sysinfo/Makefile.am b/plugins/sysinfo/Makefile.am index 0b8d7fad..3e7ef1aa 100644 --- a/plugins/sysinfo/Makefile.am +++ b/plugins/sysinfo/Makefile.am @@ -1,7 +1,7 @@ libdir = $(hexchatlibdir) lib_LTLIBRARIES = sysinfo.la -sysinfo_la_SOURCES = hwmon.c match.c parse.c pci.c xsys.c +sysinfo_la_SOURCES = match.c parse.c pci.c xsys.c sysinfo_la_LDFLAGS = -avoid-version -module sysinfo_la_LIBADD = -lpci AM_CPPFLAGS = $(COMMON_CFLAGS) -I$(srcdir)/../../src/common diff --git a/plugins/sysinfo/hwmon.c b/plugins/sysinfo/hwmon.c deleted file mode 100644 index e562458f..00000000 --- a/plugins/sysinfo/hwmon.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * hwmon.c - Hardware monitoring functions for X-Sys - * Copyright (C) 2005 Tony Vroon - * - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * 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 -#include -#include -#include -#include -#include "xsys.h" - -int hwmon_chip_present() -{ - FILE *fp = fopen("/sys/class/hwmon/hwmon0/device/name", "r"); - if(fp != NULL) { - fclose(fp); - return 1; - } - return 0; -} - -#if 0 -void get_hwmon_chip_name(char *name) -{ - char *position, buffer[bsize]; - FILE *fp = fopen("/sys/class/hwmon/hwmon0/device/name", "r"); - if(fp != NULL) { - if(fgets(buffer, bsize, fp) != NULL) { - position = strstr(buffer, "\n"); - *(position) = '\0'; - snprintf(name, sizeof(name), "%s", buffer); - } - fclose(fp); - } -} -#endif - -void get_hwmon_temp(unsigned int *value, unsigned int *sensor) -{ - char buffer[bsize]; - FILE *fp; - snprintf(buffer, bsize, "/sys/class/hwmon/hwmon0/device/temp%i_input", *sensor); - fp = fopen(buffer, "r"); - if(fp != NULL) { - if(fgets(buffer, bsize, fp) != NULL) - *value = atoi(buffer); - fclose(fp); - } -} diff --git a/plugins/sysinfo/hwmon.h b/plugins/sysinfo/hwmon.h deleted file mode 100644 index fe71274b..00000000 --- a/plugins/sysinfo/hwmon.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * hwmon.h - Hardware monitoring header for X-Sys - * Copyright (C) 2005 Tony Vroon - * - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * 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 - */ - - -#ifndef _HWMON_H_ -#define _HWMON_H_ - -int hwmon_chip_present(); -void get_hwmon_chip_name(char *name); -void get_hwmon_temp(unsigned int *value, unsigned int *sensor); - -#endif diff --git a/plugins/sysinfo/parse.c b/plugins/sysinfo/parse.c index 3f1ad6c5..6c86c645 100644 --- a/plugins/sysinfo/parse.c +++ b/plugins/sysinfo/parse.c @@ -32,7 +32,6 @@ #include "pci.h" #include "match.h" -#include "hwmon.h" #include "xsys.h" #include "parse.h" @@ -47,7 +46,8 @@ int xs_parse_cpu(char *model, char *vendor, double *freq, char *cache, unsigned FILE *fp = fopen("/proc/cpuinfo", "r"); if(fp == NULL) return 1; - if(count != NULL) *count = 0; + + *count = 0; strcpy(cache,"unknown\0"); #if defined(__i386__) || defined(__x86_64__) @@ -435,28 +435,3 @@ int xs_parse_distro(char *name) strcpy(name, buffer); return 0; } - -int xs_parse_hwmon_chip(char *chip) -{ - if (!hwmon_chip_present()) - return 1; -#if 0 - else - get_hwmon_chip_name(chip); -#endif - return 0; -} - -int xs_parse_hwmon_temp(char *temp, unsigned int *sensor) -{ - unsigned int value; - float celsius; - - if (!hwmon_chip_present()) - return 1; - else - get_hwmon_temp(&value, sensor); - celsius = (float)value; - snprintf(temp, bsize, "%.1fC", celsius/1000.0); - return 0; -} diff --git a/plugins/sysinfo/parse.h b/plugins/sysinfo/parse.h index 27aac7da..600793de 100644 --- a/plugins/sysinfo/parse.h +++ b/plugins/sysinfo/parse.h @@ -34,7 +34,5 @@ int xs_parse_video(char *vid_card); int xs_parse_agpbridge(char *agp_bridge); int xs_parse_ether(char *ethernet_card); int xs_parse_distro(char *name); -int xs_parse_hwmon_chip(char *chip); -int xs_parse_hwmon_temp(char *temp, unsigned int *sensor); #endif diff --git a/plugins/sysinfo/xsys.c b/plugins/sysinfo/xsys.c index 79abcea1..17c25616 100644 --- a/plugins/sysinfo/xsys.c +++ b/plugins/sysinfo/xsys.c @@ -86,6 +86,7 @@ print_summary (int announce, char* format) char os_host[bsize]; char os_user[bsize]; char os_kernel[bsize]; + char *free_space; unsigned long long mem_total; unsigned long long mem_free; unsigned int count; @@ -158,7 +159,9 @@ print_summary (int announce, char* format) return HEXCHAT_EAT_ALL; } - snprintf (buffer, bsize, "%s", pretty_freespace ("Physical", &mem_free, &mem_total)); + free_space = pretty_freespace ("Physical", &mem_free, &mem_total); + snprintf (buffer, bsize, "%s", free_space); + free (free_space); format_output ("RAM", buffer, format); strcat (sysinfo, "\017 "); strncat (sysinfo, buffer, bsize - strlen (sysinfo));