fix fd >= 0 handling