不熟悉 AIX,但以下内容适用于 Linux 和 Solaris。您可以使用 LD_PRELOAD 环境变量,它告诉 ld.so 在 libc 之前加载共享库,然后编写您自己的系统调用版本,并可选择调用原始版本。man ld.so了解更多信息。类似的东西
#include <dlfcn.h>
typedef int (*ioctl_fn)(int, int, void*);
static
int
my_ioctl(int fildes,
int request,
void* argp,
ioctl_fn fn_ptr)
{
int result = 0;
/* call original or do my stuff */
if (request == INTERESTED)
{
result = 0;
}
else
{
result = (*fn_ptr)(fildes, request, argp);
}
return result;
}
/*
* override ioctl() - on first call get a pointer to the "real" one
* and then pass it onto our version of the function
*/
int
ioctl(int fildes,
int request,
void* argp)
{
static ioctl_fn S_fn_ptr = 0;
if (S_fn_ptr == 0)
{
S_fn_ptr = (ioctl_fn)dlsym(RTLD_NEXT, "ioctl");
}
return my_ioctl(fildes, request, argp, S_fn_ptr);
}
Run Code Online (Sandbox Code Playgroud)
这是从我周围的一些代码中雕刻出来的,如果我做错了,我深表歉意。
| 归档时间: |
|
| 查看次数: |
1175 次 |
| 最近记录: |