home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / unix / programm / 5783 < prev    next >
Encoding:
Text File  |  1992-12-28  |  4.7 KB  |  117 lines

  1. Newsgroups: comp.unix.programmer
  2. Path: sparky!uunet!paladin.american.edu!darwin.sura.net!jvnc.net!aggarwal
  3. From: aggarwal@tigger.jvnc.net (Vikas Aggarwal)
  4. Subject: Re: Question on daemon's under inetd
  5. Message-ID: <1992Dec28.104412.891@tigger.jvnc.net>
  6. Originator: aggarwal@nisc.jvnc.net
  7. Sender: news@tigger.jvnc.net (Zee News Genie)
  8. Nntp-Posting-Host: nisc.jvnc.net
  9. Organization: JvNCnet
  10. References: <1992Dec24.064005.5831@tigger.jvnc.net> <1992Dec24.161716.7183@Princeton.EDU> <1992Dec27.183029.2343@Princeton.EDU>
  11. Date: Mon, 28 Dec 1992 10:44:12 GMT
  12. Lines: 103
  13.  
  14. subbarao@fc.hp.com (Kartik Subbarao) writes:
  15.  
  16. >Once again, I must flame myself for a hastily submitted article (I had to
  17. >get on a plane in 30 minutes)
  18.  
  19. >In article <1992Dec24.161716.7183@Princeton.EDU> I wrote:
  20. >>In article <1992Dec24.064005.5831@tigger.jvnc.net> aggarwal@tigger.jvnc.net (Vikas Aggarwal) writes:
  21. >>>? Can't I reuse the file descr 0 handed to me by 'inetd' ??
  22. >>
  23. >>You can't issue an accept() on a socket given to you by inetd.
  24. >>
  25. ... stuff deleted
  26.  
  27. >>Note, this socket is bound to a different TCP
  28. >>port than the server socket, so that you can potentially have multiple remote
  29. >>hosts accessing your service. 
  30.  
  31. >This is bullshit. The reader socket is bound to the same port as the
  32. >server socket. As far as the remote host is connected, it's the same
  33. >connection. You can still have multiple remote connections accessing your
  34. >service since the REMOTE port will be different for each connection.
  35.  
  36. >>Here's where the wait/nowait comes in. If you
  37. >>specify wait in /etc/inetd.conf, inetd will NOT allow multiple instances of
  38. >>your daemon to run. That is, it will wait until the process is terminated
  39. >>before it forks off another instance. If you specify nowait, then it will
  40. >>fork off as many requests as it can handle, without waiting for any of them
  41. >>to finish. Once again, the socket that inetd returns to you is a normal 
  42. >>read/write socket, so you cannot accept() on it, even after the connection is 
  43. >>closed. 
  44.  
  45. >This is correct.
  46.  
  47. >>Even if you could, it would be useless, since it is not bound to the 
  48. >>well-known port.
  49.  
  50. >This is wrong, just as before.
  51.  
  52.  
  53. Back to my original question.. can I reuse the file descriptor handed to
  54. me by inetd ? Specifying 'wait' in the inetd.conf file would essentially
  55. tell inetd to wait for the original program to exit.. and if possible,
  56. I would like to tell the inetd forked process to bind to the port and
  57. handle all future requests.
  58.  
  59. Incidentally, I *have* been using bootp and tftp code that actually
  60. does what I had described (server hangs around for a period of time
  61. before exiting). Both are UDP datagram services, and they set an 
  62. alarm before entering an endless loop.. I am attaching the relevant
  63. code below.
  64.  
  65.  
  66.  -vikas                                                     (609) 258-2403
  67.  vikas@jvnc.net                                      ...rutgers!jvncnet!vikas
  68. --------------------------------------------------------------------------
  69.  
  70. Dec 26 16:42:32 nisc bootpd[9822]: server starting
  71. Dec 26 16:42:32 nisc bootpd[9822]: from 162.58.1.2.
  72. Dec 26 16:42:32 nisc bootpd[9822]: (re)reading /etc/bootptab
  73. Dec 26 16:42:32 nisc bootpd[9822]: Searching for 656d61696
  74. Dec 26 16:42:32 nisc bootpd[9822]: No match by hardware addr
  75. Dec 26 16:47:20 nisc bootpd[9822]: from 162.58.1.2.
  76. Dec 26 16:47:20 nisc bootpd[9822]: Searching for 656d61696
  77. Dec 26 16:47:20 nisc bootpd[9822]: No match by hardware addr
  78. Dec 26 16:49:20 nisc bootpd[9822]: from 162.58.1.2.
  79. Dec 26 16:49:20 nisc bootpd[9822]: Searching for 656d61696
  80. Dec 26 16:49:20 nisc bootpd[9822]: No match by hardware addr
  81. Dec 26 16:54:33 nisc bootpd[9822]: Server exiting after 300 secs inactivity
  82.  
  83.  
  84.         signal(SIGALRM, onalarm);
  85.         lastmsgtime = time(0);
  86.         alarm(15);
  87.         for (;;) {
  88.                 fromlen = sizeof(from);
  89.                 n = recvfrom(0, buf, sizeof (buf)-1, 0, &from, &fromlen);
  90.                 if (n < 0) {
  91.                         if (errno != EINTR)
  92.                                 sleep(1);
  93.                         syslog(LOG_INFO, "recvfrom failed %d (%s)",
  94.                                n, sys_errlist[errno]);
  95.                         errno = 0;
  96.                         continue;
  97.                 }
  98.                 syslog(LOG_INFO, "from %s.\n", inet_ntoa( from.sin_addr ));
  99.                 bp = (struct bootp *) buf;
  100.                 if (n < sizeof *bp)
  101.                     continue;
  102.                 readtab();                      /* (re)read the bootptab */
  103.                 sigblock(1<<SIGALRM);
  104.                 lastmsgtime = time(0);
  105.                 switch (bp->bp_op) {
  106.                 case BOOTREQUEST:
  107. i                        request();
  108.                         break;
  109.  
  110.                 case BOOTREPLY:
  111.                         reply();
  112.                         break;
  113.                 }
  114.                 sigsetmask(0);
  115.         }
  116.  
  117.