Return value of call_usermodehelper() is not correct

Viewed 362

I am calling a user-space application, /usr/bin/myapp, from a Linux Kernel Module using call_usermodehelper(). The myapp returns 2228 when it exits. I should receive same value i.e 2228 as a return value of call_usermodehelper() in the kernel module. However, I am receiving a different value, that is 46080.

My question is, why I don't receive the value I return from myapp as the return value of call_usermodehelper()? Note, myapp executes successfully when I call it from kernel module using call_usermodehelper(). I don't return 0 as a success code. I return 2228 on exit.

Here is the sample code: user-space's application code:

#include <stdio.h>

int main(int argc, char *argv[])
{
    printf("%s called successfully\n", argv[0]);
    return 2228;
}

Kernel Module's Code:

int call_userspaceapp()
{
    int ret = -EPERM;
    char *argv[] = {"/usr/bin/myapp", "11", "22", "33", NULL};
    char *envp[] = {"HOME=/", NULL};

    ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);

    printk("%s returns value %d", argv[0], ret);

    return ret;
}
1 Answers

However, I am receiving a different value, that is 46080.

Exit status has 8 bits and return value is just like waitpid return value. See userspace definition of WEXITSTATUS to access the exit status, which is 46080 >> 8 = 180, which is equal to the returned exit status 2228 % 256 = 180. Here drbd_nl.c I found an example of call_usermodehelper that also accesses the exit status with (ret >> 8) && 0xff, just like WEXITSTATUS.

Related