Fix timeout handler and gid/uid checking