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?
The last argument for
call_usermodehelper
is actually some sort of enumeration: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.