1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-16 01:57:09 +00:00

upspeed/f downspeed/f: Be able to use ${gw_iface} as argument (#571)

This commit is contained in:
su8 2018-08-06 21:48:07 +00:00 committed by Brenden Matthews
parent fd4ab7fc07
commit bd98860640
4 changed files with 24 additions and 4 deletions

View File

@ -781,10 +781,12 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
END OBJ(conky_build_date, nullptr) obj_be_plain_text(obj, BUILD_DATE); END OBJ(conky_build_date, nullptr) obj_be_plain_text(obj, BUILD_DATE);
END OBJ(conky_build_arch, nullptr) obj_be_plain_text(obj, BUILD_ARCH); END OBJ(conky_build_arch, nullptr) obj_be_plain_text(obj, BUILD_ARCH);
END OBJ(downspeed, &update_net_stats) END OBJ(downspeed, &update_net_stats)
parse_net_stat_arg(obj, arg, free_at_crash); update_gateway_info();
parse_net_stat_arg(obj, arg, free_at_crash);
obj->callbacks.print = &print_downspeed; obj->callbacks.print = &print_downspeed;
END OBJ(downspeedf, &update_net_stats) END OBJ(downspeedf, &update_net_stats)
parse_net_stat_arg(obj, arg, free_at_crash); update_gateway_info();
parse_net_stat_arg(obj, arg, free_at_crash);
obj->callbacks.print = &print_downspeedf; obj->callbacks.print = &print_downspeedf;
#ifdef BUILD_X11 #ifdef BUILD_X11
END OBJ(downspeedgraph, &update_net_stats) END OBJ(downspeedgraph, &update_net_stats)
@ -1405,10 +1407,12 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
END OBJ(alignc, nullptr) obj->data.l = arg != nullptr ? atoi(arg) : 0; END OBJ(alignc, nullptr) obj->data.l = arg != nullptr ? atoi(arg) : 0;
obj->callbacks.print = &new_alignc; obj->callbacks.print = &new_alignc;
END OBJ(upspeed, &update_net_stats) END OBJ(upspeed, &update_net_stats)
parse_net_stat_arg(obj, arg, free_at_crash); update_gateway_info();
parse_net_stat_arg(obj, arg, free_at_crash);
obj->callbacks.print = &print_upspeed; obj->callbacks.print = &print_upspeed;
END OBJ(upspeedf, &update_net_stats) END OBJ(upspeedf, &update_net_stats)
parse_net_stat_arg(obj, arg, free_at_crash); update_gateway_info();
parse_net_stat_arg(obj, arg, free_at_crash);
obj->callbacks.print = &print_upspeedf; obj->callbacks.print = &print_upspeedf;
#ifdef BUILD_X11 #ifdef BUILD_X11
END OBJ(upspeedgraph, &update_net_stats) END OBJ(upspeedgraph, &update_net_stats)

View File

@ -94,6 +94,8 @@ struct sysfs {
float factor, offset; float factor, offset;
}; };
char e_iface[50];
#define SHORTSTAT_TEMPL "%*s %llu %llu %llu" #define SHORTSTAT_TEMPL "%*s %llu %llu %llu"
#define LONGSTAT_TEMPL "%*s %llu %llu %llu " #define LONGSTAT_TEMPL "%*s %llu %llu %llu "
@ -314,6 +316,7 @@ int update_gateway_info(void) {
} }
if (!(dest || mask) && ((flags & RTF_GATEWAY) || !gate)) { if (!(dest || mask) && ((flags & RTF_GATEWAY) || !gate)) {
gw_info.count++; gw_info.count++;
snprintf(e_iface, 49, "%s", iface);
SAVE_SET_STRING(gw_info.iface, iface) SAVE_SET_STRING(gw_info.iface, iface)
ina.s_addr = gate; ina.s_addr = gate;
SAVE_SET_STRING(gw_info.ip, inet_ntoa(ina)) SAVE_SET_STRING(gw_info.ip, inet_ntoa(ina))

View File

@ -55,4 +55,6 @@ int update_stat(void);
void print_distribution(struct text_object *, char *, int); void print_distribution(struct text_object *, char *, int);
void determine_longstat_file(void); void determine_longstat_file(void);
extern char e_iface[50];
#endif /* _LINUX_H */ #endif /* _LINUX_H */

View File

@ -48,6 +48,12 @@
#define SOCK_CLOEXEC O_CLOEXEC #define SOCK_CLOEXEC O_CLOEXEC
#endif /* SOCK_CLOEXEC */ #endif /* SOCK_CLOEXEC */
#if defined(__linux__)
#include "linux.h"
#else
char e_iface[50] = "empty";
#endif /* __linux__ */
/* network interface stuff */ /* network interface stuff */
enum if_up_strictness_ { IFUP_UP, IFUP_LINK, IFUP_ADDR }; enum if_up_strictness_ { IFUP_UP, IFUP_LINK, IFUP_ADDR };
@ -117,6 +123,11 @@ void parse_net_stat_arg(struct text_object *obj, const char *arg,
if (arg == nullptr) { arg = DEFAULTNETDEV; } if (arg == nullptr) { arg = DEFAULTNETDEV; }
if (0 == (strcmp("$gw_iface", arg)) ||
0 == (strcmp("${gw_iface}", arg))) {
arg = e_iface;
}
while (sscanf(arg + i, " %20s", nextarg) == 1) { while (sscanf(arg + i, " %20s", nextarg) == 1) {
if (strcmp(nextarg, "-n") == 0 || strcmp(nextarg, "--netmask") == 0) { if (strcmp(nextarg, "-n") == 0 || strcmp(nextarg, "--netmask") == 0) {
shownetmask = true; shownetmask = true;