move atexit code to xexit() and fix ftrunc order for mtime.