{
}
-void update_uptime(void)
+int update_uptime(void)
{
#ifdef HAVE_SYSINFO
if (!prefer_proc) {
if (!(fp = open_file("/proc/uptime", &rep))) {
info.uptime = 0.0;
- return;
+ return 0;
}
fscanf(fp, "%lf", &info.uptime);
fclose(fp);
}
+ return 0;
}
int check_mount(char *s)
/* these things are also in sysinfo except Buffers:
* (that's why I'm reading them from proc) */
-void update_meminfo(void)
+int update_meminfo(void)
{
FILE *meminfo_fp;
static int rep = 0;
info.buffers = info.cached = info.memfree = info.memeasyfree = 0;
if (!(meminfo_fp = open_file("/proc/meminfo", &rep))) {
- return;
+ return 0;
}
while (!feof(meminfo_fp)) {
info.bufmem = info.cached + info.buffers;
fclose(meminfo_fp);
+ return 0;
}
int get_laptop_mode(void)
/* Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT */
#define RT_ENTRY_FORMAT "%63s %lx %lx %x %*d %*d %*d %lx %*d %*d %*d\n"
-void update_gateway_info(void)
+int update_gateway_info(void)
{
FILE *fp;
struct in_addr ina;
if ((fp = fopen("/proc/net/route", "r")) == NULL) {
update_gateway_info_failure("fopen()");
- return;
+ return 0;
}
/* skip over the table header line, which is always present */
}
}
fclose(fp);
- return;
+ return 0;
}
void free_gateway_info(void)
snprintf(p, p_max_size, "%s", gw_info.ip);
}
-void update_net_stats(void)
+int update_net_stats(void)
{
FILE *net_dev_fp;
static int rep = 0;
/* get delta */
delta = current_update_time - last_update_time;
if (delta <= 0.0001) {
- return;
+ return 0;
}
/* open file and ignore first two lines */
if (!(net_dev_fp = open_file("/proc/net/dev", &rep))) {
clear_net_stats();
- return;
+ return 0;
}
fgets(buf, 255, net_dev_fp); /* garbage */
first = 0;
fclose(net_dev_fp);
+ return 0;
}
int result;
-void update_total_processes(void)
+int update_total_processes(void)
{
DIR *dir;
struct dirent *entry;
info.procs = 0;
if (!(dir = opendir("/proc"))) {
- return;
+ return 0;
}
while ((entry = readdir(dir))) {
if (!entry) {
/* Problem reading list of processes */
closedir(dir);
info.procs = 0;
- return;
+ return 0;
}
if (sscanf(entry->d_name, "%d%c", &ignore1, &ignore2) == 1) {
info.procs++;
}
}
closedir(dir);
+ return 0;
}
-void update_threads(void)
+int update_threads(void)
{
#ifdef HAVE_SYSINFO
if (!prefer_proc) {
if (!(fp = open_file("/proc/loadavg", &rep))) {
info.threads = 0;
- return;
+ return 0;
}
fscanf(fp, "%*f %*f %*f %*d/%hu", &info.threads);
fclose(fp);
}
+ return 0;
}
#define CPU_SAMPLE_COUNT 15
#define TMPL_LONGSTAT "%*s %llu %llu %llu %llu %llu %llu %llu %llu"
#define TMPL_SHORTSTAT "%*s %llu %llu %llu %llu"
-void update_stat(void)
+int update_stat(void)
{
FILE *stat_fp;
static int rep = 0;
pthread_mutex_lock(&last_stat_update_mutex);
if (last_stat_update == current_update_time) {
pthread_mutex_unlock(&last_stat_update_mutex);
- return;
+ return 0;
}
last_stat_update = current_update_time;
pthread_mutex_unlock(&last_stat_update_mutex);
if (info.cpu_usage) {
memset(info.cpu_usage, 0, info.cpu_count * sizeof(float));
}
- return;
+ return 0;
}
idx = 0;
}
}
fclose(stat_fp);
+ return 0;
}
-void update_running_processes(void)
+int update_running_processes(void)
{
update_stat();
+ return 0;
}
-void update_cpu_usage(void)
+int update_cpu_usage(void)
{
update_stat();
+ return 0;
}
-void update_load_average(void)
+int update_load_average(void)
{
#ifdef HAVE_GETLOADAVG
if (!prefer_proc) {
if (!(fp = open_file("/proc/loadavg", &rep))) {
info.loadavg[0] = info.loadavg[1] = info.loadavg[2] = 0.0;
- return;
+ return 0;
}
fscanf(fp, "%f %f %f", &info.loadavg[0], &info.loadavg[1],
&info.loadavg[2]);
fclose(fp);
}
+ return 0;
}
/***********************************************************/
Update: it seems the folder name is hardware-dependent. We add an aditional adapter
argument, specifying the folder name.
+
+ Update: on some systems it's /sys/class/power_supply/ADP1 instead of /sys/class/power_supply/AC
*/
void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size, const char *adapter)
char buf[256];
char buf2[256];
+ struct stat sb;
FILE *fp;
if (!p_client_buffer || client_buffer_size <= 0) {
return;
}
- snprintf(buf2, sizeof(buf2), "%s/%s/uevent", SYSFS_AC_ADAPTER_DIR, adapter);
- fp = open_file(buf2, &rep);
+ if(adapter)
+ snprintf(buf2, sizeof(buf2), "%s/%s/uevent", SYSFS_AC_ADAPTER_DIR, adapter);
+ else{
+ snprintf(buf2, sizeof(buf2), "%s/AC/uevent", SYSFS_AC_ADAPTER_DIR);
+ if(stat(buf2, &sb) == -1) snprintf(buf2, sizeof(buf2), "%s/ADP1/uevent", SYSFS_AC_ADAPTER_DIR);
+ }
+ if(stat(buf2, &sb) == 0) fp = open_file(buf2, &rep); else fp = 0;
if (fp) {
/* sysfs processing */
while (!feof(fp)) {
snprintf(buffer, n, "%s", pb_battery_info[i]);
}
-void update_top(void)
+int update_top(void)
{
process_find_top(info.cpu, info.memu, info.time
#ifdef IOSTATS
#endif
);
info.first_process = get_first_process();
+ return 0;
}
#define ENTROPY_AVAIL_PATH "/proc/sys/kernel/random/entropy_avail"
return (state > 0) ? "frozen" : "free ";
}
-void update_diskio(void)
+typedef struct DEV_LIST_TYPE
+{
+ char *dev_name;
+ int memoized;
+ struct DEV_LIST_TYPE *next;
+
+} DEV_LIST, *DEV_LIST_PTR;
+
+/* Same as sf #2942117 but memoized using a linked list */
+int is_disk(char *dev)
+{
+ char syspath[PATH_MAX];
+ char *slash;
+ static DEV_LIST_PTR dev_head = NULL;
+ DEV_LIST_PTR dev_cur, dev_last;
+
+ dev_cur = dev_head;
+
+ while (dev_cur) {
+ if (strcmp(dev_cur->dev_name, dev) == 0)
+ return dev_cur->memoized;
+ dev_last = dev_cur;
+ dev_cur = dev_cur->next;
+ }
+
+ dev_cur = (DEV_LIST_PTR)malloc(sizeof(DEV_LIST));
+ dev_cur->dev_name = (char *)malloc((strlen(dev)+1)*sizeof(char));
+ strcpy(dev_cur->dev_name,dev);
+ dev_cur->next = NULL;
+
+ while ((slash = strchr(dev, '/')))
+ *slash = '!';
+ snprintf(syspath, sizeof(syspath), "/sys/block/%s", dev);
+ dev_cur->memoized = !(access(syspath, F_OK));
+
+ if (dev_head)
+ dev_last->next = dev_cur;
+ else
+ dev_head = dev_cur;
+
+ return dev_cur->memoized;
+}
+
+int update_diskio(void)
{
FILE *fp;
static int rep = 0;
struct diskio_stat *cur;
unsigned int reads, writes;
unsigned int total_reads = 0, total_writes = 0;
- size_t len_devbuf;
stats.current = 0;
stats.current_read = 0;
stats.current_write = 0;
if (!(fp = open_file("/proc/diskstats", &rep))) {
- return;
+ return 0;
}
/* read reads and writes from all disks (minor = 0), including cd-roms
* XXX: ignore devices which are part of a SW RAID (MD_MAJOR) */
if (col_count == 5 && major != LVM_BLK_MAJOR && major != NBD_MAJOR
&& major != RAMDISK_MAJOR && major != LOOP_MAJOR) {
- /* If the last character of the device is a digit we assume
- * it is a subdevice (needed for kernel > 2.6.31) */
- len_devbuf = strlen(devbuf);
- if ((len_devbuf > 0) && !isdigit(devbuf[len_devbuf-1])) {
+ /* check needed for kernel >= 2.6.31, see sf #2942117 */
+ if (is_disk(devbuf)) {
total_reads += reads;
total_writes += writes;
}
}
update_diskio_values(&stats, total_reads, total_writes);
fclose(fp);
+ return 0;
}