qnx get resmgr_context_t of old resource manager
qnx get resmgr_context_t of old resource manager
我试图通过 /proc/{pid}/as 为 qnx 6.6 创建自己的进程管理器。
但我只需要更改一个操作 (io_open),所有其他操作应继续使用旧文件 (/proc/{pid}/as)。
我是否可以只获取指向 resmgr_context_t 的指针(从路径或 fd,在 resmgr_attach 之前)并且对于所有其他操作只调用默认函数?
这是我想要的愚蠢示例:
resmgr_context_t* old_context;
int my_lseek(resmgr_context_t *ctp, io_lseek_t *msg, RESMGR_OCB_T *ocb){
return iofunc_lseek_default(old_context, msg, ocb);
}
您需要制作一个只为 io_open 注册函数的常规资源管理器,所有其他资源管理器操作将向下过滤到堆栈中的较低资源管理器。
Return 来自 io_open 回调的 ENOENT 如果您希望消息向下移动 resmgr 堆栈到其他已注册的 io_open 回调,否则 return EOK。
为简洁起见省略了错误检查。
#include <errno.h>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <sys/iofunc.h>
#include <sys/dispatch.h>
static resmgr_connect_funcs_t connect_funcs;
static resmgr_io_funcs_t io_funcs;
static iofunc_attr_t attr;
int io_open (resmgr_context_t *ctp, io_open_t *msg, RESMGR_HANDLE_T *handle, void *extra);
int main(int argc, char **argv)
{
resmgr_attr_t resmgr_attr;
dispatch_t *dpp;
dispatch_context_t *ctp;
int id;
// initialize dispatch interface
dpp = dispatch_create();
// initialize resource manager attributes
memset(&resmgr_attr, 0, sizeof resmgr_attr);
resmgr_attr.nparts_max = 1;
resmgr_attr.msg_max_size = 2048;
// initialize functions for handling messages
iofunc_func_init(_RESMGR_CONNECT_NFUNCS, &connect_funcs,
_RESMGR_IO_NFUNCS, &io_funcs);
connect_funcs.open = io_open;
// initialize attribute structure used by the device
iofunc_attr_init(&attr, S_IFNAM | 0666, 0, 0);
// attach to /proc/{pid}/as path, replace '1' with correct pid
resmgr_attach(dpp, &resmgr_attr,"/proc/1/as",
_FTYPE_ANY, _RESMGR_FLAG_BEFORE|_RESMGR_FLAG_DIR,
&connect_funcs, &io_funcs, &attr);
ctp = dispatch_context_alloc(dpp);
/* start the resource manager message loop */
while(1) {
if((ctp = dispatch_block(ctp)) == NULL) {
perror("dispatch_block");
return EXIT_FAILURE;
}
dispatch_handler(ctp);
}
}
int io_open (resmgr_context_t *ctp, io_open_t *msg, RESMGR_HANDLE_T *handle, void *extra)
{
time_t tod;
tod = time(NULL);
printf ("%10d %-32s is being opened\n", tod, msg->connect.path);
return(ENOENT);
}
我试图通过 /proc/{pid}/as 为 qnx 6.6 创建自己的进程管理器。
但我只需要更改一个操作 (io_open),所有其他操作应继续使用旧文件 (/proc/{pid}/as)。
我是否可以只获取指向 resmgr_context_t 的指针(从路径或 fd,在 resmgr_attach 之前)并且对于所有其他操作只调用默认函数?
这是我想要的愚蠢示例:
resmgr_context_t* old_context;
int my_lseek(resmgr_context_t *ctp, io_lseek_t *msg, RESMGR_OCB_T *ocb){
return iofunc_lseek_default(old_context, msg, ocb);
}
您需要制作一个只为 io_open 注册函数的常规资源管理器,所有其他资源管理器操作将向下过滤到堆栈中的较低资源管理器。
Return 来自 io_open 回调的 ENOENT 如果您希望消息向下移动 resmgr 堆栈到其他已注册的 io_open 回调,否则 return EOK。
为简洁起见省略了错误检查。
#include <errno.h>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <sys/iofunc.h>
#include <sys/dispatch.h>
static resmgr_connect_funcs_t connect_funcs;
static resmgr_io_funcs_t io_funcs;
static iofunc_attr_t attr;
int io_open (resmgr_context_t *ctp, io_open_t *msg, RESMGR_HANDLE_T *handle, void *extra);
int main(int argc, char **argv)
{
resmgr_attr_t resmgr_attr;
dispatch_t *dpp;
dispatch_context_t *ctp;
int id;
// initialize dispatch interface
dpp = dispatch_create();
// initialize resource manager attributes
memset(&resmgr_attr, 0, sizeof resmgr_attr);
resmgr_attr.nparts_max = 1;
resmgr_attr.msg_max_size = 2048;
// initialize functions for handling messages
iofunc_func_init(_RESMGR_CONNECT_NFUNCS, &connect_funcs,
_RESMGR_IO_NFUNCS, &io_funcs);
connect_funcs.open = io_open;
// initialize attribute structure used by the device
iofunc_attr_init(&attr, S_IFNAM | 0666, 0, 0);
// attach to /proc/{pid}/as path, replace '1' with correct pid
resmgr_attach(dpp, &resmgr_attr,"/proc/1/as",
_FTYPE_ANY, _RESMGR_FLAG_BEFORE|_RESMGR_FLAG_DIR,
&connect_funcs, &io_funcs, &attr);
ctp = dispatch_context_alloc(dpp);
/* start the resource manager message loop */
while(1) {
if((ctp = dispatch_block(ctp)) == NULL) {
perror("dispatch_block");
return EXIT_FAILURE;
}
dispatch_handler(ctp);
}
}
int io_open (resmgr_context_t *ctp, io_open_t *msg, RESMGR_HANDLE_T *handle, void *extra)
{
time_t tod;
tod = time(NULL);
printf ("%10d %-32s is being opened\n", tod, msg->connect.path);
return(ENOENT);
}