{"action":"created","issue":{"url":"https://api.github.com/repos/civetweb/civetweb/issues/296","repository_url":"https://api.github.com/repos/civetweb/civetweb","labels_url":"https://api.github.com/repos/civetweb/civetweb/issues/296/labels{/name}","comments_url":"https://api.github.com/repos/civetweb/civetweb/issues/296/comments","events_url":"https://api.github.com/repos/civetweb/civetweb/issues/296/events","html_url":"https://github.com/civetweb/civetweb/issues/296","id":147208904,"number":296,"title":"POST data to CGI-script does not receive EO","user":{"login":"kriztioan","id":18376356,"avatar_url":"https://avatars.githubusercontent.com/u/18376356?v=3","gravatar_id":"","url":"https://api.github.com/users/kriztioan","html_url":"https://github.com/kriztioan","followers_url":"https://api.github.com/users/kriztioan/followers","following_url":"https://api.github.com/users/kriztioan/following{/other_user}","gists_url":"https://api.github.com/users/kriztioan/gists{/gist_id}","starred_url":"https://api.github.com/users/kriztioan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kriztioan/subscriptions","organizations_url":"https://api.github.com/users/kriztioan/orgs","repos_url":"https://api.github.com/users/kriztioan/repos","events_url":"https://api.github.com/users/kriztioan/events{/privacy}","received_events_url":"https://api.github.com/users/kriztioan/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2016-04-10T09:21:58Z","updated_at":"2016-04-19T20:31:34Z","closed_at":null,"body":"When sending POST-data to a CGI-script, EOF is not received through STDIN because the write end of the pipe is not closed by the child process after forking [and before replacing the process image with that of the CGI-script]. In other words, read keeps blocking in the CGI-script. Note that the read end in the parent is properly closed. A straightforward fix is to have spawn_process in civetweb.c receive the fdin [and other file-descriptors] as the pipe-array[s]:\r\n\r\n`spawn_process(struct mg_connection *conn,\r\n              const char *prog,\r\n              char *envblk,\r\n              char *envp[],\r\n              int fdin[2],\r\n              int fdout[2],\r\n              int fderr[2],\r\n              const char *dir)`\r\n\r\nThe child then simply closes fdin[1], fdout[0] and fderr[0]; in essence both ends of fdin, fdout and fderr are closed, as the read, write and write ends are duplicated to STDIN, STDOUT and STDERR of the child process, respectively.\r\n\r\n`(void)close(fdin[0]);\r\n (void)close(fdout[1]);\r\n (void)close(fderr[1]);\r\n (void)close(fdin[1]);\r\n (void)close(fdout[0]);\r\n (void)close(fderr[0]); `\r\n\r\nhandle_cgi_request` then calls spawn_process as:\r\n\r\n`pid = spawn_process(conn, p, blk.buf, blk.var, fdin, fdout, fderr, dir);`\r\n\r\nI am using the civetweb under Mac/OSX as an embedded web server."},"comment":{"url":"https://api.github.com/repos/civetweb/civetweb/issues/comments/212115014","html_url":"https://github.com/civetweb/civetweb/issues/296#issuecomment-212115014","issue_url":"https://api.github.com/repos/civetweb/civetweb/issues/296","id":212115014,"user":{"login":"bel2125","id":5619191,"avatar_url":"https://avatars.githubusercontent.com/u/5619191?v=3","gravatar_id":"","url":"https://api.github.com/users/bel2125","html_url":"https://github.com/bel2125","followers_url":"https://api.github.com/users/bel2125/followers","following_url":"https://api.github.com/users/bel2125/following{/other_user}","gists_url":"https://api.github.com/users/bel2125/gists{/gist_id}","starred_url":"https://api.github.com/users/bel2125/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bel2125/subscriptions","organizations_url":"https://api.github.com/users/bel2125/orgs","repos_url":"https://api.github.com/users/bel2125/repos","events_url":"https://api.github.com/users/bel2125/events{/privacy}","received_events_url":"https://api.github.com/users/bel2125/received_events","type":"User","site_admin":false},"created_at":"2016-04-19T20:31:34Z","updated_at":"2016-04-19T20:31:34Z","body":"I think for Windows, the handles must be explicitly set to \"do not inherit\":\r\n\r\n```\r\n\t/* Mark handles that should not be inherited. See\r\n\t * https://msdn.microsoft.com/en-us/library/windows/desktop/ms682499%28v=vs.85%29.aspx\r\n\t */\r\n\tSetHandleInformation((HANDLE)_get_osfhandle(fdin[1]),\r\n\t                     HANDLE_FLAG_INHERIT,\r\n\t                     0);\r\n\tSetHandleInformation((HANDLE)_get_osfhandle(fdout[0]),\r\n\t                     HANDLE_FLAG_INHERIT,\r\n\t                     0);\r\n\tSetHandleInformation((HANDLE)_get_osfhandle(fderr[0]),\r\n\t                     HANDLE_FLAG_INHERIT,\r\n\t                     0);\r\n```\r\n\r\nThis seems to work in a first test.\r\n\r\nNext I'm trying to get the test running on the Travis CI environment as well.\r\n"}}