summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--btimed.c28
-rw-r--r--btimed.xinetd2
2 files changed, 20 insertions, 10 deletions
diff --git a/btimed.c b/btimed.c
index 82d3c94..0a3b609 100644
--- a/btimed.c
+++ b/btimed.c
@@ -21,7 +21,8 @@ int
main(int argc, char **argv)
{
int sd;
- char msg[BTIME_MSGLEN];
+ char inmsg[BTIME_MSGLEN];
+ char outmsg[BTIME_MSGLEN];
struct sockaddr_in cli_addr;
int cli_addr_len;
ssize_t nbytes;
@@ -31,15 +32,24 @@ main(int argc, char **argv)
/* Running out of (x)inetd the socket was duped onto stdin. */
sd = fileno(stdin);
- memset(&cli_addr, 0, sizeof cli_addr);
- cli_addr_len = sizeof cli_addr;
- nbytes = recvfrom(sd, &msg, BTIME_MSGLEN, MSG_WAITALL,
- (struct sockaddr *)&cli_addr, &cli_addr_len);
+ /* We want to exit after 30 seconds of inactivity */
+ alarm(30);
- memset(msg, 0, BTIME_MSGLEN);
- sprintf(msg, "%u\n", get_btime());
- sendto(sd, &msg, BTIME_MSGLEN, MSG_DONTWAIT,
- (struct sockaddr *)&cli_addr, cli_addr_len);
+ /* Generate the standard btime message */
+ memset(outmsg, 0, BTIME_MSGLEN);
+ sprintf(outmsg, "%u\n", get_btime());
+
+ for (;;) {
+ memset(&cli_addr, 0, sizeof cli_addr);
+ cli_addr_len = sizeof cli_addr;
+ nbytes = recvfrom(sd, &inmsg, BTIME_MSGLEN, MSG_WAITALL,
+ (struct sockaddr *)&cli_addr, &cli_addr_len);
+
+ sendto(sd, &outmsg, BTIME_MSGLEN, MSG_DONTWAIT,
+ (struct sockaddr *)&cli_addr, cli_addr_len);
+ /* We want to exit after 30 seconds of inactivity */
+ alarm(30);
+ }
return 0;
}
diff --git a/btimed.xinetd b/btimed.xinetd
index 345e93e..ab8d1ff 100644
--- a/btimed.xinetd
+++ b/btimed.xinetd
@@ -1,7 +1,7 @@
# default: on
# description: btimed
-service qarshd
+service btimed
{
type = UNLISTED
disable = no