stdout
This commit is contained in:
parent
9302254d57
commit
4f81d28174
|
|
@ -117,11 +117,29 @@ void duplicate_output_to_log() {
|
|||
int log_fd = open(LOG_OUT_FILE, O_WRONLY | O_CREAT | O_APPEND, 0644);
|
||||
if (log_fd < 0) return;
|
||||
|
||||
int stdout_copy = dup(STDOUT_FILENO);
|
||||
int stderr_copy = dup(STDERR_FILENO);
|
||||
|
||||
dup2(log_fd, STDOUT_FILENO);
|
||||
dup2(log_fd, STDERR_FILENO);
|
||||
close(log_fd);
|
||||
|
||||
// 让 stdout 和 stderr 同时输出到日志文件和控制台
|
||||
FILE *log_file = fdopen(log_fd, "a");
|
||||
if (log_file) {
|
||||
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||
setvbuf(stderr, NULL, _IOLBF, 0);
|
||||
stdout = log_file;
|
||||
stderr = log_file;
|
||||
}
|
||||
|
||||
dup2(stdout_copy, STDOUT_FILENO);
|
||||
dup2(stderr_copy, STDERR_FILENO);
|
||||
close(stdout_copy);
|
||||
close(stderr_copy);
|
||||
}
|
||||
|
||||
|
||||
typedef int (*orig_execve_type)(const char *filename, char *const argv[],
|
||||
char *const envp[]);
|
||||
|
||||
|
|
|
|||
BIN
intercept.so
BIN
intercept.so
Binary file not shown.
Loading…
Reference in New Issue