Bugfix: memory and thread-deleting problems
[monky] / src / linux.c
index 3185217..ce5f733 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;
 }
 
 /***********************************************************/
@@ -2190,7 +2199,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
@@ -2198,6 +2207,7 @@ void update_top(void)
 #endif
                 );
        info.first_process = get_first_process();
+       return 0;
 }
 
 #define ENTROPY_AVAIL_PATH "/proc/sys/kernel/random/entropy_avail"
@@ -2297,7 +2307,7 @@ int is_disk(char *dev)
        return dev_cur->memoized;
 }
 
-void update_diskio(void)
+int update_diskio(void)
 {
        FILE *fp;
        static int rep = 0;
@@ -2313,7 +2323,7 @@ void update_diskio(void)
        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
@@ -2348,4 +2358,5 @@ void update_diskio(void)
        }
        update_diskio_values(&stats, total_reads, total_writes);
        fclose(fp);
+       return 0;
 }