lib/debug: fix fd check before dup'ing to stderr