diff options
author | Nate Straz <nstraz@redhat.com> | 2006-01-05 21:45:17 +0000 |
---|---|---|
committer | Nathan Straz <nstraz@redhat.com> | 2008-09-23 09:37:45 -0400 |
commit | 1f2aa6ac06fc734c616967e64e69117f59d9429c (patch) | |
tree | 7845827adb87fb3d938a0c90f4f23d244bae6723 /btimed.c | |
parent | 882783f2913e9daa30e12fc2fb1ae0e4a51a3b4b (diff) | |
download | qarsh-1f2aa6ac06fc734c616967e64e69117f59d9429c.tar.gz qarsh-1f2aa6ac06fc734c616967e64e69117f59d9429c.tar.xz qarsh-1f2aa6ac06fc734c616967e64e69117f59d9429c.zip |
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
Diffstat (limited to 'btimed.c')
-rw-r--r-- | btimed.c | 28 |
1 files changed, 19 insertions, 9 deletions
@@ -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; } |