1.3.22: popen() fails without /bin/sh

Hanak Michal-r50233 Michal.Hanak@motorola.com
Tue Jun 10 14:07:00 GMT 2003


Hello,

it seems to me that the popen() does not work correctly in applications running on hosts without "/bin/sh" available. 

The Cygwin's popen() should normally work in a way that after vfork(), the execl("/bin/sh"...) is tried first and if it fails, the execlp("sh"...) is tried to find "sh" on PATH. (see source in newlib/libc/posix.c/popen.c, or code lines bellow).

A problem is that the execlp() gets never called because unsuccessful execl() causes vfork-ed child process to exit. Workaround is to use fork() instead of vfork() but this is perhaps too expensive. 

Does anybody face similar problem ? 
Is there any workaround if I want/need to use the built-in popen()?

Many Thanks,
Michal



Just for clarification, this is the sequence in newlib/libc/posix.c/popen.c:

....
execl(_PATH_BSHELL, "sh", "-c", program, NULL);
#ifdef __CYGWIN__
/* On cygwin32, we may not have /bin/sh.  In that
        case, try to find sh on PATH.  */
execlp("sh", "sh", "-c", program, NULL);
#endif
....


Attached there are two example files. The file "fails.c" shows application which fails to spawn simple "pwd" when /bin/sh is not on path. The file "works.c" shows the private popen2() workaround using fork().



-------------- next part --------------
A non-text attachment was scrubbed...
Name: fails.c
Type: application/octet-stream
Size: 355 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20030610/64f2d790/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: works.c
Type: application/octet-stream
Size: 2850 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20030610/64f2d790/attachment-0001.obj>
-------------- next part --------------
--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


More information about the Cygwin mailing list