summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNate Straz <nstraz@redhat.com>2006-01-05 21:45:17 +0000
committerNathan Straz <nstraz@redhat.com>2008-09-23 09:37:45 -0400
commit1f2aa6ac06fc734c616967e64e69117f59d9429c (patch)
tree7845827adb87fb3d938a0c90f4f23d244bae6723
parent882783f2913e9daa30e12fc2fb1ae0e4a51a3b4b (diff)
downloadqarsh-1f2aa6ac06fc734c616967e64e69117f59d9429c.zip
qarsh-1f2aa6ac06fc734c616967e64e69117f59d9429c.tar.gz
qarsh-1f2aa6ac06fc734c616967e64e69117f59d9429c.tar.xz
Keep btimed around to hand out btime packets until no one has asked for one
in 30 seconds. Fix the servce name in the btimed xinetd config file
-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