Why does call_usermodehelper fail most of the times?

Deadly 提交于 2019-11-28 09:52:14

问题


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);

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

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?

Is there anyway to do this operation without call_usermodehelper?


回答1:


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 */

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

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



来源:https://stackoverflow.com/questions/40385836/why-does-call-usermodehelper-fail-most-of-the-times

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!