Index: /pykota/trunk/bin/cupspykota
===================================================================
--- /pykota/trunk/bin/cupspykota (revision 1190)
+++ /pykota/trunk/bin/cupspykota (revision 1191)
@@ -24,4 +24,7 @@
 #
 # $Log$
+# Revision 1.10  2003/11/18 17:54:24  jalet
+# SIGTERMs are now transmitted to original backends.
+#
 # Revision 1.9  2003/11/18 14:11:07  jalet
 # Small fix for bizarre urls
@@ -127,5 +130,5 @@
             fulldevice_uri = os.environ.get("DEVICE_URI", "")
             device_uri = fulldevice_uri[len("cupspykota:"):]
-            if device_uri.startswith("//") :
+            if device_uri.startswith("//") :    # lpd (at least)
                 device_uri = device_uri[2:]
             os.environ["DEVICE_URI"] = device_uri
@@ -161,4 +164,12 @@
     return "%s >/dev/null" % (cmdline % locals())
 
+gotSigTerm = 0
+def sigterm_handler(signum, frame) :
+    """Sets a global variable whenever SIGTERM is received."""
+    # SIGTERM will be ignore most of the time, but during
+    # the call to the real backend, we have to pass it through.
+    global gotSigTerm
+    gotSigTerm = 1
+    
 def main(thebackend) :    
     """Do it, and do it right !"""
@@ -167,9 +178,10 @@
     # Fortunately SIGPIPE is already ignored by Python
     # It's there just in case this changes in the future.
-    # But here we will IGNORE SIGTERM for now, and see
-    # in a future release if we shouldn't pass it to the 
-    # original backend instead.
+    # Here we have to handle SIGTERM correctly, and pass
+    # it to the original backend if needed.
+    global gotSigTerm
+    gotSigTerm = 0
     signal.signal(signal.SIGPIPE, signal.SIG_IGN)
-    signal.signal(signal.SIGTERM, signal.SIG_IGN)
+    signal.signal(signal.SIGTERM, sigterm_handler)
     
     #
@@ -286,4 +298,12 @@
             status = subprocess.poll()
             
+            # Now if we got SIGTERM, we have 
+            # to kill -TERM the original backend
+            if gotSigTerm :
+                try :
+                    os.kill(subprocess.pid, signal.SIGTERM)
+                except : # ignore if process was already killed.
+                    pass
+            
             # In any case, deal with any remaining I/O
             availablefds = pollster.poll()
@@ -314,5 +334,9 @@
                     elif fd == cerrfno :    
                         errdata += data
-                if mask & select.POLLHUP :
+                if (mask & select.POLLHUP) or (mask & select.POLLERR) :
+                    # I've never seen POLLERR myself, but this probably
+                    # can't hurt to treat an error condition just like 
+                    # an EOF.
+                    # 
                     # Some standard I/O stream has no more datas
                     if fd == infno :
@@ -373,5 +397,5 @@
                 else :    
                     os.close(tocfno)
-            
+                
         # Input file was a real file, we have to close it.    
         if mustclose :
@@ -401,5 +425,5 @@
         printer.addJobToHistory(thebackend.jobid, user, thebackend.accounter.getLastPageCounter(), action, jobsize)
     
-    return retcode
+    return retcode # return (retcode or gotSigTerm) shouldn't be needed
 
 if __name__ == "__main__" :    
@@ -440,5 +464,5 @@
                         if fullname.startswith('"') and fullname.endswith('"') :
                             fullname = fullname[1:-1]
-                        print '%s cupspykota:%s "PyKota+%s" "PyKota managed %s"' % (devicetype, device, name, fullname)    
+                        print '%s cupspykota:%s "PyKota+%s" "PyKota managed %s"' % (devicetype, device, name, fullname)
         retcode = 0
     elif len(sys.argv) not in (6, 7) :    
Index: /pykota/trunk/NEWS
===================================================================
--- /pykota/trunk/NEWS (revision 1189)
+++ /pykota/trunk/NEWS (revision 1191)
@@ -24,4 +24,7 @@
     - 1.16alpha8 :
     
+        - Now cupspykota transmits SIGTERMS to the original  
+          backend when the user deletes a job being processed.
+          
         - The documentation is now licensed under the terms of the
           GNU GPL too.
