Add patch from PR 50067 by David Shao, which comes from FreeBSD ports/Dragonfly overlay, to improve the situation on FreeBSD and Dragonfly.