Fix some warnings in xsys

- Remove unused code
- Fix leak
This commit is contained in:
TingPing 2014-12-11 09:57:11 -05:00
parent 74ff67acd3
commit 72f82d096c
6 changed files with 7 additions and 123 deletions

View File

@ -1,7 +1,7 @@
libdir = $(hexchatlibdir) libdir = $(hexchatlibdir)
lib_LTLIBRARIES = sysinfo.la 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_LDFLAGS = -avoid-version -module
sysinfo_la_LIBADD = -lpci sysinfo_la_LIBADD = -lpci
AM_CPPFLAGS = $(COMMON_CFLAGS) -I$(srcdir)/../../src/common AM_CPPFLAGS = $(COMMON_CFLAGS) -I$(srcdir)/../../src/common

View File

@ -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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#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);
}
}

View File

@ -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

View File

@ -32,7 +32,6 @@
#include "pci.h" #include "pci.h"
#include "match.h" #include "match.h"
#include "hwmon.h"
#include "xsys.h" #include "xsys.h"
#include "parse.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"); FILE *fp = fopen("/proc/cpuinfo", "r");
if(fp == NULL) if(fp == NULL)
return 1; return 1;
if(count != NULL) *count = 0;
*count = 0;
strcpy(cache,"unknown\0"); strcpy(cache,"unknown\0");
#if defined(__i386__) || defined(__x86_64__) #if defined(__i386__) || defined(__x86_64__)
@ -435,28 +435,3 @@ int xs_parse_distro(char *name)
strcpy(name, buffer); strcpy(name, buffer);
return 0; 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;
}

View File

@ -34,7 +34,5 @@ int xs_parse_video(char *vid_card);
int xs_parse_agpbridge(char *agp_bridge); int xs_parse_agpbridge(char *agp_bridge);
int xs_parse_ether(char *ethernet_card); int xs_parse_ether(char *ethernet_card);
int xs_parse_distro(char *name); int xs_parse_distro(char *name);
int xs_parse_hwmon_chip(char *chip);
int xs_parse_hwmon_temp(char *temp, unsigned int *sensor);
#endif #endif

View File

@ -86,6 +86,7 @@ print_summary (int announce, char* format)
char os_host[bsize]; char os_host[bsize];
char os_user[bsize]; char os_user[bsize];
char os_kernel[bsize]; char os_kernel[bsize];
char *free_space;
unsigned long long mem_total; unsigned long long mem_total;
unsigned long long mem_free; unsigned long long mem_free;
unsigned int count; unsigned int count;
@ -158,7 +159,9 @@ print_summary (int announce, char* format)
return HEXCHAT_EAT_ALL; 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); format_output ("RAM", buffer, format);
strcat (sysinfo, "\017 "); strcat (sysinfo, "\017 ");
strncat (sysinfo, buffer, bsize - strlen (sysinfo)); strncat (sysinfo, buffer, bsize - strlen (sysinfo));