gpt4 book ai didi

linux - 为什么 call_usermodehelper 大多数时候都失败了?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:34:25 30 4
gpt4 key购买 nike

在内核模块中,我尝试使用 call_usermodehelper 函数来执行一个可执行文件 sha1,它将一个文件作为参数并将该文件的 SHA1 哈希和写入另一个文件(命名为输出)。可执行文件完美运行。

int result=-1;
name = "/home/file"
char *hargv[] = {"/home/sha1", name,NULL };
char *henvp[] = {"HOME=/", "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL };
result = call_usermodehelper("/home/sha1", hargv, henvp, 1);

但大多数时候 call_usermodehelper 返回 -14 并且无法执行可执行文件。可能是什么原因?

有时它可以工作,但随后创建的输出文件被锁定(与直接运行 sha1 时发生的情况不同),我必须运行 chown 才能正确使用它。如何预防?

没有 call_usermodehelper 是否可以执行此操作?

最佳答案

call_usermodehelper 的最后一个参数实际上是某种枚举:

#define UMH_NO_WAIT     0       /* don't wait at all */
#define UMH_WAIT_EXEC 1 /* wait for the exec, but not the process */
#define UMH_WAIT_PROC 2 /* wait for the process to complete */
#define UMH_KILLABLE 4 /* wait for EXEC/PROC killable */

如您所见,wait=1 时函数会在执行 exec 时等待,但不会等待进程。

如果没有其他约束,值 UMH_WAIT_PROC 会给出更稳定的结果。

关于linux - 为什么 call_usermodehelper 大多数时候都失败了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40385836/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com