更加详细的debug信息
This commit is contained in:
parent
e389cde2d9
commit
da26edc508
|
|
@ -4,6 +4,7 @@
|
|||
#include <errno.h> // 添加 errno 相关定义
|
||||
#include <fcntl.h>
|
||||
#include <json-c/json.h>
|
||||
#include <pty.h>
|
||||
#include <signal.h> // 添加 SIGCHLD 相关定义
|
||||
#include <stdbool.h> // 引入 bool 类型
|
||||
#include <stdio.h>
|
||||
|
|
@ -15,13 +16,22 @@
|
|||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <pty.h>
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
#define DEBUG_LOG(fmt, ...) \
|
||||
fprintf(stderr, "[DEBUG] %s:%d:%s(): " fmt "\n", __FILE__, __LINE__, \
|
||||
__func__, ##__VA_ARGS__)
|
||||
// getpid要用到
|
||||
#include <execinfo.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void print_stacktrace() {
|
||||
void *buffer[100];
|
||||
int size = backtrace(buffer, 100); // 注意这里是 void ** 和 int 参数
|
||||
backtrace_symbols_fd(buffer, size, STDERR_FILENO);
|
||||
}
|
||||
|
||||
#define DEBUG_LOG(fmt, ...) \
|
||||
fprintf(stderr, "[DEBUG][PID %d] %s:%d:%s(): " fmt "\n", getpid(), \
|
||||
__FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
|
||||
#define DEBUG_LOG(fmt, ...) ((void)0)
|
||||
|
|
@ -338,8 +348,7 @@ void duplicate_output_to_log() {
|
|||
|
||||
while ((n = read(master_fd, buffer, sizeof(buffer))) > 0) {
|
||||
// 检查错误
|
||||
if (memmem(buffer, n, "error", 5) ||
|
||||
memmem(buffer, n, "Error", 5) ||
|
||||
if (memmem(buffer, n, "error", 5) || memmem(buffer, n, "Error", 5) ||
|
||||
memmem(buffer, n, "ERROR", 5)) {
|
||||
has_error = 1;
|
||||
}
|
||||
|
|
@ -427,13 +436,15 @@ int execve(const char *filename, char *const argv[], char *const envp[]) {
|
|||
char input = getchar();
|
||||
if (input != 'Y' && input != 'y') {
|
||||
printf("\nExecution cancelled.\n");
|
||||
return -1;
|
||||
exit(EXIT_FAILURE);
|
||||
// return -1;
|
||||
}
|
||||
printf("\nContinuing execution...\n");
|
||||
} else if (strcmp(shared_config->rules[i].type, "error") == 0) {
|
||||
printf(ANSI_COLOR_RED "[Error] %s" ANSI_COLOR_RESET "\n",
|
||||
shared_config->rules[i].msg);
|
||||
return -1;
|
||||
exit(EXIT_FAILURE);
|
||||
// return -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -490,6 +501,10 @@ __attribute__((destructor)) static void cleanup_shared_memory() {
|
|||
}
|
||||
shared_config = NULL;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
print_stacktrace();
|
||||
#endif
|
||||
|
||||
// if (log_fd != -1) {
|
||||
// DEBUG_LOG("Closing log file descriptor.");
|
||||
// close(log_fd);
|
||||
|
|
|
|||
BIN
intercept.so
BIN
intercept.so
Binary file not shown.
Loading…
Reference in New Issue