块读取直到Memfd_create中可用的数据
我正在尝试在内存中创建一个文件,该文件的行为就像字符设备一样。我已经使用了memfd_create(Path,0)
,但是我开始认为这不是我需要的。 从本质上讲,我想做的是通过ld_preload打开钩子,寻找open(“/dev/input/event0”)
,然后将返回的FD更改为我的MEMFD。然后,我想创建一种以挂钩应用程序来读取的队列,就像它是读取设备文件一样。
但是,即使有0个字节要读取,在我的memFD上使用时似乎也不会阻止()。你能把我指向正确的方向吗?
编辑:
按照要求,我提供代码,但是我不确定这是否有任何帮助,因为它实际上是两行...
struct input_event ev;
int kbd = memfd_create("/dev/input/event0", 0);
read(kbd, &ev, sizeof(ev)); //<-- How can I make this block by default?
I'm trying to create a file in memory, which behaves just like a character device. I've used memfd_create(path, 0)
, but I'm starting to think this is not what I need.
In essence what I want to do is create a hook via LD_PRELOAD on open, look for open("/dev/input/event0")
and change the returned fd to my memfd. Then I want to create a sort of queue for the hooked app to read from just like it would if it were a read device file.
However read() seems to not block when used on my memfd even if there are 0 bytes to be read. Could you point me in the right direction?
EDIT:
As requested I'm providing the code, however I'm not quite sure if this will be of any help since it is literally two lines...
struct input_event ev;
int kbd = memfd_create("/dev/input/event0", 0);
read(kbd, &ev, sizeof(ev)); //<-- How can I make this block by default?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
哦。使用管道代替memfd。
然后从一端写入并在挂钩应用程序中阅读。
D'oh. Use a pipe instead of a memfd.
Then write from one end and read in the hooked app.