*
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2007 Toni Spets
- * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* All rights reserved.
*
#endif
#include <linux/route.h>
#include <math.h>
+#include <pthread.h>
/* The following ifdefs were adapted from gkrellm */
#include <linux/major.h>
fgets(buf, 255, net_dev_fp); /* garbage (field names) */
/* read each interface */
- for (i2 = 0; i2 < 16; i2++) {
+ for (i2 = 0; i2 < MAX_NET_INTERFACES; i2++) {
struct net_stat *ns;
char *s, *p;
char temp_addr[18];
ns->up = 1;
memset(&(ns->addr.sa_data), 0, 14);
- memset(ns->addrs, 0, 17 * 16 + 1); /* Up to 17 chars per ip, max 16 interfaces. Nasty memory usage... */
+ memset(ns->addrs, 0, 17 * MAX_NET_INTERFACES + 1); /* Up to 17 chars per ip, max MAX_NET_INTERFACES interfaces. Nasty memory usage... */
last_recv = ns->recv;
last_trans = ns->trans;
/*** ip addr patch ***/
i = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
- conf.ifc_buf = malloc(sizeof(struct ifreq) * 16);
- conf.ifc_len = sizeof(struct ifreq) * 16;
+ conf.ifc_buf = malloc(sizeof(struct ifreq) * MAX_NET_INTERFACES);
+ conf.ifc_len = sizeof(struct ifreq) * MAX_NET_INTERFACES;
memset(conf.ifc_buf, 0, conf.ifc_len);
ioctl((long) i, SIOCGIFCONF, &conf);
curtmp1 = curtmp1 + ns->net_rec[i];
curtmp2 = curtmp2 + ns->net_trans[i];
}
- if (curtmp1 == 0) {
- curtmp1 = 1;
- }
- if (curtmp2 == 0) {
- curtmp2 = 1;
- }
ns->recv_speed = curtmp1 / (double) info.net_avg_samples;
ns->trans_speed = curtmp2 / (double) info.net_avg_samples;
if (info.net_avg_samples > 1) {
#define TMPL_LONGSTAT "%*s %llu %llu %llu %llu %llu %llu %llu %llu"
#define TMPL_SHORTSTAT "%*s %llu %llu %llu %llu"
-inline static void update_stat(void)
+void update_stat(void)
{
FILE *stat_fp;
static int rep = 0;
const char *stat_template = NULL;
unsigned int malloc_cpu_size = 0;
extern void* global_cpu;
+
+ static pthread_mutex_t last_stat_update_mutex = PTHREAD_MUTEX_INITIALIZER;
static double last_stat_update = 0.0;
/* since we use wrappers for this function, the update machinery
* can't eliminate double invocations of this function. Check for
* them here, otherwise cpu_usage counters are freaking out. */
- if (last_stat_update == current_update_time)
+ pthread_mutex_lock(&last_stat_update_mutex);
+ if (last_stat_update == current_update_time) {
+ pthread_mutex_unlock(&last_stat_update_mutex);
return;
+ }
last_stat_update = current_update_time;
+ pthread_mutex_unlock(&last_stat_update_mutex);
/* add check for !info.cpu_usage since that mem is freed on a SIGUSR1 */
if (!cpu_setup || !info.cpu_usage) {
}
if (!(stat_fp = open_file("/proc/stat", &rep))) {
- info.run_procs = 0;
+ info.run_threads = 0;
if (info.cpu_usage) {
memset(info.cpu_usage, 0, info.cpu_count * sizeof(float));
}
}
if (strncmp(buf, "procs_running ", 14) == 0) {
- sscanf(buf, "%*s %hu", &info.run_procs);
+ sscanf(buf, "%*s %hu", &info.run_threads);
} else if (strncmp(buf, "cpu", 3) == 0) {
double delta;
if (isdigit(buf[3])) {
}
}
-#define PROC_I8K "/proc/i8k"
-#define I8K_DELIM " "
-static char *i8k_procbuf = NULL;
-void update_i8k(void)
-{
- FILE *fp;
-
- if (!i8k_procbuf) {
- i8k_procbuf = (char *) malloc(128 * sizeof(char));
- }
- if ((fp = fopen(PROC_I8K, "r")) == NULL) {
- CRIT_ERR(NULL, NULL, "/proc/i8k doesn't exist! use insmod to make sure the kernel "
- "driver is loaded...");
- }
-
- memset(&i8k_procbuf[0], 0, 128);
- if (fread(&i8k_procbuf[0], sizeof(char), 128, fp) == 0) {
- NORM_ERR("something wrong with /proc/i8k...");
- }
-
- fclose(fp);
-
- i8k.version = strtok(&i8k_procbuf[0], I8K_DELIM);
- i8k.bios = strtok(NULL, I8K_DELIM);
- i8k.serial = strtok(NULL, I8K_DELIM);
- i8k.cpu_temp = strtok(NULL, I8K_DELIM);
- i8k.left_fan_status = strtok(NULL, I8K_DELIM);
- i8k.right_fan_status = strtok(NULL, I8K_DELIM);
- i8k.left_fan_rpm = strtok(NULL, I8K_DELIM);
- i8k.right_fan_rpm = strtok(NULL, I8K_DELIM);
- i8k.ac_status = strtok(NULL, I8K_DELIM);
- i8k.buttons_status = strtok(NULL, I8K_DELIM);
-}
-
/***********************************************************/
/***********************************************************/
/***********************************************************/
obj->data.opaque = NULL;
}
-/* Prior to kernel version 2.6.12, the CPU fan speed was available in
- * ADT746X_FAN_OLD, whereas later kernel versions provide this information in
- * ADT746X_FAN. */
-#define ADT746X_FAN "/sys/devices/temperatures/sensor1_fan_speed"
-#define ADT746X_FAN_OLD "/sys/devices/temperatures/cpu_fan_speed"
-
-void get_adt746x_fan(char *p_client_buffer, size_t client_buffer_size)
-{
- static int rep = 0;
- char adt746x_fan_state[64];
- FILE *fp;
-
- if (!p_client_buffer || client_buffer_size <= 0) {
- return;
- }
-
- if ((fp = open_file(ADT746X_FAN, &rep)) == NULL
- && (fp = open_file(ADT746X_FAN_OLD, &rep)) == NULL) {
- sprintf(adt746x_fan_state, "adt746x not found");
- } else {
- fgets(adt746x_fan_state, sizeof(adt746x_fan_state), fp);
- adt746x_fan_state[strlen(adt746x_fan_state) - 1] = 0;
- fclose(fp);
- }
-
- snprintf(p_client_buffer, client_buffer_size, "%s", adt746x_fan_state);
-}
-
-/* Prior to kernel version 2.6.12, the CPU temperature was found in
- * ADT746X_CPU_OLD, whereas later kernel versions provide this information in
- * ADT746X_CPU. */
-#define ADT746X_CPU "/sys/devices/temperatures/sensor1_temperature"
-#define ADT746X_CPU_OLD "/sys/devices/temperatures/cpu_temperature"
-
-void get_adt746x_cpu(char *p_client_buffer, size_t client_buffer_size)
-{
- static int rep = 0;
- char adt746x_cpu_state[64];
- FILE *fp;
-
- if (!p_client_buffer || client_buffer_size <= 0) {
- return;
- }
-
- if ((fp = open_file(ADT746X_CPU, &rep)) == NULL
- && (fp = open_file(ADT746X_CPU_OLD, &rep)) == NULL) {
- sprintf(adt746x_cpu_state, "adt746x not found");
- } else {
- fscanf(fp, "%2s", adt746x_cpu_state);
- fclose(fp);
- }
-
- snprintf(p_client_buffer, client_buffer_size, "%s", adt746x_cpu_state);
-}
-
#define CPUFREQ_PREFIX "/sys/devices/system/cpu"
#define CPUFREQ_POSTFIX "cpufreq/scaling_cur_freq"
* Peter Tarjan (ptarjan@citromail.hu) */
/* return cpu voltage in mV (use divisor=1) or V (use divisor=1000) */
-char get_voltage(char *p_client_buffer, size_t client_buffer_size,
+static char get_voltage(char *p_client_buffer, size_t client_buffer_size,
const char *p_format, int divisor, unsigned int cpu)
{
FILE *f;
return 1;
}
+void print_voltage_mv(struct text_object *obj, char *p, int p_max_size)
+{
+ static int ok = 1;
+ if (ok) {
+ ok = get_voltage(p, p_max_size, "%.0f", 1, obj->data.i);
+ }
+}
+
+void print_voltage_v(struct text_object *obj, char *p, int p_max_size)
+{
+ static int ok = 1;
+ if (ok) {
+ ok = get_voltage(p, p_max_size, "%'.3f", 1000, obj->data.i);
+ }
+}
+
#define ACPI_FAN_DIR "/proc/acpi/fan/"
void get_acpi_fan(char *p_client_buffer, size_t client_buffer_size)
info.first_process = get_first_process();
}
-void update_entropy(void)
+#define ENTROPY_AVAIL_PATH "/proc/sys/kernel/random/entropy_avail"
+
+int get_entropy_avail(unsigned int *val)
{
static int rep = 0;
- const char *entropy_avail = "/proc/sys/kernel/random/entropy_avail";
- const char *entropy_poolsize = "/proc/sys/kernel/random/poolsize";
- FILE *fp1, *fp2;
+ FILE *fp;
- info.entropy.entropy_avail = 0;
- info.entropy.poolsize = 0;
+ if (!(fp = open_file(ENTROPY_AVAIL_PATH, &rep)))
+ return 1;
- if ((fp1 = open_file(entropy_avail, &rep)) == NULL) {
- return;
- }
+ if (fscanf(fp, "%u", val) != 1)
+ return 1;
- if ((fp2 = open_file(entropy_poolsize, &rep)) == NULL) {
- fclose(fp1);
- return;
- }
+ fclose(fp);
+ return 0;
+}
- fscanf(fp1, "%u", &info.entropy.entropy_avail);
- fscanf(fp2, "%u", &info.entropy.poolsize);
+#define ENTROPY_POOLSIZE_PATH "/proc/sys/kernel/random/poolsize"
- fclose(fp1);
- fclose(fp2);
+int get_entropy_poolsize(unsigned int *val)
+{
+ static int rep = 0;
+ FILE *fp;
+
+ if (!(fp = open_file(ENTROPY_POOLSIZE_PATH, &rep)))
+ return 1;
+
+ if (fscanf(fp, "%u", val) != 1)
+ return 1;
+
+ fclose(fp);
+ return 0;
}
const char *get_disk_protect_queue(const char *disk)