- Timestamp:
- 11/18/03 18:54:24 (21 years ago)
- Location:
- pykota/trunk
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/cupspykota
r1190 r1191 24 24 # 25 25 # $Log$ 26 # Revision 1.10 2003/11/18 17:54:24 jalet 27 # SIGTERMs are now transmitted to original backends. 28 # 26 29 # Revision 1.9 2003/11/18 14:11:07 jalet 27 30 # Small fix for bizarre urls … … 127 130 fulldevice_uri = os.environ.get("DEVICE_URI", "") 128 131 device_uri = fulldevice_uri[len("cupspykota:"):] 129 if device_uri.startswith("//") : 132 if device_uri.startswith("//") : # lpd (at least) 130 133 device_uri = device_uri[2:] 131 134 os.environ["DEVICE_URI"] = device_uri … … 161 164 return "%s >/dev/null" % (cmdline % locals()) 162 165 166 gotSigTerm = 0 167 def 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 163 174 def main(thebackend) : 164 175 """Do it, and do it right !""" … … 167 178 # Fortunately SIGPIPE is already ignored by Python 168 179 # 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 172 184 signal.signal(signal.SIGPIPE, signal.SIG_IGN) 173 signal.signal(signal.SIGTERM, sig nal.SIG_IGN)185 signal.signal(signal.SIGTERM, sigterm_handler) 174 186 175 187 # … … 286 298 status = subprocess.poll() 287 299 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 288 308 # In any case, deal with any remaining I/O 289 309 availablefds = pollster.poll() … … 314 334 elif fd == cerrfno : 315 335 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 # 317 341 # Some standard I/O stream has no more datas 318 342 if fd == infno : … … 373 397 else : 374 398 os.close(tocfno) 375 399 376 400 # Input file was a real file, we have to close it. 377 401 if mustclose : … … 401 425 printer.addJobToHistory(thebackend.jobid, user, thebackend.accounter.getLastPageCounter(), action, jobsize) 402 426 403 return retcode 427 return retcode # return (retcode or gotSigTerm) shouldn't be needed 404 428 405 429 if __name__ == "__main__" : … … 440 464 if fullname.startswith('"') and fullname.endswith('"') : 441 465 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) 443 467 retcode = 0 444 468 elif len(sys.argv) not in (6, 7) : -
pykota/trunk/NEWS
r1189 r1191 24 24 - 1.16alpha8 : 25 25 26 - Now cupspykota transmits SIGTERMS to the original 27 backend when the user deletes a job being processed. 28 26 29 - The documentation is now licensed under the terms of the 27 30 GNU GPL too.