Only set socket mode if some specific mode has been requested or
if we want to run with different GID. Also add missing <sys/stat.h>
include to avoid compiler warning.