summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-09-13 16:16:24 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-09-13 16:16:24 +0000
commit3e2be1aaa3fcc433ee79400409220135a86a716e (patch)
tree937fd81fa9038970e163c3ae559cd7b1ee2c63a3
parentf7de4c0808f05a86ba0924caab062da18fb7a62e (diff)
downloadpx4-nuttx-3e2be1aaa3fcc433ee79400409220135a86a716e.tar.gz
px4-nuttx-3e2be1aaa3fcc433ee79400409220135a86a716e.tar.bz2
px4-nuttx-3e2be1aaa3fcc433ee79400409220135a86a716e.zip
Fix order problem that was causing dup2 to clobber pipe FD and hang
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2046 42af7a65-404d-4744-a932-0658087f49c3
-rwxr-xr-xnuttx/netutils/thttpd/thttpd_cgi.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/nuttx/netutils/thttpd/thttpd_cgi.c b/nuttx/netutils/thttpd/thttpd_cgi.c
index 247a71d0b..94fceff82 100755
--- a/nuttx/netutils/thttpd/thttpd_cgi.c
+++ b/nuttx/netutils/thttpd/thttpd_cgi.c
@@ -660,16 +660,18 @@ static int cgi_child(int argc, char **argv)
argp = make_argp(hc);
- /* Close all file descriptors (including stdio, stdin, stdout) EXCEPT for
- * stderr and hc->conn_fd
+ /* Close all file descriptors EXCEPT for stdin, stdout, stderr and
+ * hc->conn_fd. We'll keep stderr open for error reporting; stdin and
+ * stdout will be closed later by dup2(). Keeping stdin and stdout open
+ * now prevents re-use of fd=0 and 1 by pipe().
*/
- nllvdbg("Closing all descriptors\n");
- for (fd = 0; fd < (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS); fd++)
+ nllvdbg("Closing descriptors\n");
+ for (fd = 3; fd < (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS); fd++)
{
- /* Keep stderr open for debug; keep hc->conn_fd open for obvious reasons */
+ /* Keep hc->conn_fd open for obvious reasons */
- if (fd != 2 && fd != hc->conn_fd)
+ if (fd != hc->conn_fd)
{
close(fd);
}
@@ -939,4 +941,5 @@ int cgi(httpd_conn *hc)
return 0;
}
-#endif /* CONFIG_THTTPD && CONFIG_THTTPD_CGI_PATTERN */ \ No newline at end of file
+#endif /* CONFIG_THTTPD && CONFIG_THTTPD_CGI_PATTERN */
+