Opened 11 years ago

Last modified 8 years ago

#279 enhancement new

inetd UDP support broken

Reported by: itamarst Owned by:
Priority: normal Milestone:
Component: runner Keywords:
Cc: spiv, itamarst, moshez Branch:
Author: Launchpad Bug:

Description


Change History (13)

comment:1 Changed 11 years ago by itamarst

inetd and procmon modules have main() function which is old
app and kinda icky as well.

comment:2 Changed 11 years ago by itamarst

Also it has no tests! I am upgrading this to a bug.

comment:3 Changed 11 years ago by spiv

I'll take this.

comment:4 Changed 11 years ago by moshez

Procmon should be updated enough now. It's all up to inetd now.

comment:5 Changed 11 years ago by moshez

this should be upgraded to urgent, at least as far as inetdtap is concerned

comment:6 Changed 11 years ago by moshez

upgrading to urgent, as per radix's request

comment:7 Changed 11 years ago by moshez

Here's a patch porting the tap module to new application

Index: twisted/runner/inetdtap.py
===================================================================
RCS file: /cvs/Twisted/twisted/runner/inetdtap.py,v
retrieving revision 1.1
diff -u -r1.1 inetdtap.py
--- twisted/runner/inetdtap.py  5 Dec 2002 07:59:31 -0000       1.1
+++ twisted/runner/inetdtap.py  7 Oct 2003 18:11:08 -0000
@@ -21,14 +21,14 @@

 Maintainer: U{Andrew Bennetts<spiv@twistedmatrix.com>}

-Future Plans: Bugfixes (don't call reactor.listenTCP or forkPassingFD when
-creating a TAP!), more configurability.
+Future Plans: more configurability.
 """

 import pwd, grp
 from twisted.runner import inetd, inetdconf
 from twisted.python import log, usage
 from twisted.internet.protocol import ServerFactory
+from twisted.application import internet, service


 class Options(usage.Options):
@@ -41,7 +41,27 @@
     optFlags = [['nointernal', 'i', "Don't run internal services"]]


-def updateApplication(app, config):
+class RPCServer(internet.TCPServer):
+
+    def __init__(self, rpcVersions, rpcConf, proto, service):
+        internet.TCPServer.__init__(0, ServerFactory())
+        self.rpcConf = rpcConf
+        self.proto = proto
+        self.service = service
+
+    def startService(self):
+        internet.TCPServer.startService(self)
+        import portmap
+        portNo = self._port.getHost()[2]
+        service = self.service
+        for version in rpcVersions:
+            portmap.set(self.rpcConf.services[name], version, self.proto,
+                        portNo)
+            inetd.forkPassingFD(service.program, service.programArgs,
+                                os.environ, service.user, service.group, p)
+
+def makeService(config):
+    s = service.MultiService()

     conf = inetdconf.InetdConf()
     conf.parseFile(open(config['file']))
@@ -129,20 +149,16 @@
             factory = ServerFactory()
             factory.protocol = inetd.internalProtocols[service.name]
         elif rpc:
-            proto = protocolDict[protocol]
-            p = reactor.listenTCP(0, ServerFactory())
-            portNo = p.getHost()[2]
-            for version in rpcVersions:
-                portmap.set(rpcConf.services[name], version, proto, portNo)
-            forkPassingFD(service.program, service.programArgs, os.environ,
-                          service.user, service.group, p)
+            i = RPCServer(rpcVersions, rpcConf, proto, service)
+            i.setServiceParent(s)
             continue
         else:
             # Non-internal non-rpc services use InetdFactory
             factory = inetd.InetdFactory(service)

         if protocol == 'tcp':
-            app.listenTCP(service.port, factory)
+            klass = internet.TCPServer
         elif protocol == 'udp':
-            app.listenUDP(service.port, factory)
-
+            klass = internet.UDPServer
+        klass(service.port, factory).setServiceParent(s)
+        return s

comment:8 Changed 11 years ago by itamarst

UDP ports accept a DatagramProtocol, not a factory.

comment:9 Changed 11 years ago by moshez

In general, I suspect the runner.inetd approach to UDP is correct.
I merely converted blindly from the previous version :)

comment:10 Changed 11 years ago by moshez

That's "incorrect", sorry.

comment:11 Changed 11 years ago by moshez

/cvs/Twisted/twisted/runner/inetdtap.py,v  <--  inetdtap.py
new revision: 1.2; previous revision: 1.1
Fixed new application problem.
Renaming to "inetd UDP support broken" and downgrading to "feature"
(since it works in the common cases where there are no UDP non-RPC
servers)

UDP support is non-trivial -- you need to start an application, but sometimes
let it remain up for a while before it dies, etc. etc. Read the docs :)

comment:12 Changed 8 years ago by spiv

  • Component set to runner

comment:13 Changed 3 years ago by <automation>

  • Owner spiv deleted
Note: See TracTickets for help on using tickets.