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 gra开发者_Python百科sp how to use it or find any documents like the above one on it.
Thanks in advance for suggestions / help!
>>
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};
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
.
精彩评论