diff --git a/source/ucli/ucli-lib.cc b/source/ucli/ucli-lib.cc index 3536d1e..a329744 100644 --- a/source/ucli/ucli-lib.cc +++ b/source/ucli/ucli-lib.cc @@ -72,7 +72,11 @@ long diag_call_ioctl(unsigned long request, unsigned long arg) { fd = open(DEVICE, O_RDWR, 0); if (fd < 0) { printf("open %s error!\n", DEVICE); - return -EEXIST; + fd = open(DEVICE_BAK, O_RDWR, 0); + if (fd < 0){ + printf("open %s error!\n", DEVICE_BAK); + return EEXIST; + } } ret = ioctl(fd, request, arg); diff --git a/source/ucli/ucli.cc b/source/ucli/ucli.cc index cda768d..750f1d4 100644 --- a/source/ucli/ucli.cc +++ b/source/ucli/ucli.cc @@ -9,12 +9,76 @@ #include // for ioctl #include +// #include +// #include +// // #include +// #include +// #include + // ioctl // !todo move to a header file #define IOCTL_MAGIC_NUMBER 'k' #define IOCTL_PID _IOWR(IOCTL_MAGIC_NUMBER, 2, int) #define IOCTL_TGID _IOWR(IOCTL_MAGIC_NUMBER, 3, int) +// int switch_namespace(pid_t pid, const char *ns) { +// char ns_path[256]; +// snprintf(ns_path, sizeof(ns_path), "/proc/%d/ns/%s", pid, ns); + +// int fd = open(ns_path, O_RDONLY); +// if (fd == -1) { +// perror("open"); +// return -1; +// } + +// if (setns(fd, 0) == -1) { +// perror("setns"); +// close(fd); +// return -1; +// } + +// close(fd); +// return 0; +// } + +// int switch_to_pid_namespace(pid_t pid) { +// return switch_namespace(pid, "pid"); +// } + +// void test(variable_monitor_task *tsk_info) { +// // host +// if (tsk_info->task.pid == tsk_info->task.container_pid){ +// printf("host\n"); +// diag_printf_raw_stack(tsk_info->task.tgid, tsk_info->task.container_tgid, +// tsk_info->task.comm, &tsk_info->raw_stack); +// } + +// printf("container\n"); + +// // Save the current namespace. +// int fd = open("/proc/self/ns/pid", O_RDONLY); +// if (fd == -1) { +// perror("open"); +// return; +// } +// // Switch to the namespace of the target process. +// if (switch_to_pid_namespace(tsk_info->task.pid) != 0) { +// close(fd); +// return; +// } +// // Do something with tgid... + +// diag_printf_raw_stack(tsk_info->task.container_tgid, +// tsk_info->task.container_tgid, tsk_info->task.comm, +// &tsk_info->raw_stack); + +// // Switch back to the original namespace. +// if (!run_in_host && setns(fd, 0) == -1) { +// perror("setns"); +// } +// close(fd); +// } + static int task_info_extract(void *buf, unsigned int len, void *) { int *et_type; variable_monitor_record *vm_record; @@ -63,6 +127,7 @@ static int task_info_extract(void *buf, unsigned int len, void *) { : tsk_info->task.container_tgid, tsk_info->task.container_tgid, tsk_info->task.comm, &tsk_info->raw_stack); + test(tsk_info); diag_printf_kern_stack(&tsk_info->kern_stack); printf("#* 0xffffffffffffff %s (UNKNOWN)\n", tsk_info->task.comm); @@ -93,7 +158,7 @@ static void do_dump(const char *arg) { struct diag_ioctl_dump_param dump_param = { .user_ptr_len = &len, - .user_buf_len = 500 * 1024 * 1024, + .user_buf_len = 256 * 1024 * 1024, .user_buf = variant_buf, }; diff --git a/source/ucli/ucli.h b/source/ucli/ucli.h index 0aca6c1..d2d0bdb 100644 --- a/source/ucli/ucli.h +++ b/source/ucli/ucli.h @@ -15,6 +15,7 @@ #define VARIABLE_MONITOR_TASK_TYPE 0x1 #define DEVICE "/dev/variable_monitor" +#define DEVICE_BAK "/host/dev/variable_monitor" #define CGROUP_NAME_LEN 32 // max length of cgroup name #define TASK_COMM_LEN 16 // max length of task name