diff options
Diffstat (limited to 'yocto-poky/bitbake/lib/prserv/serv.py')
-rw-r--r-- | yocto-poky/bitbake/lib/prserv/serv.py | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/yocto-poky/bitbake/lib/prserv/serv.py b/yocto-poky/bitbake/lib/prserv/serv.py index eafc3aab7..affccd9b3 100644 --- a/yocto-poky/bitbake/lib/prserv/serv.py +++ b/yocto-poky/bitbake/lib/prserv/serv.py @@ -4,6 +4,7 @@ from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler import threading import Queue import socket +import StringIO try: import sqlite3 @@ -59,12 +60,10 @@ class PRServer(SimpleXMLRPCServer): self.register_function(self.quit, "quit") self.register_function(self.ping, "ping") self.register_function(self.export, "export") + self.register_function(self.dump_db, "dump_db") self.register_function(self.importone, "importone") self.register_introspection_functions() - self.db = prserv.db.PRData(self.dbfile) - self.table = self.db["PRMAIN"] - self.requestqueue = Queue.Queue() self.handlerthread = threading.Thread(target = self.process_request_thread) self.handlerthread.daemon = False @@ -79,6 +78,8 @@ class PRServer(SimpleXMLRPCServer): # 60 iterations between syncs or sync if dirty every ~30 seconds iterations_between_sync = 60 + bb.utils.set_process_name("PRServ Handler") + while not self.quit: try: (request, client_address) = self.requestqueue.get(True, 30) @@ -98,11 +99,13 @@ class PRServer(SimpleXMLRPCServer): self.table.sync_if_dirty() def sigint_handler(self, signum, stack): - self.table.sync() + if self.table: + self.table.sync() def sigterm_handler(self, signum, stack): - self.table.sync() - raise SystemExit + if self.table: + self.table.sync() + self.quit=True def process_request(self, request, client_address): self.requestqueue.put((request, client_address)) @@ -114,6 +117,26 @@ class PRServer(SimpleXMLRPCServer): logger.error(str(exc)) return None + def dump_db(self): + """ + Returns a script (string) that reconstructs the state of the + entire database at the time this function is called. The script + language is defined by the backing database engine, which is a + function of server configuration. + Returns None if the database engine does not support dumping to + script or if some other error is encountered in processing. + """ + buff = StringIO.StringIO() + try: + self.table.sync() + self.table.dump_db(buff) + return buff.getvalue() + except Exception as exc: + logger.error(str(exc)) + return None + finally: + buff.close() + def importone(self, version, pkgarch, checksum, value): return self.table.importone(version, pkgarch, checksum, value) @@ -141,6 +164,12 @@ class PRServer(SimpleXMLRPCServer): self.quit = False self.timeout = 0.5 + bb.utils.set_process_name("PRServ") + + # DB connection must be created after all forks + self.db = prserv.db.PRData(self.dbfile) + self.table = self.db["PRMAIN"] + logger.info("Started PRServer with DBfile: %s, IP: %s, PORT: %s, PID: %s" % (self.dbfile, self.host, self.port, str(os.getpid()))) @@ -209,7 +238,6 @@ class PRServer(SimpleXMLRPCServer): def cleanup_handles(self): signal.signal(signal.SIGINT, self.sigint_handler) signal.signal(signal.SIGTERM, self.sigterm_handler) - os.umask(0) os.chdir("/") sys.stdout.flush() @@ -282,6 +310,9 @@ class PRServerConnection(object): def export(self,version=None, pkgarch=None, checksum=None, colinfo=True): return self.connection.export(version, pkgarch, checksum, colinfo) + def dump_db(self): + return self.connection.dump_db() + def importone(self, version, pkgarch, checksum, value): return self.connection.importone(version, pkgarch, checksum, value) |