diff options
-rw-r--r-- | ax25/beacon.8 | 5 | ||||
-rw-r--r-- | ax25/beacon.c | 36 |
2 files changed, 33 insertions, 8 deletions
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 <src_call>] [-d <dest_call>[digi ..]] [-f] [-l] [-m] [-s] [-t interval] [-v] port \(lqmessage\(rq +.B beacon [-c <src_call>] [-d <dest_call>[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 <syslog.h> #include <signal.h> #include <string.h> +#include <time.h> #include <sys/types.h> #include <sys/socket.h> @@ -20,7 +21,7 @@ static int logging = FALSE; static int mail = FALSE; static int single = FALSE; -#define STR_USAGE "usage: beacon [-c <src_call>] [-d <dest_call>] [-f] [-l] [-m] [-s] [-t interval] [-v] <port> <message>\n" +#define STR_USAGE "usage: beacon [-c <src_call>] [-d <dest_call>] [-f] [-H] [-l] [-m] [-s] [-t interval] [-v] <port> <message>\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; |