This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

1.3.22: popen() fails without /bin/sh


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().



Attachment: fails.c
Description: Binary data

Attachment: works.c
Description: Binary data

--
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/

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]