Skip to content

Commit 51b780f

Browse files
committed
Adds IGNOREEMPTY=[0|1] to {P,C}BEACON cmd.
When using COMMENTCMD (PBEACON), or INFOCMD (CBEACON), direwolf reports an error when the command does not produce any stdout, even when the command exits with status 0. This commit allows something like: PBEACON IGNOREEMPTY=1 EVERY=00:30 COMMENTCMD='command_to_print_updates' Say 'command_to_print_updates' only prints to stdout when its output would be different from the last time it ran. With the above, direwolf would run the command as before, but does not print an error when no new updates are available. An error is still reported if the exit status is not 0.
1 parent b2548ec commit 51b780f

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

Diff for: beacon.c

+11-7
Original file line numberDiff line numberDiff line change
@@ -761,12 +761,14 @@ static void beacon_send (int j, dwgps_info_t *gpsinfo)
761761
strlcat (super_comment, var_comment, sizeof(super_comment));
762762
}
763763
else {
764-
text_color_set(DW_COLOR_ERROR);
765-
dw_printf ("xBEACON, config file line %d, COMMENTCMD failure.\n", g_misc_config_p->beacon[j].lineno);
766-
}
764+
if (k < 0 || !g_misc_config_p->beacon[j].ignore_empty_cmd_stdout) {
765+
text_color_set(DW_COLOR_ERROR);
766+
dw_printf ("xBEACON, config file line %d, COMMENTCMD failure.\n", g_misc_config_p->beacon[j].lineno);
767+
}
768+
strlcpy (super_comment, "", sizeof(super_comment)); /* abort */
769+
}
767770
}
768771

769-
770772
/*
771773
* Add the info part depending on beacon type.
772774
*/
@@ -882,9 +884,11 @@ static void beacon_send (int j, dwgps_info_t *gpsinfo)
882884
strlcat (beacon_text, info_part, sizeof(beacon_text));
883885
}
884886
else {
885-
text_color_set(DW_COLOR_ERROR);
886-
dw_printf ("CBEACON, config file line %d, INFOCMD failure.\n", g_misc_config_p->beacon[j].lineno);
887-
strlcpy (beacon_text, "", sizeof(beacon_text)); // abort!
887+
if(k < 0 || !g_misc_config_p->beacon[j].ignore_empty_cmd_stdout) {
888+
text_color_set(DW_COLOR_ERROR);
889+
dw_printf ("CBEACON, config file line %d, INFOCMD failure.\n", g_misc_config_p->beacon[j].lineno);
890+
}
891+
strlcpy (beacon_text, "", sizeof(beacon_text)); // abort!
888892
}
889893
}
890894
else {

Diff for: config.c

+3
Original file line numberDiff line numberDiff line change
@@ -4379,6 +4379,9 @@ static int beacon_options(char *cmd, struct beacon_s *b, int line, struct audio_
43794379
else if (strcasecmp(keyword, "INFOCMD") == 0) {
43804380
b->custom_infocmd = strdup(value);
43814381
}
4382+
else if (strcasecmp(keyword, "IGNOREEMPTY") == 0) {
4383+
b->ignore_empty_cmd_stdout = atoi(value);
4384+
}
43824385
else if (strcasecmp(keyword, "OBJNAME") == 0) {
43834386
strlcpy(b->objname, value, sizeof(b->objname));
43844387
}

Diff for: config.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ struct misc_config_s {
145145
char *comment; /* Comment or NULL. */
146146
char *commentcmd; /* Command to append more to Comment or NULL. */
147147

148-
148+
int ignore_empty_cmd_stdout; /* Do not print an error when infocmd exits
149+
with status 0, and no output is generated. */
149150
} beacon[MAX_BEACONS];
150151

151152
};

0 commit comments

Comments
 (0)