Fixes for FreeBSD

Just funneling this upstream, was submitted to my clone.