home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.programmer
- Path: sparky!uunet!paladin.american.edu!darwin.sura.net!jvnc.net!aggarwal
- From: aggarwal@tigger.jvnc.net (Vikas Aggarwal)
- Subject: Re: Question on daemon's under inetd
- Message-ID: <1992Dec28.104412.891@tigger.jvnc.net>
- Originator: aggarwal@nisc.jvnc.net
- Sender: news@tigger.jvnc.net (Zee News Genie)
- Nntp-Posting-Host: nisc.jvnc.net
- Organization: JvNCnet
- References: <1992Dec24.064005.5831@tigger.jvnc.net> <1992Dec24.161716.7183@Princeton.EDU> <1992Dec27.183029.2343@Princeton.EDU>
- Date: Mon, 28 Dec 1992 10:44:12 GMT
- Lines: 103
-
- subbarao@fc.hp.com (Kartik Subbarao) writes:
-
- >Once again, I must flame myself for a hastily submitted article (I had to
- >get on a plane in 30 minutes)
-
- >In article <1992Dec24.161716.7183@Princeton.EDU> I wrote:
- >>In article <1992Dec24.064005.5831@tigger.jvnc.net> aggarwal@tigger.jvnc.net (Vikas Aggarwal) writes:
- >>>? Can't I reuse the file descr 0 handed to me by 'inetd' ??
- >>
- >>You can't issue an accept() on a socket given to you by inetd.
- >>
- ... stuff deleted
-
- >>Note, this socket is bound to a different TCP
- >>port than the server socket, so that you can potentially have multiple remote
- >>hosts accessing your service.
-
- >This is bullshit. The reader socket is bound to the same port as the
- >server socket. As far as the remote host is connected, it's the same
- >connection. You can still have multiple remote connections accessing your
- >service since the REMOTE port will be different for each connection.
-
- >>Here's where the wait/nowait comes in. If you
- >>specify wait in /etc/inetd.conf, inetd will NOT allow multiple instances of
- >>your daemon to run. That is, it will wait until the process is terminated
- >>before it forks off another instance. If you specify nowait, then it will
- >>fork off as many requests as it can handle, without waiting for any of them
- >>to finish. Once again, the socket that inetd returns to you is a normal
- >>read/write socket, so you cannot accept() on it, even after the connection is
- >>closed.
-
- >This is correct.
-
- >>Even if you could, it would be useless, since it is not bound to the
- >>well-known port.
-
- >This is wrong, just as before.
-
-
- Back to my original question.. can I reuse the file descriptor handed to
- me by inetd ? Specifying 'wait' in the inetd.conf file would essentially
- tell inetd to wait for the original program to exit.. and if possible,
- I would like to tell the inetd forked process to bind to the port and
- handle all future requests.
-
- Incidentally, I *have* been using bootp and tftp code that actually
- does what I had described (server hangs around for a period of time
- before exiting). Both are UDP datagram services, and they set an
- alarm before entering an endless loop.. I am attaching the relevant
- code below.
-
-
- -vikas (609) 258-2403
- vikas@jvnc.net ...rutgers!jvncnet!vikas
- --------------------------------------------------------------------------
-
- Dec 26 16:42:32 nisc bootpd[9822]: server starting
- Dec 26 16:42:32 nisc bootpd[9822]: from 162.58.1.2.
- Dec 26 16:42:32 nisc bootpd[9822]: (re)reading /etc/bootptab
- Dec 26 16:42:32 nisc bootpd[9822]: Searching for 656d61696
- Dec 26 16:42:32 nisc bootpd[9822]: No match by hardware addr
- Dec 26 16:47:20 nisc bootpd[9822]: from 162.58.1.2.
- Dec 26 16:47:20 nisc bootpd[9822]: Searching for 656d61696
- Dec 26 16:47:20 nisc bootpd[9822]: No match by hardware addr
- Dec 26 16:49:20 nisc bootpd[9822]: from 162.58.1.2.
- Dec 26 16:49:20 nisc bootpd[9822]: Searching for 656d61696
- Dec 26 16:49:20 nisc bootpd[9822]: No match by hardware addr
- Dec 26 16:54:33 nisc bootpd[9822]: Server exiting after 300 secs inactivity
-
-
- signal(SIGALRM, onalarm);
- lastmsgtime = time(0);
- alarm(15);
- for (;;) {
- fromlen = sizeof(from);
- n = recvfrom(0, buf, sizeof (buf)-1, 0, &from, &fromlen);
- if (n < 0) {
- if (errno != EINTR)
- sleep(1);
- syslog(LOG_INFO, "recvfrom failed %d (%s)",
- n, sys_errlist[errno]);
- errno = 0;
- continue;
- }
- syslog(LOG_INFO, "from %s.\n", inet_ntoa( from.sin_addr ));
- bp = (struct bootp *) buf;
- if (n < sizeof *bp)
- continue;
- readtab(); /* (re)read the bootptab */
- sigblock(1<<SIGALRM);
- lastmsgtime = time(0);
- switch (bp->bp_op) {
- case BOOTREQUEST:
- i request();
- break;
-
- case BOOTREPLY:
- reply();
- break;
- }
- sigsetmask(0);
- }
-
-