Skip to content

Commit

Permalink
upspeed/f downspeed/f: Be able to use ${gw_iface} as argument (#571)
Browse files Browse the repository at this point in the history
  • Loading branch information
su8 authored and lasers committed Aug 12, 2018
1 parent 5fb0b49 commit da9f85f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_arch, nullptr) obj_be_plain_text(obj, BUILD_ARCH);
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;
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;
#ifdef BUILD_X11
END OBJ(downspeedgraph, &update_net_stats)
Expand Down Expand Up @@ -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;
obj->callbacks.print = &new_alignc;
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;
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;
#ifdef BUILD_X11
END OBJ(upspeedgraph, &update_net_stats)
Expand Down
3 changes: 3 additions & 0 deletions src/linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ struct sysfs {
float factor, offset;
};

char e_iface[50];

#define SHORTSTAT_TEMPL "%*s %llu %llu %llu"
#define LONGSTAT_TEMPL "%*s %llu %llu %llu "

Expand Down Expand Up @@ -314,6 +316,7 @@ int update_gateway_info(void) {
}
if (!(dest || mask) && ((flags & RTF_GATEWAY) || !gate)) {
gw_info.count++;
snprintf(e_iface, 49, "%s", iface);
SAVE_SET_STRING(gw_info.iface, iface)
ina.s_addr = gate;
SAVE_SET_STRING(gw_info.ip, inet_ntoa(ina))
Expand Down
2 changes: 2 additions & 0 deletions src/linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ int update_stat(void);
void print_distribution(struct text_object *, char *, int);

void determine_longstat_file(void);

extern char e_iface[50];
#endif /* _LINUX_H */
11 changes: 11 additions & 0 deletions src/net_stat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
#define SOCK_CLOEXEC O_CLOEXEC
#endif /* SOCK_CLOEXEC */

#if defined(__linux__)
#include "linux.h"
#else
char e_iface[50] = "empty";
#endif /* __linux__ */

/* network interface stuff */

enum if_up_strictness_ { IFUP_UP, IFUP_LINK, IFUP_ADDR };
Expand Down Expand Up @@ -117,6 +123,11 @@ void parse_net_stat_arg(struct text_object *obj, const char *arg,

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) {
if (strcmp(nextarg, "-n") == 0 || strcmp(nextarg, "--netmask") == 0) {
shownetmask = true;
Expand Down

0 comments on commit da9f85f

Please sign in to comment.