From c0951142cdb6a0bb75745821a294d2814c74bdd1 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Mon, 13 Jul 2015 11:03:07 +0200 Subject: add runtime configuration for throttle threshold --- journal-notify.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'journal-notify.c') diff --git a/journal-notify.c b/journal-notify.c index c711d5d..792df81 100644 --- a/journal-notify.c +++ b/journal-notify.c @@ -9,7 +9,7 @@ const char * program = NULL; -const static char optstring[] = "aehi:m:nor:t:vVx:X:"; +const static char optstring[] = "aehi:m:nor:t:T:vVx:X:"; const static struct option options_long[] = { /* name has_arg flag val */ { "and", no_argument, NULL, 'a' }, @@ -21,6 +21,7 @@ const static struct option options_long[] = { { "or", no_argument, NULL, 'o' }, { "regex", required_argument, NULL, 'r' }, { "timeout", required_argument, NULL, 't' }, + { "throttle", required_argument, NULL, 'T' }, { "verbose", no_argument, NULL, 'v' }, { "version", no_argument, NULL, 'V' }, { "execute", required_argument, NULL, 'x' }, @@ -108,6 +109,7 @@ int main(int argc, char **argv) { const char * priorityname, * icon = DEFAULTICON; int timeout = NOTIFICATION_TIMEOUT; + int throttle = THROTTLE_THRESHOLD; uint8_t executeonly = 0; char * execute = NULL; @@ -149,7 +151,7 @@ int main(int argc, char **argv) { printf("%s: %s v%s (compiled: " __DATE__ ", " __TIME__ ")\n", program, PROGNAME, VERSION); if (help > 0) - fprintf(stderr, "usage: %s [-e] [-h] [-i ICON] [-m MATCH] [-o -m MATCH] [-a -m MATCH] [-n] [-r REGEX] [-t SECONDS] [-v[v]] [-V] [-x EXECUTE] [-X EXECUTE]\n", program); + fprintf(stderr, "usage: %s [-e] [-h] [-i ICON] [-m MATCH] [-o -m MATCH] [-a -m MATCH] [-n] [-r REGEX] [-t SECONDS] [-T THROTTLE] [-v[v]] [-V] [-x EXECUTE] [-X EXECUTE]\n", program); if (version > 0 || help > 0) return EXIT_SUCCESS; @@ -234,6 +236,13 @@ int main(int argc, char **argv) { printf("Notifications will be displayed for %d seconds.\n", timeout); timeout *= 1000; + break; + case 'T': + throttle = atoi(optarg); + if (verbose > 1) + printf("Notifications will be throttled starting with the %dth.\n", throttle); + timeout *= 1000; + break; case 'X': executeonly = 1; @@ -317,10 +326,10 @@ int main(int argc, char **argv) { if (have_regex == 0 || regexec(®ex, message, 0, NULL, 0) == 0) { /* throttling */ notification_count++; - if (notification_count >= THROTTLE_THRESHOLD) { + if (notification_count >= throttle) { if (verbose) fprintf(stderr, "This is the %uth notification, throttling!\n", notification_count); - if (executeonly == 0 && notification_count == THROTTLE_THRESHOLD) { + if (executeonly == 0 && notification_count == throttle) { if ((rc = notify(program, "Throttling notification! View your journal for complete log.", 0, "dialog-warning", timeout)) > 0) { fprintf(stderr, "Failed to show notification.\n"); } -- cgit v1.2.3-54-g00ecf