I created a backup program using Vala, which is specifically designed to do backups into an external disk. It is also designed to allow several users to share the hard disk by storing each user’s backups in different folders, and each one with only permissions for their specific creator (thus other users can’t navigate the backups). It also tries to mount the hard disk automatically if it detects that it is connected but not mounted, to guarantee that in all cases the backups are done correctly.
The problem is that, if the hard disk is mounted automatically when the user enters its session, if (s)he exits, the disk remains mounted as that user, so when entering as another user, that new one won’t be able to access the hard disk.
My idea is to make my app to unmount the hard disk when the user closes the session, thus allowing other users to use the same hard disk.
My question is: how can I detect when the user closes the session?
It is also valid to detect when the application is killed/closed and be able to execute something in that moment (an umount command).