1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-05 21:07:52 +00:00

if_up: convert to generic object payload

This commit is contained in:
Phil Sutter 2009-10-09 04:30:02 +02:00
parent 2112b1f0ee
commit 3a365bcd33
4 changed files with 25 additions and 7 deletions

View File

@ -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;
}
}

View File

@ -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

View File

@ -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");

View File

@ -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);