Changeset 1191

Show
Ignore:
Timestamp:
11/18/03 18:54:24 (20 years ago)
Author:
jalet
Message:

SIGTERMs are now transmitted to original backends.

Location:
pykota/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/cupspykota

    r1190 r1191  
    2424# 
    2525# $Log$ 
     26# Revision 1.10  2003/11/18 17:54:24  jalet 
     27# SIGTERMs are now transmitted to original backends. 
     28# 
    2629# Revision 1.9  2003/11/18 14:11:07  jalet 
    2730# Small fix for bizarre urls 
     
    127130            fulldevice_uri = os.environ.get("DEVICE_URI", "") 
    128131            device_uri = fulldevice_uri[len("cupspykota:"):] 
    129             if device_uri.startswith("//") : 
     132            if device_uri.startswith("//") :    # lpd (at least) 
    130133                device_uri = device_uri[2:] 
    131134            os.environ["DEVICE_URI"] = device_uri 
     
    161164    return "%s >/dev/null" % (cmdline % locals()) 
    162165 
     166gotSigTerm = 0 
     167def sigterm_handler(signum, frame) : 
     168    """Sets a global variable whenever SIGTERM is received.""" 
     169    # SIGTERM will be ignore most of the time, but during 
     170    # the call to the real backend, we have to pass it through. 
     171    global gotSigTerm 
     172    gotSigTerm = 1 
     173     
    163174def main(thebackend) :     
    164175    """Do it, and do it right !""" 
     
    167178    # Fortunately SIGPIPE is already ignored by Python 
    168179    # It's there just in case this changes in the future. 
    169     # But here we will IGNORE SIGTERM for now, and see 
    170     # in a future release if we shouldn't pass it to the  
    171     # original backend instead. 
     180    # Here we have to handle SIGTERM correctly, and pass 
     181    # it to the original backend if needed. 
     182    global gotSigTerm 
     183    gotSigTerm = 0 
    172184    signal.signal(signal.SIGPIPE, signal.SIG_IGN) 
    173     signal.signal(signal.SIGTERM, signal.SIG_IGN) 
     185    signal.signal(signal.SIGTERM, sigterm_handler) 
    174186     
    175187    # 
     
    286298            status = subprocess.poll() 
    287299             
     300            # Now if we got SIGTERM, we have  
     301            # to kill -TERM the original backend 
     302            if gotSigTerm : 
     303                try : 
     304                    os.kill(subprocess.pid, signal.SIGTERM) 
     305                except : # ignore if process was already killed. 
     306                    pass 
     307             
    288308            # In any case, deal with any remaining I/O 
    289309            availablefds = pollster.poll() 
     
    314334                    elif fd == cerrfno :     
    315335                        errdata += data 
    316                 if mask & select.POLLHUP : 
     336                if (mask & select.POLLHUP) or (mask & select.POLLERR) : 
     337                    # I've never seen POLLERR myself, but this probably 
     338                    # can't hurt to treat an error condition just like  
     339                    # an EOF. 
     340                    #  
    317341                    # Some standard I/O stream has no more datas 
    318342                    if fd == infno : 
     
    373397                else :     
    374398                    os.close(tocfno) 
    375              
     399                 
    376400        # Input file was a real file, we have to close it.     
    377401        if mustclose : 
     
    401425        printer.addJobToHistory(thebackend.jobid, user, thebackend.accounter.getLastPageCounter(), action, jobsize) 
    402426     
    403     return retcode 
     427    return retcode # return (retcode or gotSigTerm) shouldn't be needed 
    404428 
    405429if __name__ == "__main__" :     
     
    440464                        if fullname.startswith('"') and fullname.endswith('"') : 
    441465                            fullname = fullname[1:-1] 
    442                         print '%s cupspykota:%s "PyKota+%s" "PyKota managed %s"' % (devicetype, device, name, fullname)     
     466                        print '%s cupspykota:%s "PyKota+%s" "PyKota managed %s"' % (devicetype, device, name, fullname) 
    443467        retcode = 0 
    444468    elif len(sys.argv) not in (6, 7) :     
  • pykota/trunk/NEWS

    r1189 r1191  
    2424    - 1.16alpha8 : 
    2525     
     26        - Now cupspykota transmits SIGTERMS to the original   
     27          backend when the user deletes a job being processed. 
     28           
    2629        - The documentation is now licensed under the terms of the 
    2730          GNU GPL too.