One possible fly in the ointment: if there's ever any other flags for SETFD aside from CLOEXEC, this should use a F_GETFD call to find the prior flags, then use FD_CLOEXEC | the prior value here.  But ISTR there is no other flag at present, so I suspect you're good.