Chinaunix

标题: call_usermodehelper()返回值-2 [打印本页]

作者: Gen216ius    时间: 2012-07-30 17:17
标题: call_usermodehelper()返回值-2
请教一个关于call_usermodehelper()的问题,我怎么试都是返回-2,我的应用程序test,放在/bin/test下,在/bin目录下执行./test是没有问题,但是通过内核执行时就出现返回值-2,在内核时执行如下代码,可是一直没有办法执行到test,这是为什么啊!!?谢谢大家!!

void test_call_usermode(void)
{
        int iRet;
        char *argv[2], *envp[3];


    /* set up a minimal environment */
        iRet = 0;
        envp[iRet++] = "HOME=/";
        envp[iRet++] = "PATH=/sbin:/usr/sbin:/bin:/usr/bin";
        envp[iRet] = NULL;

        /* set up the argument list */
        iRet = 0;
        argv[iRet++] = "/bin/test";
        argv[iRet] = NULL;

        /* call ifconfig to configure the virtual network interface */
        iRet = call_usermodehelper(argv[0], argv, envp, 0);
        //iRet = kernel_execve(argv[0], argv, envp);
        printk("ifconfig %s %s returned %d\n", argv[1], argv[2], iRet);

}
作者: Gen216ius    时间: 2012-07-31 09:21
高手们帮个忙咯,项目比较急!!谢谢大家!!
作者: Gen216ius    时间: 2012-08-02 09:43
等着大家:wink:
作者: wwxbei    时间: 2012-08-02 10:29
-2是no such file or directory,  是不是运行到这的时候文件系统还没挂载?
作者: onlyxuyang    时间: 2012-08-02 21:38
这种问题review一下call_usermodehelper的code啊....

看看是哪一步fail了,4楼说的我觉得也有可能....  
作者: Gen216ius    时间: 2012-08-02 21:52
回复 4# wwxbei

在文件Main.c (init)        22491        2012/3/22中的如下代码中调用的
/* This is a non __init function. Force it to be noinline otherwise gcc
* makes it inline to init() and it becomes part of init.text section
*/
static noinline int init_post(void)
{
        /* need to finish all async __init code before freeing the memory */
        async_synchronize_full();
        free_initmem();
        mark_rodata_ro();
        system_state = SYSTEM_RUNNING;
        numa_default_policy();


        current->signal->flags |= SIGNAL_UNKILLABLE;

             //此处调用的那个包含call_usermodehelper()的函数
        if (ramdisk_execute_command) {
                run_init_process(ramdisk_execute_command);
                printk(KERN_WARNING "Failed to execute %s\n",
                                ramdisk_execute_command);
        }

        /*
         * We try each of these until one succeeds.
         *
         * The Bourne shell can be used instead of init if we are
         * trying to recover a really broken machine.
         */
        if (execute_command) {
                run_init_process(execute_command);
                printk(KERN_WARNING "Failed to execute %s.  Attempting "
                                        "defaults...\n", execute_command);
        }
        run_init_process("/sbin/init");
        run_init_process("/etc/init");
        run_init_process("/bin/init");
        run_init_process("/bin/sh");

        panic("No init found.  Try passing init= option to kernel. "
              "See Linux Documentation/init.txt for guidance.");
}
按理说文件系统已经起来了,接着是启动Android了。并且用call_usermodehelper()调用了/bin/ls,返回值就不是-2了,但是看不到调用后结果,LOG中看不到当前目录下的文件列表,因此还有一个问题:执行call_usermodehelper()后的那个应用程序结果从那里显示打印信息。

另外还试了run_init_process()这个函数,那个应用程序也是执行不成功的。
   
作者: Gen216ius    时间: 2012-08-02 22:02
onlyxuyang 发表于 2012-08-02 21:38
这种问题review一下call_usermodehelper的code啊....

看看是哪一步fail了,4楼说的我觉得也有可能....


是在Namei.c (fs)        90057        2012/3/22文件中如下函数
static int link_path_walk(const char *name, struct nameidata *nd)中出错的如下代码处出错,并返回的

                err = do_lookup(nd, &this, &next, &inode);
                if (err)
                        break;
                if (inode && unlikely(inode->i_op->follow_link) &&  //inode->i_op->follow_link不能访问的,inode似乎是空的,待续ING,目前在追前面的do_lookup函数
                    (lookup_flags & LOOKUP_FOLLOW)) {
                        err = do_follow_link(inode, &next, nd);
                        if (err)
                                goto return_err;
                        nd->inode = nd->path.dentry->d_inode;
                } else {//执行了else
                        path_to_nameidata(&next, nd);
                        nd->inode = inode;
                }
                err = -ENOENT;//#define        ENOENT                 2        /* No such file or directory */
                if (!nd->inode)
                        break;//从这里退出的
作者: szhxc111    时间: 2013-10-03 17:26
call_usermodehelper的第三个参数改为1试试




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2