call_usermodehelper / call_usermodehelperpipe usag

2019-04-29 16:40发布

I've followed this great document on invoking user apps from the kernel: http://www.ibm.com/developerworks/linux/library/l-user-space-apps/index.html

But I'm now interested in how to get the output from the apps that have been run. I tried passing in redirection operators to write the output to a file.. Eg:

char *argv[] = { "/usr/bin/ls", ">>", "/tmp/list", NULL};
call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);

No such luck. I came across call_usermodehelperpipe and wondered if that would be what I'm after, but I haven't been able to grasp how to use it or find any documents like the above one on it.

Thanks in advance for suggestions / help!

标签: c linux kernel
2条回答
该账号已被封号
2楼-- · 2019-04-29 17:07

>> is not an argument for ls, it is something from the shell. It can be parsed using/bin/sh -c "ls >> /tmp/list" (in shell). In C, this is:

char *argv[] = { "/bin/bash", "-c", "/bin/ls >> /tmp/list", NULL};
查看更多
来,给爷笑一个
3楼-- · 2019-04-29 17:15

You can't use the usermodehelper code to do this, as it only supports running a process with stdin connected to a pipe.

You could duplicate its functionality, changing ____call_usermodehelper to override stdout in addition to stdin.

查看更多
登录 后发表回答