unix: call setgoups before calling setuid/setgid

Partial fix for #1093

Shamelessly taken from: https://github.com/mozilla/rust/pull/12085

/cc @indutny

If you have a few milliseconds to spare, it'd be great to get your input, @bnoordhuis.

As for the dropping caps part, I'll need to look into that, doesn't look anywhere straightforward :-/