Navigation Menu

Skip to content

Commit

Permalink
Use enum online_state more
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Randolf committed Jan 10, 2017
1 parent ff766a3 commit 97d9f12
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions main.c
Expand Up @@ -30,14 +30,14 @@ void state_change(enum online_state state_new, struct ping_intf* pi)
pi->state = state_new;

printlog(LOG_INFO, "Interface '%s' changed to %s", pi->name,
get_status_str(pi));
get_status_str(pi->state));

scripts_run(pi, state_new);
}

const char* get_status_str(struct ping_intf* pi)
const char* get_status_str(enum online_state state)
{
switch (pi->state) {
switch (state) {
case UNKNOWN: return "UNKNOWN";
case DOWN: return "DOWN";
case NO_ROUTE: return "NO_ROUTE";
Expand All @@ -48,13 +48,13 @@ const char* get_status_str(struct ping_intf* pi)
}
}

const char* get_global_status_str(void)
enum online_state get_global_status(void)
{
for (int i=0; i < MAX_NUM_INTERFACES && intf[i].name[0]; i++) {
if (intf[i].state == ONLINE)
return "ONLINE";
return ONLINE;
}
return "OFFLINE";
return OFFLINE;
}

int get_online_interface_names(const char** dest, int destLen)
Expand Down Expand Up @@ -165,7 +165,7 @@ int main(__attribute__((unused)) int argc, __attribute__((unused)) char** argv)
printf("\n");
for (int i=0; i < MAX_NUM_INTERFACES && intf[i].name[0]; i++) {
printf("%s:\t%-8s %3.0f%% (%d/%d on %s)\n", intf[i].name,
get_status_str(&intf[i]),
get_status_str(intf[i].state),
(float)intf[i].cnt_succ*100/intf[i].cnt_sent,
intf[i].cnt_succ, intf[i].cnt_sent, intf[i].device);
ping_stop(&intf[i]);
Expand Down
4 changes: 2 additions & 2 deletions main.h
Expand Up @@ -98,8 +98,8 @@ void scripts_finish(void);
// main.c
void notify_interface(const char* interface, const char* action);
struct ping_intf* get_interface(const char* interface);
const char* get_status_str(struct ping_intf* pi);
const char* get_global_status_str();
const char* get_status_str(enum online_state state);
enum online_state get_global_status();
int get_online_interface_names(const char** dest, int destLen);
int get_all_interface_names(const char** dest, int destLen);
void state_change(enum online_state state_new, struct ping_intf* pi);
Expand Down
2 changes: 1 addition & 1 deletion scripts.c
Expand Up @@ -47,7 +47,7 @@ static void task_scripts_run(struct runqueue *q, struct runqueue_task *t)
len = snprintf(cmd, sizeof(cmd),
"export INTERFACE=\"%s\"; export DEVICE=\"%s\"; export GLOBAL=\"%s\"; "
"for hook in /etc/pingcheck/%s.d/*; do [ -r \"$hook\" ] && sh $hook; done",
pi->name, pi->device, get_global_status_str(), state_str);
pi->name, pi->device, get_status_str(get_global_status()), state_str);

if (len <= 0 || (unsigned int)len >= sizeof(cmd)) { // error or truncated
printlog(LOG_ERR, "Run scripts commands truncated!");
Expand Down
4 changes: 2 additions & 2 deletions ubus.c
Expand Up @@ -238,7 +238,7 @@ static int server_status(struct ubus_context *ctx,
if (pi == NULL) {
return -1;
}
blobmsg_add_string(&b, "status", get_status_str(pi));
blobmsg_add_string(&b, "status", get_status_str(pi->state));
blobmsg_add_string(&b, "interface", pi->name);
blobmsg_add_string(&b, "device", pi->device);
blobmsg_add_u32(&b, "percent", pi->cnt_sent > 0 ? pi->cnt_succ*100/pi->cnt_sent : 0);
Expand All @@ -252,7 +252,7 @@ static int server_status(struct ubus_context *ctx,
void* arr;
const char* dest[MAX_NUM_INTERFACES];

blobmsg_add_string(&b, "status", get_global_status_str());
blobmsg_add_string(&b, "status", get_status_str(get_global_status()));

arr = blobmsg_open_array(&b, "online_interfaces");
num = get_online_interface_names(dest, MAX_NUM_INTERFACES);
Expand Down

0 comments on commit 97d9f12

Please sign in to comment.