免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 7800 | 回复: 7
打印 上一主题 下一主题

[内核模块] call_usermodehelper()返回值-2 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-07-30 17:17 |只看该作者 |倒序浏览
请教一个关于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);

}

论坛徽章:
0
2 [报告]
发表于 2012-07-31 09:21 |只看该作者
高手们帮个忙咯,项目比较急!!谢谢大家!!

论坛徽章:
0
3 [报告]
发表于 2012-08-02 09:43 |只看该作者
等着大家:wink:

论坛徽章:
0
4 [报告]
发表于 2012-08-02 10:29 |只看该作者
-2是no such file or directory,  是不是运行到这的时候文件系统还没挂载?

论坛徽章:
0
5 [报告]
发表于 2012-08-02 21:38 |只看该作者
这种问题review一下call_usermodehelper的code啊....

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

论坛徽章:
0
6 [报告]
发表于 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()这个函数,那个应用程序也是执行不成功的。
   

论坛徽章:
0
7 [报告]
发表于 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;//从这里退出的

论坛徽章:
0
8 [报告]
发表于 2013-10-03 17:26 |只看该作者
call_usermodehelper的第三个参数改为1试试
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP