54 lines
874 B
Python
54 lines
874 B
Python
|
|
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()
|