It looks fine, but we don't have interceptors for popen(3), popenve(3), pclose(3). Could you include them together with this patch? Add add a test for popenve(3).
But of course new code can be added as a new revision.
Added assertion verifying that fileno(fp) works.