From 13188c8b110a8cc94f43bc6c5a37b073e3b78430 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Wed, 5 May 2010 18:57:27 +0200 Subject: [PATCH] Bugfix: memory and thread-deleting problems This patch is the C version of a32d9e41a440a043e19d20e3b91a45f626297472 (from the master branch). --- src/apcupsd.c | 4 ++-- src/apcupsd.h | 2 +- src/common.c | 22 ++++++++++++++----- src/common.h | 24 ++++++++++----------- src/conky.c | 14 ++++++++---- src/conky.h | 2 +- src/diskio.h | 2 +- src/entropy.c | 3 ++- src/entropy.h | 2 +- src/fs.c | 5 +++-- src/fs.h | 2 +- src/hddtemp.c | 9 ++++---- src/hddtemp.h | 2 +- src/i8k.c | 10 +++++++-- src/i8k.h | 2 +- src/ibm.c | 5 +++-- src/ibm.h | 2 +- src/linux.c | 61 +++++++++++++++++++++++++++++++---------------------- src/linux.h | 4 ++-- src/logging.h | 4 ++++ src/moc.c | 3 ++- src/moc.h | 2 +- src/mpd.c | 7 +++--- src/mpd.h | 2 +- src/net_stat.c | 5 +++-- src/net_stat.h | 2 +- src/tcp-portmon.c | 3 ++- src/tcp-portmon.h | 2 +- src/users.c | 3 ++- src/x11.c | 5 +++-- 30 files changed, 132 insertions(+), 83 deletions(-) diff --git a/src/apcupsd.c b/src/apcupsd.c index 7bec156..2e23bf7 100644 --- a/src/apcupsd.c +++ b/src/apcupsd.c @@ -154,7 +154,7 @@ static int fill_items(int sock, PAPCUPSD_S apc) { // // Conky update function for apcupsd data // -void update_apcupsd(void) { +int update_apcupsd(void) { int i; APCUPSD_S apc; @@ -225,5 +225,5 @@ void update_apcupsd(void) { // "atomically" copy the data into working set // memcpy(info.apcupsd.items, apc.items, sizeof(info.apcupsd.items)); - return; + return 0; } diff --git a/src/apcupsd.h b/src/apcupsd.h index d452833..4097b5d 100644 --- a/src/apcupsd.h +++ b/src/apcupsd.h @@ -49,6 +49,6 @@ typedef struct apcupsd_s { } APCUPSD_S, *PAPCUPSD_S; /* Service routine for the conky main thread */ -void update_apcupsd(void); +int update_apcupsd(void); #endif /*APCUPSD_H_*/ diff --git a/src/common.c b/src/common.c index 4a8d78a..b9b093b 100644 --- a/src/common.c +++ b/src/common.c @@ -84,9 +84,10 @@ char *strndup(const char *s, size_t n) } #endif /* HAVE_STRNDUP */ -void update_uname(void) +int update_uname(void) { uname(&info.uname_s); + return 0; } double get_time(void) @@ -268,7 +269,7 @@ void format_seconds_short(char *buf, unsigned int n, long seconds) * Populated while initialising text objects in construct_text_object(). */ static struct update_cb { struct update_cb *next; - void (*func)(void); + int (*func)(void); pthread_t thread; sem_t start_wait, end_wait; @@ -286,7 +287,7 @@ static int threading_started = 0; /* Register an update callback. Don't allow duplicates, to minimise side * effects and overhead. */ -void add_update_callback(void (*func)(void)) +void add_update_callback(int (*func)(void)) { struct update_cb *uc = &update_cb_head; @@ -376,7 +377,12 @@ static void *run_update_callback(void *data) while (1) { if (sem_wait(&ucb->start_wait)) pthread_exit(NULL); if (ucb->running == 0) pthread_exit(NULL); - (*ucb->func)(); + if((*ucb->func)()) { + ucb->next = ucb; //this is normally not be possible, so we use it to show that there was a critical error + sem_post(&ucb->end_wait); + sem_post(&ucb->end_wait); + pthread_exit(NULL); + } if (sem_post(&ucb->end_wait)) pthread_exit(NULL); } } @@ -411,8 +417,14 @@ void update_stuff(void) } /* need to synchronise here, otherwise locking is needed (as data * would be printed with some update callbacks still running) */ - for (uc = update_cb_head.next; uc; uc = uc->next) + for (uc = update_cb_head.next; uc; uc = uc->next) { sem_wait(&uc->end_wait); + if(uc == uc->next) { + pthread_join(uc->thread, NULL); + free(uc); + exit(EXIT_FAILURE); + } + } /* XXX: move the following into the update_meminfo() functions? */ if (no_buffers) { diff --git a/src/common.h b/src/common.h index f9f0393..ff3d5dd 100644 --- a/src/common.h +++ b/src/common.h @@ -11,7 +11,7 @@ #include #include "text_object.h" -void add_update_callback(void (*func)(void)); +void add_update_callback(int (*func)(void)); void free_update_callbacks(void); void start_update_threading(void); @@ -19,20 +19,20 @@ void start_update_threading(void); void strfold(char *start, int count); int check_mount(char *s); void prepare_update(void); -void update_uptime(void); -void update_meminfo(void); -void update_net_stats(void); -void update_cpu_usage(void); -void update_total_processes(void); -void update_uname(void); -void update_threads(void); -void update_running_processes(void); +int update_uptime(void); +int update_meminfo(void); +int update_net_stats(void); +int update_cpu_usage(void); +int update_total_processes(void); +int update_uname(void); +int update_threads(void); +int update_running_processes(void); void update_stuff(void); char get_freq(char *, size_t, const char *, int, unsigned int); void print_voltage_mv(struct text_object *, char *, int); void print_voltage_v(struct text_object *, char *, int); -void update_load_average(void); -void update_top(void); +int update_load_average(void); +int update_top(void); void free_all_processes(void); struct process *get_first_process(void); void get_cpu_count(void); @@ -50,7 +50,7 @@ void format_seconds(char *buf, unsigned int n, long t); void format_seconds_short(char *buf, unsigned int n, long t); #ifdef X11 -void update_x11info(void); +int update_x11info(void); #endif int round_to_int_temp(float); diff --git a/src/conky.c b/src/conky.c index 4468848..ad129c0 100644 --- a/src/conky.c +++ b/src/conky.c @@ -509,6 +509,7 @@ static inline void for_each_line(char *b, int f(char *, int)) char *ps, *pe; int special_index = 0; /* specials index */ + if(! b) return; for (ps = b, pe = b; *pe; pe++) { if (*pe == '\n') { *pe = '\0'; @@ -762,6 +763,8 @@ void generate_text_internal(char *p, int p_max_size, buff_in[0] = 0; #endif /* HAVE_ICONV */ + if(! p) return; + p[0] = 0; obj = root.next; while (obj && p_max_size > 0) { @@ -4024,12 +4027,9 @@ void clean_up_x11() { } #endif -void clean_up(void *memtofree1, void* memtofree2) -{ +void clean_up_without_threads(void *memtofree1, void* memtofree2) { int i; - free_update_callbacks(); - #ifdef NCURSES if(output_methods & TO_NCURSES) { endwin(); @@ -4125,6 +4125,12 @@ void clean_up(void *memtofree1, void* memtofree2) } } +void clean_up(void *memtofree1, void* memtofree2) +{ + free_update_callbacks(); + clean_up_without_threads(memtofree1, memtofree2); +} + static int string_to_bool(const char *s) { if (!s) { diff --git a/src/conky.h b/src/conky.h index 9a6b80d..84f64c0 100644 --- a/src/conky.h +++ b/src/conky.h @@ -308,7 +308,7 @@ extern int cpu_separate; extern struct information info; /* defined in users.c */ -void update_users(void); +int update_users(void); void update_user_time(char *tty); /* defined in conky.c */ diff --git a/src/diskio.h b/src/diskio.h index c762ac9..8168f8a 100644 --- a/src/diskio.h +++ b/src/diskio.h @@ -47,7 +47,7 @@ struct diskio_stat { extern struct diskio_stat stats; struct diskio_stat *prepare_diskio_stat(const char *); -void update_diskio(void); +int update_diskio(void); void clear_diskio_stats(void); void update_diskio_values(struct diskio_stat *, unsigned int, unsigned int); diff --git a/src/entropy.c b/src/entropy.c index 732cfb7..597ea0a 100644 --- a/src/entropy.c +++ b/src/entropy.c @@ -49,10 +49,11 @@ static struct { .poolsize = 0, }; -void update_entropy(void) +int update_entropy(void) { get_entropy_avail(&entropy.avail); get_entropy_poolsize(&entropy.poolsize); + return 0; } void print_entropy_avail(struct text_object *obj, char *p, int p_max_size) diff --git a/src/entropy.h b/src/entropy.h index 76ee687..52418c3 100644 --- a/src/entropy.h +++ b/src/entropy.h @@ -31,7 +31,7 @@ #ifndef _ENTROPY_H #define _ENTROPY_H -void update_entropy(void); +int update_entropy(void); void print_entropy_avail(struct text_object *, char *, int); void print_entropy_perc(struct text_object *, char *, int); diff --git a/src/fs.c b/src/fs.c index 0981919..54617c6 100644 --- a/src/fs.c +++ b/src/fs.c @@ -65,13 +65,13 @@ static void update_fs_stat(struct fs_stat *fs); void get_fs_type(const char *path, char *result); -void update_fs_stats(void) +int update_fs_stats(void) { unsigned i; static double last_fs_update = 0.0; if (current_update_time - last_fs_update < 13) - return; + return 0; for (i = 0; i < MAX_FS_STATS; ++i) { if (fs_stats[i].set) { @@ -79,6 +79,7 @@ void update_fs_stats(void) } } last_fs_update = current_update_time; + return 0; } void clear_fs_stats(void) diff --git a/src/fs.h b/src/fs.h index 0c93c8e..097086a 100644 --- a/src/fs.h +++ b/src/fs.h @@ -28,7 +28,7 @@ void print_fs_size(struct text_object *, char *, int); void print_fs_used(struct text_object *, char *, int); void print_fs_type(struct text_object *, char *, int); -void update_fs_stats(void); +int update_fs_stats(void); struct fs_stat *prepare_fs_stat(const char *path); void clear_fs_stats(void); diff --git a/src/hddtemp.c b/src/hddtemp.c index 5f7edec..b1ba81e 100644 --- a/src/hddtemp.c +++ b/src/hddtemp.c @@ -206,29 +206,30 @@ out_fail: return 1; } -void update_hddtemp(void) { +int update_hddtemp(void) { char *data, *dev, unit, *saveptr; short val; static double last_hddtemp_update = 0.0; /* limit tcp connection overhead */ if (current_update_time - last_hddtemp_update < 5) - return; + return 0; last_hddtemp_update = current_update_time; free_hddtemp_info(); if (!(data = fetch_hddtemp_output())) - return; + return 0; if (read_hdd_val(data, &dev, &val, &unit, &saveptr)) { free(data); - return; + return 0; } do { add_hddtemp_info(dev, val, unit); } while (!read_hdd_val(NULL, &dev, &val, &unit, &saveptr)); free(data); + return 0; } void free_hddtemp(void) diff --git a/src/hddtemp.h b/src/hddtemp.h index 1642e41..ac40171 100644 --- a/src/hddtemp.h +++ b/src/hddtemp.h @@ -5,7 +5,7 @@ void set_hddtemp_host(const char *); void set_hddtemp_port(const char *); -void update_hddtemp(void); +int update_hddtemp(void); void free_hddtemp(void); int get_hddtemp_info(const char *, short *, char *); diff --git a/src/i8k.c b/src/i8k.c index 822c0c7..c21d4b1 100644 --- a/src/i8k.c +++ b/src/i8k.c @@ -53,7 +53,7 @@ struct { #define PROC_I8K "/proc/i8k" #define I8K_DELIM " " static char *i8k_procbuf = NULL; -void update_i8k(void) +int update_i8k(void) { FILE *fp; @@ -61,8 +61,13 @@ void update_i8k(void) 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 " + free(i8k_procbuf); + i8k_procbuf = NULL; + NORM_ERR("/proc/i8k doesn't exist! use insmod to make sure the kernel " "driver is loaded..."); + clean_up_without_threads(NULL, NULL); + free(current_mail_spool); + return 1; } memset(&i8k_procbuf[0], 0, 128); @@ -82,6 +87,7 @@ void update_i8k(void) i8k.right_fan_rpm = strtok(NULL, I8K_DELIM); i8k.ac_status = strtok(NULL, I8K_DELIM); i8k.buttons_status = strtok(NULL, I8K_DELIM); + return 0; } static const char *fan_status_to_string(int status) diff --git a/src/i8k.h b/src/i8k.h index a0fde0a..fe71d49 100644 --- a/src/i8k.h +++ b/src/i8k.h @@ -32,7 +32,7 @@ #ifndef _I8K_H #define _I8K_H -void update_i8k(void); +int update_i8k(void); void print_i8k_left_fan_status(struct text_object *, char *, int); void print_i8k_cpu_temp(struct text_object *, char *, int); void print_i8k_right_fan_status(struct text_object *, char *, int); diff --git a/src/ibm.c b/src/ibm.c index 47b0d33..560d2b0 100644 --- a/src/ibm.c +++ b/src/ibm.c @@ -73,7 +73,7 @@ speed: 2944 commands: enable, disable * Peter Tarjan (ptarjan@citromail.hu) */ -void get_ibm_acpi_fan(struct text_object *obj, char *p, int p_max_size) +int get_ibm_acpi_fan(struct text_object *obj, char *p, int p_max_size) { FILE *fp; unsigned int speed = 0; @@ -82,7 +82,7 @@ void get_ibm_acpi_fan(struct text_object *obj, char *p, int p_max_size) (void)obj; if (!p || p_max_size <= 0) { - return; + return 0; } snprintf(fan, 127, "%s/fan", IBM_ACPI_DIR); @@ -106,6 +106,7 @@ void get_ibm_acpi_fan(struct text_object *obj, char *p, int p_max_size) fclose(fp); snprintf(p, p_max_size, "%d", speed); + return 0; } /* get the measured temperatures from the temperature sensors diff --git a/src/ibm.h b/src/ibm.h index eed3595..64cec6a 100644 --- a/src/ibm.h +++ b/src/ibm.h @@ -6,7 +6,7 @@ #include void get_ibm_acpi_fan(struct text_object *, char *, int); -void get_ibm_acpi_temps(void); +int get_ibm_acpi_temps(void); void get_ibm_acpi_volume(struct text_object *, char *, int); void get_ibm_acpi_brightness(struct text_object *, char *, int); diff --git a/src/linux.c b/src/linux.c index 3185217..ce5f733 100644 --- a/src/linux.c +++ b/src/linux.c @@ -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; } diff --git a/src/linux.h b/src/linux.h index c6f651f..ee79a5c 100644 --- a/src/linux.h +++ b/src/linux.h @@ -10,7 +10,7 @@ const char *get_disk_protect_queue(const char *); char *get_ioscheduler(char *); int get_laptop_mode(void); -void update_gateway_info(void); +int update_gateway_info(void); void free_gateway_info(void); int gateway_exists(void); void print_gateway_iface(char *, int); @@ -28,6 +28,6 @@ void free_sysfs_sensor(struct text_object *); int get_entropy_avail(unsigned int *); int get_entropy_poolsize(unsigned int *); -void update_stat(void); +int update_stat(void); #endif /* _LINUX_H */ diff --git a/src/logging.h b/src/logging.h index 8bfa63f..486e792 100644 --- a/src/logging.h +++ b/src/logging.h @@ -30,6 +30,7 @@ #include "mail.h" void clean_up(void *memtofree1, void* memtofree2); +void clean_up_without_threads(void *memtofree1, void* memtofree2); #ifndef _LOGGING_H #define _LOGGING_H @@ -44,6 +45,9 @@ void clean_up(void *memtofree1, void* memtofree2); #define CRIT_ERR(memtofree1, memtofree2, ...) \ { NORM_ERR(__VA_ARGS__); clean_up(memtofree1, memtofree2); free(current_mail_spool); exit(EXIT_FAILURE); } +#define THREAD_CRIT_ERR(memtofree1, memtofree2, ...) \ + { NORM_ERR(__VA_ARGS__); clean_up_without_threads(memtofree1, memtofree2); free(current_mail_spool); return; } + /* debugging output */ extern int global_debug_level; #define __DBGP(level, ...) \ diff --git a/src/moc.c b/src/moc.c index eca3329..7988185 100644 --- a/src/moc.c +++ b/src/moc.c @@ -133,7 +133,8 @@ static int run_moc_thread(double interval) return 0; } -void update_moc(void) +int update_moc(void) { run_moc_thread(info.music_player_interval * 100000); + return 0; } diff --git a/src/moc.h b/src/moc.h index b1d9cc5..324c290 100644 --- a/src/moc.h +++ b/src/moc.h @@ -40,7 +40,7 @@ struct moc_s { }; extern struct moc_s moc; -void update_moc(void); +int update_moc(void); void free_moc(void); #endif /* MOC_H_ */ diff --git a/src/mpd.c b/src/mpd.c index a4ca152..ec929b7 100644 --- a/src/mpd.c +++ b/src/mpd.c @@ -113,23 +113,24 @@ void free_mpd(void) static void *update_mpd_thread(void *) __attribute__((noreturn)); -void update_mpd(void) +int update_mpd(void) { int interval; static timed_thread *thread = NULL; if (thread) - return; + return 0; interval = info.music_player_interval * 1000000; thread = timed_thread_create(&update_mpd_thread, &thread, interval); if (!thread) { NORM_ERR("Failed to create MPD timed thread"); - return; + return 0; } timed_thread_register(thread, &thread); if (timed_thread_run(thread)) NORM_ERR("Failed to run MPD timed thread"); + return 0; } /* stringMAXdup dups at most text_buffer_size bytes */ diff --git a/src/mpd.h b/src/mpd.h index 94d0d29..d011fce 100644 --- a/src/mpd.h +++ b/src/mpd.h @@ -31,7 +31,7 @@ int mpd_set_port(const char *); void init_mpd(void); struct mpd_s *mpd_get_info(void); void free_mpd(void); -void update_mpd(void); +int update_mpd(void); void print_mpd_elapsed(struct text_object *, char *, int); void print_mpd_length(struct text_object *, char *, int); diff --git a/src/net_stat.c b/src/net_stat.c index 0682fee..c8c7640 100644 --- a/src/net_stat.c +++ b/src/net_stat.c @@ -400,7 +400,7 @@ void free_dns_data(void) memset(&dns_data, 0, sizeof(dns_data)); } -void update_dns_data(void) +int update_dns_data(void) { FILE *fp; char line[256]; @@ -416,7 +416,7 @@ void update_dns_data(void) free_dns_data(); if ((fp = fopen("/etc/resolv.conf", "r")) == NULL) - return; + return 0; while(!feof(fp)) { if (fgets(line, 255, fp) == NULL) { break; @@ -429,6 +429,7 @@ void update_dns_data(void) } } fclose(fp); + return 0; } void parse_nameserver_arg(struct text_object *obj, const char *arg) diff --git a/src/net_stat.h b/src/net_stat.h index 141e840..463e7db 100644 --- a/src/net_stat.h +++ b/src/net_stat.h @@ -94,7 +94,7 @@ int interface_up(struct text_object *); void free_if_up(struct text_object *); void free_dns_data(void); -void update_dns_data(void); +int update_dns_data(void); void parse_nameserver_arg(struct text_object *, const char *); void print_nameserver(struct text_object *, char *, int); diff --git a/src/tcp-portmon.c b/src/tcp-portmon.c index 97915b6..245eb17 100644 --- a/src/tcp-portmon.c +++ b/src/tcp-portmon.c @@ -139,9 +139,10 @@ int tcp_portmon_action(struct text_object *obj, char *p, int p_max_size) return 0; } -void tcp_portmon_update(void) +int tcp_portmon_update(void) { update_tcp_port_monitor_collection(pmc); + return 0; } int tcp_portmon_clear(void) diff --git a/src/tcp-portmon.h b/src/tcp-portmon.h index f8af627..26ee428 100644 --- a/src/tcp-portmon.h +++ b/src/tcp-portmon.h @@ -40,7 +40,7 @@ struct text_object; int tcp_portmon_init(struct text_object *, const char *); int tcp_portmon_action(struct text_object *, char *, int); -void tcp_portmon_update(void); +int tcp_portmon_update(void); int tcp_portmon_clear(void); int tcp_portmon_set_max_connections(int); void tcp_portmon_free(struct text_object *); diff --git a/src/users.c b/src/users.c index cd3c01e..5ba7959 100644 --- a/src/users.c +++ b/src/users.c @@ -157,7 +157,7 @@ void update_user_time(char *tty) } } -void update_users(void) +int update_users(void) { struct information *current_info = &info; char temp[BUFLEN] = ""; @@ -221,4 +221,5 @@ void update_users(void) current_info->users.times = malloc(text_buffer_size); strncpy(current_info->users.times, "broken", text_buffer_size); } + return 0; } diff --git a/src/x11.c b/src/x11.c index a1ce8c0..264ddd2 100644 --- a/src/x11.c +++ b/src/x11.c @@ -775,13 +775,14 @@ void get_x11_desktop_info(Display *current_display, Atom atom) } } -void update_x11info(void) +int update_x11info(void) { struct information *current_info = &info; if (x_initialised != YES) - return; + return 0; current_info->x11.monitor.number = XScreenCount(display); current_info->x11.monitor.current = XDefaultScreen(display); + return 0; } #ifdef OWN_WINDOW -- 1.7.9.5