reloop
This commit is contained in:
63
tools/diag.c
Normal file
63
tools/diag.c
Normal file
@@ -0,0 +1,63 @@
|
||||
// #include "monitor_user.h"
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define DEVICE "/dev/variable_monitor"
|
||||
int file_desc = -1;
|
||||
|
||||
pid_t pid = 0;
|
||||
|
||||
/// @brief start watch
|
||||
/// @param w_arg
|
||||
/// @return 0 means success, other means fail
|
||||
int start_watch() {
|
||||
if (file_desc < 0) {
|
||||
file_desc = open(DEVICE, 0);
|
||||
}
|
||||
if (file_desc < 0) {
|
||||
printf("Can't open device file: %s\n", DEVICE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("1 \n");
|
||||
|
||||
if (ioctl(file_desc, 2, &pid) < 0) {
|
||||
printf("ioctl failed\n");
|
||||
close(file_desc);
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("2 \n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// @brief cancel watch
|
||||
/// @return 0 means success, other means fail
|
||||
int cancel_watch() {
|
||||
if (file_desc < 0) {
|
||||
file_desc = open(DEVICE, 0);
|
||||
}
|
||||
if (file_desc < 0) {
|
||||
printf("Device not open: %s,%d \n", DEVICE, file_desc);
|
||||
return file_desc;
|
||||
}
|
||||
|
||||
close(file_desc);
|
||||
file_desc = -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv){
|
||||
if (argc != 2)
|
||||
printf("USAGE: unwind-pid <pid>\n");
|
||||
|
||||
pid = atoi(argv[1]);
|
||||
|
||||
printf("%d \n", pid);
|
||||
|
||||
start_watch();
|
||||
cancel_watch();
|
||||
}
|
||||
53
tools/diag.py
Normal file
53
tools/diag.py
Normal file
@@ -0,0 +1,53 @@
|
||||
DEVICE = "/dev/variable_monitor"
|
||||
import os, sys
|
||||
import ctypes
|
||||
from ctypes import *
|
||||
import fcntl
|
||||
|
||||
file_desc = None
|
||||
|
||||
|
||||
def open_device():
|
||||
global file_desc
|
||||
if file_desc is None:
|
||||
try:
|
||||
file_desc = os.open(DEVICE, os.O_RDWR)
|
||||
except OSError:
|
||||
print(f"Can't open device file: {DEVICE}")
|
||||
return -1
|
||||
return 0
|
||||
|
||||
|
||||
def close_device():
|
||||
global file_desc
|
||||
if file_desc is None:
|
||||
print(f"Device not open: {DEVICE}, {file_desc}")
|
||||
return file_desc
|
||||
|
||||
os.close(file_desc)
|
||||
file_desc = None
|
||||
return 0
|
||||
|
||||
|
||||
class ioctl_pid(Structure):
|
||||
_fields_ = [
|
||||
("pid", c_int),
|
||||
]
|
||||
|
||||
|
||||
def ioctl(pid: int):
|
||||
pidc = ioctl_pid(
|
||||
pid=c_int(pid),
|
||||
)
|
||||
ret = fcntl.ioctl(file_desc, 0, pidc)
|
||||
if ret == 0:
|
||||
print("success")
|
||||
|
||||
|
||||
pid = int(sys.argv[1])
|
||||
|
||||
open_device()
|
||||
|
||||
ioctl(pid)
|
||||
|
||||
close_device()
|
||||
Reference in New Issue
Block a user