main unix: Cleanup shm code

* Upstream patch by asvitkine
  407edc8bfd3c6abc5da36392f8e4f5fa86b59a66