为什么call_usermodehelper在大多数情况下会失败? [英] Why does call_usermodehelper fail most of the times?

查看:896
本文介绍了为什么call_usermodehelper在大多数情况下会失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

From a kernel module, I am trying to use call_usermodehelper function to execute an executable sha1 which takes a file as argument and writes the SHA1 hash sum of the file to another file (named output). The executable works perfectly.

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并无法执行该可执行文件.可能是什么原因?

But most of the times call_usermodehelper returns -14 and fails to execute the executable. What could be the reason?

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

Sometimes it works, but then the output file created is locked (unlike what happens when sha1 is run directly) and I have to run chown before I can use it properly. How can this be prevented?

在没有call_usermodehelper的情况下是否可以执行此操作?

Is there anyway to do this operation without call_usermodehelper?

推荐答案

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

The last argument for call_usermodehelper is actually some sort of enumeration:

#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时等待,但不等待进程.

As you can see, with wait=1 the function waits while exec is performed, but doesn't wait the process.

如果没有其他限制,则值 UMH_WAIT_PROC 会给出更稳定的结果.

If no other constraints, value UMH_WAIT_PROC gives more stable results.

这篇关于为什么call_usermodehelper在大多数情况下会失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆