call_usermodehelper使用实例

#define UMH_WAIT_PROC  1       

  char * argv[3];

        argv[0] = "/sbin/mdev";
        argv[1] = "-s";
        argv[2] = 0;
        if (CallUserApp(argv)< 0) 
        {
            printk("mdev -s  failed\n");
            break;

        }


int  CallUserApp(char * argv[])
{
    int ret;
    char *envp[3];


    /*  minimal command environment taken from cpu_run_sbin_hotplug */
    envp[0] = "HOME=/";
    envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
    envp[2] = NULL;


    if (!argv || !argv[0])
    {
        printk( "%s argument is incorrect\n", __func__);
        return -1;
    }
    ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
   
    if (ret < 0) {
        printk("running user helper \"%s \" failed %d\n", argv[0], ret);
    }
    return ret;
}



static inline int call_usermodehelper(char *path, char **argv, char **envp, enum umh_wait wait);
path --- 用户空间所要启用的应用程序路径,如:"/sbin/hotplug",那么hotplug应用程序就会被内核加载启用
argv --- 传递给启用了的用户空间应用程序的参数argv
envp --- 传递给启用了的用户空间应用程序的环境变量envp,类似int main(int argc, char *_argv[])模式
wait --- 调用call_usermodehelper的内核程序是否等到被exec的用户空间应用程序,

你可能感兴趣的:(linux,driver)