I am building a libfcgi-based fastcgi application to provide “smart HTTP” transfers in git. To do so, I currently need to fork and exec the git-upload-pack program. The only issue is that libfcgi replaces STDOUT and STDERR with special FCGI file descriptors and git is not aware of these. I want to be able to capture the output of the git program (stdout & stderr) in the parent process so I can send it to the server.
I am building a libfcgi-based fastcgi application to provide smart HTTP transfers in git.
Share
After you called fork() and prior to calling exec() do the following: call close() on fds 1 and 2 (which is stdout and stderr) and then call dup2() to assign fds of STDOUT and STDERR of libfcgi new fds: 1 and 2. Then you can close original fds of STDOUT and STDERR (they will be closed only for exec’ed git program, but will still be open in your main).
This should reassign output of git to libfcgi streams. If you want to read streams manually and send data by yourself you can either use pipe() call to create a pair of fds so git can write to one, and you read from another. Or just use popen() which can do this for you (but it won’t let you work with stderr)