def rootsave(self, lines, path): """Save the lines to a root owned file at 'path'. Return an empty string for ok, else message. """ try: if os.getuid() == 0: fh = open(path, "w") for line in lines: fh.write(line) fh.close() return "" fh, temp_path = tempfile.mkstemp() f = os.fdopen(fh, "w") for line in lines: f.write(line) f.close() cmd = ("mv '%s' '%s' && chmod 644 '%s' && chown root:root '%s'" % (temp_path, path, path, path)) op = self.rootrun(cmd) if op: os.remove(temp_path) return op except: return traceback.fmt_exc()
def _debug_server(self): """ debugger thread """ try: self._process = None # Start a new process for debugging. argv = [self._process_path] + self._process_args self.logger.debug("debugger starting server: %s" % argv) try: self._process = self._debug.execv(argv, bFollow=True) except WindowsError: self.logger.error("debug_server received exception", traceback.fmt_exc()) self._pid = self._process.get_pid() self.logger.info("process started. pid=%d" % self._pid) # Wait for the debugee to finish. self._server_is_up.set() self._debug.loop() except: self.logger.error("Got an exception in _debug_server") self.logger.error(traceback.format_exc()) # Stop the debugger. finally: self._debug.stop() self._process = None self._pid = -1 self._crash_event_complete.set()
def _debug_server(self): ''' debugger thread ''' try: self._process = None # Start a new process for debugging. argv = [self._process_path] + self._process_args self.logger.debug('debugger starting server: %s' % argv) try: self._process = self._debug.execv(argv, bFollow=True) except WindowsError: self.logger.error('debug_server received exception', traceback.fmt_exc()) self._pid = self._process.get_pid() self.logger.info('process started. pid=%d' % self._pid) # Wait for the debugee to finish. self._server_is_up.set() self._debug.loop() except: self.logger.error('Got an exception in _debug_server') self.logger.error(traceback.format_exc()) # Stop the debugger. finally: self._debug.stop() self._process = None self._pid = -1 self._crash_event_complete.set()
def _debug_server(self): ''' debugger thread ''' self._system_pid = None self.logger.info('Init pykd environment') pykd.initialize() try: # Start a new process for debugging argv = [self._process_path ] + self._process_args + self.process_data argv = ' '.join(argv) self.logger.debug('Debugger starting server: %s' % argv) try: self.logger.info('Start running program with cmd:"%s"' % argv) self.report.add('cmd', argv) self._pid = pykd.startProcess(argv) self._get_correct_process_id() self.logger.debug('Process started. pykd_pid=%d' % self._pid) self._process = pykd.getCurrentProcess() self.logger.debug('Process is %s' % hex(self._process)) except WindowsError: self.logger.error('debug_server received exception', traceback.fmt_exc()) # Get Process System ID self._wait_break() while self._system_pid is None: try: self._system_pid = pykd.getProcessSystemID(self._pid) self.logger.info('process system_id=%d' % self._system_pid) except Exception as err: self.logger.debug("Get system id fail because of: %s" % err) continue # Set break points if self._wait_break(): self.logger.info( "Server is in break status setting break points") for bp in self._break_points: pykd.setBp(bp) self.logger.info("Start register event handle") # This will register our handle handler = self._handler(self) self.logger.debug('Handler object is : %s' % handler) self.logger.info('Go !!!!!') pykd.go() except: self.logger.error('Got an exception in _debug_server') self.logger.error(traceback.format_exc())
def _debug_server(self): ''' debugger thread ''' self._system_pid = None self.logger.info('Init pykd environment') pykd.initialize() try: # Start a new process for debugging argv = [self._process_path] + self._process_args + self.process_data argv = ' '.join(argv) self.logger.debug('Debugger starting server: %s' % argv) try: self.logger.info('Start running program with cmd:"%s"' % argv) self.report.add('cmd', argv) self._pid = pykd.startProcess(argv) self._get_correct_process_id() self.logger.debug('Process started. pykd_pid=%d' % self._pid) self._process = pykd.getCurrentProcess() self.logger.debug('Process is %s' % hex(self._process)) except WindowsError: self.logger.error('debug_server received exception', traceback.fmt_exc()) # Get Process System ID self._wait_break() while self._system_pid is None: try: self._system_pid = pykd.getProcessSystemID(self._pid) self.logger.info('process system_id=%d' % self._system_pid) except Exception as err: self.logger.debug("Get system id fail because of: %s" % err) continue # Set break points if self._wait_break(): self.logger.info("Server is in break status setting break points") for bp in self._break_points: pykd.setBp(bp) self.logger.info("Start register event handle") # This will register our handle handler = self._handler(self) self.logger.debug('Handler object is : %s' % handler) self.logger.info('Go !!!!!') pykd.go() except: self.logger.error('Got an exception in _debug_server') self.logger.error(traceback.format_exc())
def set(self, layout=None, variant="-"): if self.mark1 < 0: self.mark1 = 0 xrc = (self.xrc[:self.mark1] + [XKMAPMARK1 + "\n", "xkmap-set %s:%s\n" % (layout, variant), XKMAPMARK2 + "\n"] + self.xrc[self.mark1:] if layout else self.xrc) if self.rootsave: return self.rootsave(xrc, self.path) else: try: fh = open(self.path, "w") for line in xrc: fh.write(line) fh.close() except: return traceback.fmt_exc() return ""