I forgot to include O_PATH, which (in combination with O_NOFOLLOW) is required for opening a symbolic link. See revised patch in attachment.