diff --git a/src/conky.c b/src/conky.c index b0cb0d4c..735805e8 100644 --- a/src/conky.c +++ b/src/conky.c @@ -1106,8 +1106,7 @@ void generate_text_internal(char *p, int p_max_size, #endif /* __linux__ */ #if (defined(__FreeBSD__) || defined(__linux__)) OBJ(if_up) { - if ((obj->data.ifblock.s) - && (!interface_up(obj->data.ifblock.s))) { + if (!interface_up(obj)) { DO_JUMP; } } diff --git a/src/core.c b/src/core.c index 697fc067..c823f76b 100644 --- a/src/core.c +++ b/src/core.c @@ -321,7 +321,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long #endif /* __linux__ */ #if (defined(__FreeBSD__) || defined(__linux__)) END OBJ_IF_ARG(if_up, 0, "if_up needs an argument") - obj->data.ifblock.s = strndup(arg, text_buffer_size); + parse_if_up_arg(obj, arg); #endif #if defined(__OpenBSD__) END OBJ_ARG(obsd_sensors_temp, 0, "obsd_sensors_temp: needs an argument") @@ -1415,8 +1415,7 @@ void free_text_objects(struct text_object *root, int internal) #endif #if (defined(__FreeBSD__) || defined(__linux__)) case OBJ_if_up: - free(data.ifblock.s); - free(data.ifblock.str); + free_if_up(obj); break; #endif #ifdef XMMS2 diff --git a/src/net_stat.c b/src/net_stat.c index 64c46f6b..288b4e10 100644 --- a/src/net_stat.c +++ b/src/net_stat.c @@ -333,11 +333,28 @@ void clear_net_stats(void) memset(netstats, 0, sizeof(netstats)); } +void parse_if_up_arg(struct text_object *obj, const char *arg) +{ + obj->data.opaque = strndup(arg, text_buffer_size); +} + +void free_if_up(struct text_object *obj) +{ + if (obj->data.opaque) { + free(obj->data.opaque); + obj->data.opaque = NULL; + } +} + /* We should check if this is ok with OpenBSD and NetBSD as well. */ -int interface_up(const char *dev) +int interface_up(struct text_object *obj) { int fd; struct ifreq ifr; + char *dev = obj->data.opaque; + + if (!dev) + return 0; if ((fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { CRIT_ERR(NULL, NULL, "could not create sockfd"); diff --git a/src/net_stat.h b/src/net_stat.h index af3ba977..923e2189 100644 --- a/src/net_stat.h +++ b/src/net_stat.h @@ -88,7 +88,10 @@ void print_wireless_link_bar(struct text_object *, char *, int); #endif /* __linux__ */ void clear_net_stats(void); -int interface_up(const char *); + +void parse_if_up_arg(struct text_object *, const char *); +int interface_up(struct text_object *); +void free_if_up(struct text_object *); void free_dns_data(void); void update_dns_data(void);