TRQ-2289 - Queues disappeared

- Make sure to check the return code of close() calls
- Change to rename() instead of unlink(), link(), and unlink()