axiak/java_posix_spawn — Issue #1: File Descriptors not always closed.
Author: bxm156
Created: 2012-01-21 20:51:37+00:00
State: open

Hello,

I have encountered an issue with the file descriptors not getting closed. When executing a process, I use a BufferedReader on the InputStream, so that I can read line by line. When the line == null, then that means the file descriptor was closed, and there is no more input. In most cases, this works fine. I recently encounted an issue when I the execve executes a bash script, which uses ifup. When ifup is called, it configures a wireless network using wpa_supplicant. Once a connection has been established, dhclient wlan0 is executed to get a new DHCP address. At the very end of the buffer, the messages are:

ssh stopped/waiting
ssh start/running, process #####

After that, the execution hangs, because while the program script has executed, wpa_supplicant, dhclient, and ssh seem to have a hold on the STDOUT, and do not close it. This prevents the STDOUT from being closed, and therefore readLine will never return null, blocking program execution.

I attempted to correct the problem by modifying binrunner.c, and doing the execvp inside a seperate vfork, and letting the parent process wait till the child has terminated, and then clean up the file descriptors, but I wasn't able to get it to work successfully.

Any help would be greatly appreciated.