2

I need to redirect stdout of a command invoked from kernel space using the linux usermode helper api. Using "echo" commmand as an example below. This does NOT work.

static int    umh_helper() {
struct subprocess_info *sub_info;
char *argv[] = {"/bin/echo", "Hi", ">", "/tmp/command.out", NULL};
static char *envp[] = {
    "HOME=/root",
    "TERM=linux",
    "PATH=/bin:/sbin:/bin:/usr/sbin:/usr/bin", NULL };
return call_usermodehelper( argv[0], argv, envp, UMH_WAIT_PROC );
}

The command I need to run does NOT support a way to take file name as its input argument to write the output to file directly and hence I need to do this.

red0ct
  • 4,840
  • 3
  • 17
  • 44
anglee
  • 99
  • 2
  • 12
  • 2
    `call_usermodehelper` works like `execve` user library call: it does **not run shell** for execute the command. Because redirection using `>` is a *shell* functionality, it doesn't work with `call_usermodehelper`. You may try to execute shell and pass command line for it: `{"/bin/sh", "-c", "/bin/echo Hi > /tmp/command.out"}`. – Tsyvarev Sep 23 '19 at 09:03
  • using sh -c doesnt work. The call_usermodehelper returns -2. – anglee Sep 23 '19 at 20:05
  • 1
    -2 is [ENOENT](https://elixir.bootlin.com/linux/v3.9.11/source/include/uapi/asm-generic/errno-base.h#L5) - "No such file or directory". It means that some of files (shell executable, path to your program, etc.) doesn't exist. Check the paths you use. – Tsyvarev Sep 23 '19 at 21:21

0 Answers0