5

I wanted to use strace to see what was happening when I do `hadoop fs -ls ', so I ran the command:

strace -f -e trace=execve hadoop fs -ls /stg which resulted in a lot of output like this:

[pid 187050] execve("/opt/sas/app/platform/lsf/8.0/linux2.6-glibc2.3-x86_64/etc/setsid", ["setsid", "bash", "-c", "echo $$"], [/* 78 vars */]) = -1 ENOENT (No such file or directory)
[pid 187050] execve("/opt/sas/app/platform/lsf/8.0/linux2.6-glibc2.3-x86_64/bin/setsid", ["setsid", "bash", "-c", "echo $$"], [/* 78 vars */]) = -1 ENOENT (No such file or directory)
[pid 187050] execve("/opt/dca/bin/setsid", ["setsid", "bash", "-c", "echo $$"], [/* 78 vars */]) = -1 ENOENT (No such file or directory)
[pid 187050] execve("/usr/local/greenplum-cc-web/./bin/setsid", ["setsid", "bash", "-c", "echo $$"], [/* 78 vars */]) = -1 ENOENT (No such file or directory)
[pid 187050] execve("/usr/lib64/qt-3.3/bin/setsid", ["setsid", "bash", "-c", "echo $$"], [/* 78 vars */]) = -1 ENOENT (No such file or directory)
[pid 187050] execve("/usr/local/bin/setsid", ["setsid", "bash", "-c", "echo $$"], [/* 78 vars */]) = -1 ENOENT (No such file or directory)
[pid 187050] execve("/bin/setsid", ["setsid", "bash", "-c", "echo $$"], [/* 78 vars */]) = -1 ENOENT (No such file or directory)
[pid 187050] execve("/usr/bin/setsid", ["setsid", "bash", "-c", "echo $$"], [/* 78 vars */]) = 0

Why would there be so many -1 ENOENT (No such file or directory) results?

jcm
  • 233
  • 3
  • 7

1 Answers1

9

It's trying to run the program by calling every potential location in $PATH-order without foreknowledge of where the program is. This is completely normal because doing something like stat() then execve() is considered a race condition by security best practices in a lot of software shops.

Andrew Domaszek
  • 5,163
  • 1
  • 15
  • 27
  • 1
    The libc functions `execlp()` and `execvp()` implement this `PATH` searching. The type of race condition is known as "TOCTOU", time-of-check time-of-use: [CWE-367](http://cwe.mitre.org/data/definitions/367.html) – mr.spuratic Mar 12 '15 at 10:25
  • 1
    Also, there is no point in doing checks first. You would just generate one extra system call. – Simon Richter Mar 12 '15 at 12:39
  • If I recall correctly, execlp and execvp both call a shell to do the path search for you (in the same way). – Andrew Domaszek Mar 12 '15 at 12:50
  • @AndrewDomaszek None of the `exec` functions call a shell. They are all C library functions wrapping around the `execve` system call. The `execve` library call is a very thin wrapper, the other five `exec` functions need more logic and are likely implemented on top of the `execve` library call. The `system` library function does however call a shell. – kasperd Apr 13 '15 at 08:39
  • [IEEE Std 1003.1-2008](http://pubs.opengroup.org/stage7tc1/functions/exec.html) "In the cases where the other members of the exec family of functions would fail and set errno to [ENOEXEC], the execlp() and execvp() functions shall execute a command interpreter and the environment of the executed command shall be as if the process invoked the sh utility using execl() as follows [..]" Spec suggests otherwise... – Andrew Domaszek Apr 13 '15 at 16:15