From f7ff72ae37521a4f610debbe0756aae4a309d69d Mon Sep 17 00:00:00 2001 From: Jhe Date: Wed, 29 Jan 2020 15:11:21 +0800 Subject: [PATCH] split log when multithread was disabled --- qiling/os/linux/thread.py | 8 ++++---- qiling/os/posix/syscall.py | 8 +++----- qiling/utils.py | 6 ++++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/qiling/os/linux/thread.py b/qiling/os/linux/thread.py index 714124412..b481025d3 100644 --- a/qiling/os/linux/thread.py +++ b/qiling/os/linux/thread.py @@ -233,10 +233,10 @@ def update_global_thread_id(self): #global GLOBAL_THREAD_ID self.ql.global_thread_id = os.getpid() - def set_thread_log_file(self, log_file): - if self.ql.log_split and log_file != None: - self.log_file_fd = open(log_file + "_" + str(os.getpid()) + '.' + str(self.thread_id), 'w+') - #logging.basicConfig(filename= log_file + "_" + str(os.getpid()) + ".qlog", filemode='w+', level=logging.DEBUG, format='%(message)s') + def set_thread_log_file(self, log_dir): + if self.ql.log_split and log_dir != None: + _logger = self.ql.log_file_fd + self.log_file_fd = ql_setup_logging_file(self.ql.output, log_dir, _logger) def get_current_path(self): return self.current_path diff --git a/qiling/os/posix/syscall.py b/qiling/os/posix/syscall.py index 098d58a78..79179dbbc 100644 --- a/qiling/os/posix/syscall.py +++ b/qiling/os/posix/syscall.py @@ -1142,6 +1142,7 @@ def ql_syscall_rt_sigprocmask(ql, rt_sigprocmask_how, rt_sigprocmask_nset, rt_si def ql_syscall_vfork(ql, null0, null1, null2, null3, null4, null5): + breakpoint() pid = os.fork() if pid == 0: @@ -1152,12 +1153,9 @@ def ql_syscall_vfork(ql, null0, null1, null2, null3, null4, null5): ql.thread_management.cur_thread.set_thread_log_file(ql.log_dir) else: if ql.log_split: - #ql.log_file = (ql.log_file + "_" + str(pid)) - _logger = ql_setup_logging_stream(ql.output) + _logger = ql.log_file_fd _logger = ql_setup_logging_file(ql.output, ql.log_file , _logger) - # if ql.log_dir != None: - # ql.log_file_fd = open(ql.log_dir + "_" + str(os.getpid()), 'w+') - #ql.log_file_fd = logging.basicConfig(filename=ql.log_file_name + "_" + str(os.getpid()) + ".qlog", filemode='w+', level=logging.DEBUG, format='%(message)s') + ql.log_file_fd = _logger else: regreturn = pid diff --git a/qiling/utils.py b/qiling/utils.py index 64c42bf41..b450d4815 100644 --- a/qiling/utils.py +++ b/qiling/utils.py @@ -61,8 +61,10 @@ def ql_get_module_function(module_name, function_name): def ql_setup_logger(logger_name=None): - if logger_name is None: # use random logger name to avoid share logger_name in unittesting - logger_name = 'qiling_%s' % random.random() + if logger_name is None: # increasing logger name counter to prevent conflict + loggers = logging.root.manager.loggerDict + _counter = len(loggers) + logger_name = 'qiling_%s' % _counter logger = logging.getLogger(logger_name) logger.setLevel(logging.DEBUG) return logger