Rewrite semaphore cleanup in exit_proc