added new variables battery_volts and battery_temp
[monky] / src / linux.c
index 23f95fa..49e4768 100644 (file)
@@ -105,7 +105,7 @@ void prepare_update(void)
 {
 }
 
-void update_uptime(void)
+int update_uptime(void)
 {
 #ifdef HAVE_SYSINFO
        if (!prefer_proc) {
@@ -121,11 +121,12 @@ void update_uptime(void)
 
                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)
@@ -153,7 +154,7 @@ 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;
@@ -165,7 +166,7 @@ void update_meminfo(void)
                info.buffers = info.cached = info.memfree = info.memeasyfree = 0;
 
        if (!(meminfo_fp = open_file("/proc/meminfo", &rep))) {
-               return;
+               return 0;
        }
 
        while (!feof(meminfo_fp)) {
@@ -195,6 +196,7 @@ void update_meminfo(void)
        info.bufmem = info.cached + info.buffers;
 
        fclose(meminfo_fp);
+       return 0;
 }
 
 int get_laptop_mode(void)
@@ -265,7 +267,7 @@ void update_gateway_info_failure(const char *reason)
 /* 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;
@@ -279,7 +281,7 @@ void update_gateway_info(void)
 
        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 */
@@ -299,7 +301,7 @@ void update_gateway_info(void)
                }
        }
        fclose(fp);
-       return;
+       return 0;
 }
 
 void free_gateway_info(void)
@@ -326,7 +328,7 @@ void print_gateway_ip(char *p, int p_max_size)
        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;
@@ -350,13 +352,13 @@ void update_net_stats(void)
        /* 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 */
@@ -538,11 +540,12 @@ void update_net_stats(void)
        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;
@@ -551,23 +554,24 @@ void update_total_processes(void)
 
        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) {
@@ -583,11 +587,12 @@ void update_threads(void)
 
                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
@@ -661,7 +666,7 @@ void get_cpu_count(void)
 #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;
@@ -683,7 +688,7 @@ void update_stat(void)
        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);
@@ -711,7 +716,7 @@ void update_stat(void)
                if (info.cpu_usage) {
                        memset(info.cpu_usage, 0, info.cpu_count * sizeof(float));
                }
-               return;
+               return 0;
        }
 
        idx = 0;
@@ -782,19 +787,22 @@ void update_stat(void)
                }
        }
        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) {
@@ -812,12 +820,13 @@ void update_load_average(void)
 
                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;
 }
 
 /***********************************************************/
@@ -1336,6 +1345,8 @@ void get_acpi_fan(char *p_client_buffer, size_t client_buffer_size)
 
    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)
@@ -1344,14 +1355,20 @@ void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size, const
 
        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)) {
@@ -1532,10 +1549,24 @@ present voltage:         16608 mV
   On some systems POWER_SUPPLY_ENERGY_* is replaced by POWER_SUPPLY_CHARGE_*
 */
 
+/*on n900 with power kernel: (non power kernel could use "hal-device bme" and do something else)
+/sys/class/power_supply/bq27200-0/uevent
+PHYSDEVPATH=/class/i2c-adapter/i2c-2/2-0055
+PHYSDEVBUS=i2c
+PHYSDEVDRIVER=bq27200-battery
+POWER_SUPPLY_NAME=bq27200-0
+POWER_SUPPLY_TYPE=Battery
+POWER_SUPPLY_PRESENT=1                                                                                                 << this is always 1, it means the battery is inserted
+POWER_SUPPLY_VOLTAGE_NOW=4039                                                                          << this keeps updating during charging
+POWER_SUPPLY_CURRENT_NOW=1960                   << this goes negative when charging!
+POWER_SUPPLY_CAPACITY=98                                                                                               << supposed to be the %, I THOUGHT it stops updating when charging until it hits 100%, but maybe not?
+POWER_SUPPLY_TEMP=39                                                                                                           << only temperature sensor in n900 :(
+*/
+
 #define SYSFS_BATTERY_BASE_PATH "/sys/class/power_supply"
-#define ACPI_BATTERY_BASE_PATH "/proc/acpi/battery"
-#define APM_PATH "/proc/apm"
-#define MAX_BATTERY_COUNT 4
+#define ACPI_BATTERY_BASE_PATH "/proc/acpi/battery" //not for n900
+#define APM_PATH "/proc/apm"  //not for n900
+#define MAX_BATTERY_COUNT 4 //more like 1
 
 static FILE *sysfs_bat_fp[MAX_BATTERY_COUNT] = { NULL, NULL, NULL, NULL };
 static FILE *acpi_bat_fp[MAX_BATTERY_COUNT] = { NULL, NULL, NULL, NULL };
@@ -1547,6 +1578,12 @@ static char batteries[MAX_BATTERY_COUNT][32];
 static int acpi_last_full[MAX_BATTERY_COUNT];
 static int acpi_design_capacity[MAX_BATTERY_COUNT];
 
+//eg 4100
+static int last_battery_volts[MAX_BATTERY_COUNT];
+
+//eg 35
+static int last_battery_temp[MAX_BATTERY_COUNT];
+
 /* e.g. "charging 75%" */
 static char last_battery_str[MAX_BATTERY_COUNT][64];
 /* e.g. "3h 15m" */
@@ -1616,6 +1653,8 @@ void get_battery_stuff(char *buffer, unsigned int n, const char *bat, int item)
 
        memset(last_battery_str[idx], 0, sizeof(last_battery_str[idx]));
        memset(last_battery_time_str[idx], 0, sizeof(last_battery_time_str[idx]));
+       //memset(last_battery_volts[idx], 0, sizeof(last_battery_volts[idx]));
+       //memset(last_battery_temp[idx], 0, sizeof(last_battery_temp[idx]));
 
        /* first try SYSFS if that fails try ACPI */
 
@@ -1629,11 +1668,14 @@ void get_battery_stuff(char *buffer, unsigned int n, const char *bat, int item)
 
        if (sysfs_bat_fp[idx] != NULL) {
                /* SYSFS */
-               int present_rate = -1;
-               int remaining_capacity = -1;
-               char charging_state[64];
+               int present_rate = -9999; //we will put "current now" into this. negative when charging!
+               int remaining_capacity = -1; //in %
+               char charging_state[64];//can't get this without hal bme
+               int voltage = -1;
+               //int capacity = -1;
+               int temp = 9999;
                char present[4];
-
+               strcpy(present, "no");
                strcpy(charging_state, "unknown");
 
                while (!feof(sysfs_bat_fp[idx])) {
@@ -1643,100 +1685,108 @@ void get_battery_stuff(char *buffer, unsigned int n, const char *bat, int item)
 
                        /* let's just hope units are ok */
                        if (strncmp (buf, "POWER_SUPPLY_PRESENT=1", 22) == 0)
-                               strcpy(present, "yes");
-                       else if (strncmp (buf, "POWER_SUPPLY_PRESENT=0", 22) == 0)
-                               strcpy(present, "no");
-                       else if (strncmp (buf, "POWER_SUPPLY_STATUS=", 20) == 0)
-                               sscanf(buf, "POWER_SUPPLY_STATUS=%63s", charging_state);
-                       /* present_rate is not the same as the
-                       current flowing now but it is the same value
-                       which was used in the past. so we continue
-                       the tradition! */
+                               strcpy(present, "yes");//n900 always yes
+                       else if (strncmp(buf, "POWER_SUPPLY_VOLTAGE_NOW=", 25) == 0)
+                               sscanf(buf, "POWER_SUPPLY_VOLTAGE_NOW=%d", &voltage);
+//             else if (strncmp (buf, "POWER_SUPPLY_STATUS=", 20) == 0)
+//                     sscanf(buf, "POWER_SUPPLY_STATUS=%63s", charging_state);
                        else if (strncmp(buf, "POWER_SUPPLY_CURRENT_NOW=", 25) == 0)
                                sscanf(buf, "POWER_SUPPLY_CURRENT_NOW=%d", &present_rate);
-                       else if (strncmp(buf, "POWER_SUPPLY_ENERGY_NOW=", 24) == 0)
-                               sscanf(buf, "POWER_SUPPLY_ENERGY_NOW=%d", &remaining_capacity);
-                       else if (strncmp(buf, "POWER_SUPPLY_ENERGY_FULL=", 25) == 0)
-                               sscanf(buf, "POWER_SUPPLY_ENERGY_FULL=%d", &acpi_last_full[idx]);
-                       else if (strncmp(buf, "POWER_SUPPLY_CHARGE_NOW=", 24) == 0)
-                               sscanf(buf, "POWER_SUPPLY_CHARGE_NOW=%d", &remaining_capacity);
-                       else if (strncmp(buf, "POWER_SUPPLY_CHARGE_FULL=", 25) == 0)
-                               sscanf(buf, "POWER_SUPPLY_CHARGE_FULL=%d", &acpi_last_full[idx]);
+                       else if (strncmp(buf, "POWER_SUPPLY_CAPACITY=", 22) == 0)
+                               sscanf(buf, "POWER_SUPPLY_CAPACITY=%d", &remaining_capacity);
+                       else if (strncmp(buf, "POWER_SUPPLY_TEMP=", 18) == 0)
+                               sscanf(buf, "POWER_SUPPLY_TEMP=%d", &temp);
+//                     else if (strncmp(buf, "POWER_SUPPLY_ENERGY_NOW=", 24) == 0)
+//                             sscanf(buf, "POWER_SUPPLY_ENERGY_NOW=%d", &remaining_capacity);
+//                     else if (strncmp(buf, "POWER_SUPPLY_ENERGY_FULL=", 25) == 0)
+//                             sscanf(buf, "POWER_SUPPLY_ENERGY_FULL=%d", &acpi_last_full[idx]);
+//                     else if (strncmp(buf, "POWER_SUPPLY_CHARGE_NOW=", 24) == 0)
+//                             sscanf(buf, "POWER_SUPPLY_CHARGE_NOW=%d", &remaining_capacity);
+//                     else if (strncmp(buf, "POWER_SUPPLY_CHARGE_FULL=", 25) == 0)
+//                             sscanf(buf, "POWER_SUPPLY_CHARGE_FULL=%d", &acpi_last_full[idx]);
                }
 
                fclose(sysfs_bat_fp[idx]);
                sysfs_bat_fp[idx] = NULL;
+               
+               last_battery_volts[idx] = voltage;
+               last_battery_temp[idx] = temp;
 
                /* Hellf[i]re notes that remaining capacity can exceed acpi_last_full */
-               if (remaining_capacity > acpi_last_full[idx])
-                       acpi_last_full[idx] = remaining_capacity;  /* normalize to 100% */
+               //lance notes, we don't care
+//             if (remaining_capacity > acpi_last_full[idx])
+//                     acpi_last_full[idx] = remaining_capacity;  /* normalize to 100% */
 
                /* not present */
-               if (strcmp(present, "No") == 0) {
-                       strncpy(last_battery_str[idx], "not present", 64);
-               }
+               //not possible
+//             if (strcmp(present, "no") == 0) {
+//                     strncpy(last_battery_str[idx], "not present", 64);
+//             }
                /* charging */
-               else if (strcmp(charging_state, "Charging") == 0) {
-                       if (acpi_last_full[idx] != 0 && present_rate > 0) {
+               if (present_rate <= 0) {//if charging
                                /* e.g. charging 75% */
-                               snprintf(last_battery_str[idx], sizeof(last_battery_str[idx])-1, "charging %i%%",
-                                       (int) (((float) remaining_capacity / acpi_last_full[idx]) * 100 ));
+                               snprintf(last_battery_str[idx], sizeof(last_battery_str[idx])-1, "charging %i%%", remaining_capacity);
+                               snprintf(last_battery_time_str[idx], sizeof(last_battery_time_str[idx]) - 1, "unknown");
                                /* e.g. 2h 37m */
-                               format_seconds(last_battery_time_str[idx], sizeof(last_battery_time_str[idx])-1,
-                                             (long) (((float)(acpi_last_full[idx] - remaining_capacity) / present_rate) * 3600));
-                       } else if (acpi_last_full[idx] != 0 && present_rate <= 0) {
-                               snprintf(last_battery_str[idx], sizeof(last_battery_str[idx])-1, "charging %d%%",
-                                       (int) (((float)remaining_capacity / acpi_last_full[idx]) * 100));
-                               snprintf(last_battery_time_str[idx],
-                                       sizeof(last_battery_time_str[idx]) - 1, "unknown");
-                       } else {
-                               strncpy(last_battery_str[idx], "charging", sizeof(last_battery_str[idx])-1);
-                               snprintf(last_battery_time_str[idx],
-                                       sizeof(last_battery_time_str[idx]) - 1, "unknown");
-                       }
-               }
+//                             format_seconds(last_battery_time_str[idx], sizeof(last_battery_time_str[idx])-1,
+//                                           (long) (((float)(acpi_last_full[idx] - remaining_capacity) / present_rate) * 3600));
+               }
+
+//             else if (acpi_last_full[idx] != 0 && present_rate <= 0) {//supposed to be guessing the time to fully charge, won't work though.
+//                     snprintf(last_battery_str[idx], sizeof(last_battery_str[idx])-1, "charging %d%%",
+//                             (int) (((float)remaining_capacity / acpi_last_full[idx]) * 100));
+//                     snprintf(last_battery_time_str[idx],
+//                             sizeof(last_battery_time_str[idx]) - 1, "unknown");
+//             } else {
+//                             strncpy(last_battery_str[idx], "charging", sizeof(last_battery_str[idx])-1);
+//                             snprintf(last_battery_time_str[idx],
+//                                     sizeof(last_battery_time_str[idx]) - 1, "unknown");
+//                     }
+//             }
                /* discharging */
-               else if (strncmp(charging_state, "Discharging", 64) == 0) {
-                       if (present_rate > 0) {
+               else if (present_rate > 0) {
+                         
                                /* e.g. discharging 35% */
-                               snprintf(last_battery_str[idx], sizeof(last_battery_str[idx])-1, "discharging %i%%",
-                                       (int) (((float) remaining_capacity / acpi_last_full[idx]) * 100 ));
-                               /* e.g. 1h 12m */
-                               format_seconds(last_battery_time_str[idx], sizeof(last_battery_time_str[idx])-1,
-                                             (long) (((float) remaining_capacity / present_rate) * 3600));
-                       } else if (present_rate == 0) { /* Thanks to Nexox for this one */
-                               snprintf(last_battery_str[idx], sizeof(last_battery_str[idx])-1, "full");
-                               snprintf(last_battery_time_str[idx],
-                                       sizeof(last_battery_time_str[idx]) - 1, "unknown");
-                       } else {
-                               snprintf(last_battery_str[idx], sizeof(last_battery_str[idx])-1,
-                                       "discharging %d%%",
-                                       (int) (((float)remaining_capacity / acpi_last_full[idx]) * 100));
-                               snprintf(last_battery_time_str[idx],
+                               snprintf(last_battery_str[idx], sizeof(last_battery_str[idx])-1, "discharging %i%%", remaining_capacity);
+
+                               snprintf(last_battery_time_str[idx],
                                        sizeof(last_battery_time_str[idx]) - 1, "unknown");
-                       }
+                                       /* e.g. 1h 12m */
+//                             format_seconds(last_battery_time_str[idx], sizeof(last_battery_time_str[idx])-1,
+//                                           (long) (((float) remaining_capacity / present_rate) * 3600));             
+//                      else {
+//                             snprintf(last_battery_str[idx], sizeof(last_battery_str[idx])-1,
+//                                     "discharging %d%%",
+//                                     (int) (((float)remaining_capacity / acpi_last_full[idx]) * 100));
+//                             snprintf(last_battery_time_str[idx],
+//                                     sizeof(last_battery_time_str[idx]) - 1, "unknown");
+//                     }
                }
                /* charged */
                /* thanks to Lukas Zapletal <lzap@seznam.cz> */
-               else if (strncmp(charging_state, "Charged", 64) == 0 || strncmp(charging_state, "Full", 64) == 0) {
-                               /* Below happens with the second battery on my X40,
-                                * when the second one is empty and the first one
-                                * being charged. */
-                               if (remaining_capacity == 0)
-                                       strcpy(last_battery_str[idx], "empty");
-                               else
-                                       strcpy(last_battery_str[idx], "charged");
-               }
+               
+                if (remaining_capacity == 100)
+                               strcpy(last_battery_str[idx], "charged");
+                                       
+//             else if (strncmp(charging_state, "Charged", 64) == 0 || strncmp(charging_state, "Full", 64) == 0) {
+//                             /* Below happens with the second battery on my X40,
+//                              * when the second one is empty and the first one
+//                              * being charged. */
+//                             if (remaining_capacity == 0)
+//                                     strcpy(last_battery_str[idx], "empty");
+//                             else
+//                                     strcpy(last_battery_str[idx], "charged");
+//             }
                /* unknown, probably full / AC */
-               else {
-                       if (acpi_last_full[idx] != 0
-                           && remaining_capacity != acpi_last_full[idx])
-                               snprintf(last_battery_str[idx], 64, "unknown %d%%",
-                                       (int) (((float)remaining_capacity / acpi_last_full[idx]) * 100));
-                       else
-                               strncpy(last_battery_str[idx], "AC", 64);
-               }
-       } else if (acpi_bat_fp[idx] != NULL) {
+//             else {
+//                     if (acpi_last_full[idx] != 0
+//                         && remaining_capacity != acpi_last_full[idx])
+//                             snprintf(last_battery_str[idx], 64, "unknown %d%%",
+//                                     (int) (((float)remaining_capacity / acpi_last_full[idx]) * 100));
+//                     else
+//                             strncpy(last_battery_str[idx], "AC", 64);
+//             }
+       } else if (acpi_bat_fp[idx] != NULL) {//skipped on n900
                /* ACPI */
                int present_rate = -1;
                int remaining_capacity = -1;
@@ -1870,7 +1920,7 @@ void get_battery_stuff(char *buffer, unsigned int n, const char *bat, int item)
                }
                fclose(acpi_bat_fp[idx]);
                acpi_bat_fp[idx] = NULL;
-       } else {
+       } else {//also skipped on n900
                /* APM */
                if (apm_bat_fp[idx] == NULL) {
                        apm_bat_fp[idx] = open_file(APM_PATH, &rep2);
@@ -1912,6 +1962,12 @@ void set_return_value(char *buffer, unsigned int n, int item, int idx)
                case BATTERY_TIME:
                        snprintf(buffer, n, "%s", last_battery_time_str[idx]);
                        break;
+               case BATTERY_VOLTS:
+                       snprintf(buffer, n, "%i", last_battery_volts[idx]); // voltage
+                       break;
+               case BATTERY_TEMP:
+                       snprintf(buffer, n, "%i", last_battery_temp[idx]); // temperature
+                       break;
                default:
                        break;
        }
@@ -1962,7 +2018,7 @@ int get_battery_perct(const char *bat)
        }
        last_battery_perct_time[idx] = current_update_time;
 
-       /* Only check for SYSFS or ACPI */
+       /* Only check for SYSFS */
 
        if (sysfs_bat_fp[idx] == NULL && acpi_bat_fp[idx] == NULL && apm_bat_fp[idx] == NULL) {
                sysfs_bat_fp[idx] = open_file(sysfs_path, &rep);
@@ -1979,68 +2035,72 @@ int get_battery_perct(const char *bat)
                        char buf[256];
                        if (fgets(buf, 256, sysfs_bat_fp[idx]) == NULL)
                                break;
-
-                       if (strncmp(buf, "POWER_SUPPLY_CHARGE_NOW=", 24) == 0) {
-                               sscanf(buf, "POWER_SUPPLY_CHARGE_NOW=%d", &remaining_capacity);
-                       } else if (strncmp(buf, "POWER_SUPPLY_CHARGE_FULL=",25) == 0) {
-                               sscanf(buf, "POWER_SUPPLY_CHARGE_FULL=%d", &acpi_design_capacity[idx]);
-                       } else if (strncmp(buf, "POWER_SUPPLY_ENERGY_NOW=", 24) == 0) {
-                               sscanf(buf, "POWER_SUPPLY_ENERGY_NOW=%d", &remaining_capacity);
-                       } else if (strncmp(buf, "POWER_SUPPLY_ENERGY_FULL=",25) == 0) {
-                               sscanf(buf, "POWER_SUPPLY_ENERGY_FULL=%d", &acpi_design_capacity[idx]);
+                       if (strncmp(buf, "POWER_SUPPLY_CAPACITY=", 22) == 0) {
+                               sscanf(buf, "POWER_SUPPLY_CAPACITY=%d", &remaining_capacity);
+                               
+//                     if (strncmp(buf, "POWER_SUPPLY_CHARGE_NOW=", 24) == 0) {
+//                             sscanf(buf, "POWER_SUPPLY_CHARGE_NOW=%d", &remaining_capacity);
+//                     } else if (strncmp(buf, "POWER_SUPPLY_CHARGE_FULL=",25) == 0) {
+//                             sscanf(buf, "POWER_SUPPLY_CHARGE_FULL=%d", &acpi_design_capacity[idx]);
+//                     } else if (strncmp(buf, "POWER_SUPPLY_ENERGY_NOW=", 24) == 0) {
+//                             sscanf(buf, "POWER_SUPPLY_ENERGY_NOW=%d", &remaining_capacity);
+//                     } else if (strncmp(buf, "POWER_SUPPLY_ENERGY_FULL=",25) == 0) {
+//                             sscanf(buf, "POWER_SUPPLY_ENERGY_FULL=%d", &acpi_design_capacity[idx]);
+//                     }
                        }
                }
-
                fclose(sysfs_bat_fp[idx]);
                sysfs_bat_fp[idx] = NULL;
 
-       } else if (acpi_bat_fp[idx] != NULL) {
-               /* ACPI */
-               /* read last full capacity if it's zero */
-               if (acpi_design_capacity[idx] == 0) {
-                       static int rep2;
-                       char path[128];
-                       FILE *fp;
-
-                       snprintf(path, 127, ACPI_BATTERY_BASE_PATH "/%s/info", bat);
-                       fp = open_file(path, &rep2);
-                       if (fp != NULL) {
-                               while (!feof(fp)) {
-                                       char b[256];
-
-                                       if (fgets(b, 256, fp) == NULL) {
-                                               break;
-                                       }
-                                       if (sscanf(b, "last full capacity: %d",
-                                                               &acpi_design_capacity[idx]) != 0) {
-                                               break;
-                                       }
-                               }
-                               fclose(fp);
-                       }
-               }
-
-               fseek(acpi_bat_fp[idx], 0, SEEK_SET);
-
-               while (!feof(acpi_bat_fp[idx])) {
-                       char buf[256];
-
-                       if (fgets(buf, 256, acpi_bat_fp[idx]) == NULL) {
-                               break;
-                       }
-
-                       if (buf[0] == 'r') {
-                               sscanf(buf, "remaining capacity: %d", &remaining_capacity);
-                       }
-               }
-       }
+       } 
+//     else if (acpi_bat_fp[idx] != NULL) {
+//             /* ACPI */
+//             /* read last full capacity if it's zero */
+//             if (acpi_design_capacity[idx] == 0) {
+//                     static int rep2;
+//                     char path[128];
+//                     FILE *fp;
+//
+//                     snprintf(path, 127, ACPI_BATTERY_BASE_PATH "/%s/info", bat);
+//                     fp = open_file(path, &rep2);
+//                     if (fp != NULL) {
+//                             while (!feof(fp)) {
+//                                     char b[256];
+//
+//                                     if (fgets(b, 256, fp) == NULL) {
+//                                             break;
+//                                     }
+//                                     if (sscanf(b, "last full capacity: %d",
+//                                                             &acpi_design_capacity[idx]) != 0) {
+//                                             break;
+//                                     }
+//                             }
+//                             fclose(fp);
+//                     }
+//             }
+//
+//             fseek(acpi_bat_fp[idx], 0, SEEK_SET);
+//
+//             while (!feof(acpi_bat_fp[idx])) {
+//                     char buf[256];
+//
+//                     if (fgets(buf, 256, acpi_bat_fp[idx]) == NULL) {
+//                             break;
+//                     }
+//
+//                     if (buf[0] == 'r') {
+//                             sscanf(buf, "remaining capacity: %d", &remaining_capacity);
+//                     }
+//             }
+//     }
        if (remaining_capacity < 0) {
                return 0;
        }
        /* compute the battery percentage */
-       last_battery_perct[idx] =
-               (int) (((float) remaining_capacity / acpi_design_capacity[idx]) * 100);
-       if (last_battery_perct[idx] > 100) last_battery_perct[idx] = 100;
+       last_battery_perct[idx] = 
+               remaining_capacity;
+               //(int) (((float) remaining_capacity / acpi_design_capacity[idx]) * 100);
+       //if (last_battery_perct[idx] > 100) last_battery_perct[idx] = 100;
        return last_battery_perct[idx];
 }
 
@@ -2182,7 +2242,7 @@ void get_powerbook_batt_info(char *buffer, size_t n, int i)
        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
@@ -2190,6 +2250,7 @@ void update_top(void)
 #endif
                 );
        info.first_process = get_first_process();
+       return 0;
 }
 
 #define ENTROPY_AVAIL_PATH "/proc/sys/kernel/random/entropy_avail"
@@ -2246,7 +2307,50 @@ const char *get_disk_protect_queue(const char *disk)
        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;
@@ -2256,14 +2360,13 @@ void update_diskio(void)
        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
@@ -2277,14 +2380,10 @@ void update_diskio(void)
                 * 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) */
-                       if (devbuf) {
-                               len_devbuf = strlen(devbuf);
-                               if ((len_devbuf > 0) && !isdigit(devbuf[len_devbuf-1])) {
-                                       total_reads += reads;
-                                       total_writes += writes;
-                               }
+                       /* check needed for kernel >= 2.6.31, see sf #2942117 */
+                       if (is_disk(devbuf)) {
+                               total_reads += reads;
+                               total_writes += writes;
                        }
                } else {
                        col_count = sscanf(buf, "%u %u %s %*u %u %*u %u",
@@ -2302,4 +2401,5 @@ void update_diskio(void)
        }
        update_diskio_values(&stats, total_reads, total_writes);
        fclose(fp);
+       return 0;
 }