From b0fb676d39b3be6e231b86edf348d47888bb26f7 Mon Sep 17 00:00:00 2001 From: Thomas Osterried Date: Mon, 4 Jul 2016 14:16:15 +0200 Subject: beacon with new option -H: -> beacon intervals relative to the hour. Idea by Folkert van Heusden . Signed-off-by: Thomas Osterried --- ax25/beacon.8 | 5 ++++- ax25/beacon.c | 36 +++++++++++++++++++++++++++++------- 2 files changed, 33 insertions(+), 8 deletions(-) (limited to 'ax25') diff --git a/ax25/beacon.8 b/ax25/beacon.8 index b4ca83c..62be7d3 100644 --- a/ax25/beacon.8 +++ b/ax25/beacon.8 @@ -2,7 +2,7 @@ .SH NAME beacon \- transmit periodic messages on an AX.25 port. .SH SYNOPSIS -.B beacon [-c ] [-d [digi ..]] [-f] [-l] [-m] [-s] [-t interval] [-v] port \(lqmessage\(rq +.B beacon [-c ] [-d [digi ..]] [-f] [-H] [-l] [-m] [-s] [-t interval] [-v] port \(lqmessage\(rq .SH DESCRIPTION .LP .B Beacon @@ -29,6 +29,9 @@ Do not fork into the background. .BI \-l Enables the logging of errors to the system log, the default is off. .TP 16 +.BI \-H +Start interval relative to the hour. +.TP 16 .BI \-m Changes the destination address to \(lqMAIL\(rq and sends the message text once only. This option overrides any destination callsign given with the \-d option. diff --git a/ax25/beacon.c b/ax25/beacon.c index e4e4749..18ccc93 100644 --- a/ax25/beacon.c +++ b/ax25/beacon.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -20,7 +21,7 @@ static int logging = FALSE; static int mail = FALSE; static int single = FALSE; -#define STR_USAGE "usage: beacon [-c ] [-d ] [-f] [-l] [-m] [-s] [-t interval] [-v] \n" +#define STR_USAGE "usage: beacon [-c ] [-d ] [-f] [-H] [-l] [-m] [-s] [-t interval] [-v] \n" static void terminate(int sig) { @@ -36,12 +37,14 @@ int main(int argc, char *argv[]) { struct full_sockaddr_ax25 dest; struct full_sockaddr_ax25 src; - int s, n, dlen, len, interval = 30; + int s, n, dlen, len; char *addr, *port, *message, *portcall; char *srccall = NULL, *destcall = NULL; int dofork = 1; + time_t interval = 30; + int interval_relative = 0; - while ((n = getopt(argc, argv, "c:d:flmst:v")) != -1) { + while ((n = getopt(argc, argv, "c:d:fHlmst:v")) != -1) { switch (n) { case 'c': srccall = optarg; @@ -52,6 +55,9 @@ int main(int argc, char *argv[]) case 'f': dofork = 0; break; + case 'H': + interval_relative = 1; + break; case 'l': logging = TRUE; break; @@ -62,7 +68,7 @@ int main(int argc, char *argv[]) single = TRUE; break; case 't': - interval = atoi(optarg); + interval = (time_t ) atoi(optarg); if (interval < 1) { fprintf(stderr, "beacon: interval must be greater than on minute\n"); return 1; @@ -78,6 +84,11 @@ int main(int argc, char *argv[]) } } + if (interval_relative && interval > 60L) { + fprintf(stderr, "beacon: can't align interval > 60min to an hour\n"); + return 1; + } + signal(SIGTERM, terminate); if (optind == argc || optind == argc - 1) { @@ -141,7 +152,17 @@ int main(int argc, char *argv[]) syslog(LOG_INFO, "starting"); } + /* interval has a one minute resolution */ + interval *= 60L; + for (;;) { + + if (interval_relative) { + time_t t_sleep = interval - (time(NULL) % interval); + if (t_sleep > 0) + sleep(t_sleep); + } + if ((s = socket(AF_AX25, SOCK_DGRAM, 0)) == -1) { if (logging) { syslog(LOG_ERR, "socket: %m"); @@ -168,10 +189,11 @@ int main(int argc, char *argv[]) close(s); - if (!single) - sleep(interval * 60); - else + if (single) break; + + if (!interval_relative) + sleep(interval); } return 0; -- cgit v1.2.3