KUDU-378. Fix hang due to malloc() after fork()
KUDU-378. Fix hang due to malloc() after fork()

POSIX specifies that a multithreaded program may only call
async-signal-safe operations from a child process after a fork() and
before an execve() due to the unpredictable state of mutexes and other
data structures accessed by the various threads at the time of the
fork(). In particular, malloc() must be avoided.

It turns out that opendir() calls malloc(), and closedir() calls free(),
so we call opendir() before the fork() call and use the DIR* handle from
the child process. opendir() sets the close-on-exec flag on the file
descriptor underlying the DIR*, and execve() specifies that any open
directory streams are closed when it runs.

readdir64() is not async-signal-safe, but it does not call malloc()
either, and after perusing the eglibc source it seems not to do anything
that would make it unsafe to call after a fork(). See comments for more
discussion.

Change-Id: I8897dafc60ee507f061bc31056fc1060edc322e3
Reviewed-on: http://gerrit.ent.cloudera.com:8080/3302
Tested-by: jenkins
Reviewed-by: Todd Lipcon <2c763d726a8c2f6afda9be7e0e56a2caa6bb5e6b@cloudera.com>

helifu/kudu,EvilMcJerkface/kudu,helifu/kudu,helifu/kudu,andrwng/kudu,InspurUSA/kudu,andrwng/kudu,cloudera/kudu,cloudera/kudu,cloudera/kudu,andrwng/kudu,InspurUSA/kudu,InspurUSA/kudu,cloudera/kudu,EvilMcJerkface/kudu,helifu/kudu,EvilMcJerkface/kudu,helifu/kudu,cloudera/kudu,EvilMcJerkface/kudu,andrwng/kudu,EvilMcJerkface/kudu,EvilMcJerkface/kudu,helifu/kudu,andrwng/kudu,InspurUSA/kudu,cloudera/kudu,InspurUSA/kudu,cloudera/kudu,InspurUSA/kudu,andrwng/kudu,cloudera/kudu,andrwng/kudu,helifu/kudu,andrwng/kudu,cloudera/kudu,andrwng/kudu,InspurUSA/kudu,helifu/kudu,InspurUSA/kudu,EvilMcJerkface/kudu,EvilMcJerkface/kudu,helifu/kudu,InspurUSA/kudu,EvilMcJerkface/kudu