Comment 13 for bug 138331

Revision history for this message
Chuck Kollars (chuck-ckollars) wrote :

I had the same problem with gutsy and pam_mount. I found that trackerd is neither the only problem (gtk-window-decorator is too) nor the root cause. Improvements to trackerd exit are welcome and should prevent some unrepeatable failures, but they may not deal with the core problem.

It seems that some processes (trackerd for example) are never even notified of a logout by gdm until after pam_mount tries to do a umount. The code in gdm apparently calls pam_close_session() _before_ it signals processes like trackerd. (Note that pam_mount, which actually does the umount, is called from gdm. And pam_mount is called on to do its thing in the middle of the "logout" process; just saying "logout" is too imprecise.) The pam_mount un-mount process is sufficiently error-prone that I wouldn't be surprised if this problem has come up before in other contexts and has a solution known to pam_mount experts.

One possible long-term solution is to manipulate the order of the code in gdm. This seems the cleanest, but it may risk lots of instability and require lots of testing.

One possible short-term (and very configuration-specific solution) is to add an optional invocation of pam_exec.so in /etc/pam.d/gdm to signal TERM to the offending process _before_ the invocation of pam_mount.so.

A cleaner, more robust solution is to add an optional invocation of pam_script.so in /etc/pam.d/gdm. Then supply a generic script that pam_script.so invokes. The possible problem with this approach is that although Ubuntu contains lots and lots of possible pam modules, it does not include pam_script. Obtaining the source as a tarball then compiling it seems to work fine. But the decision of what to "officially support" and what not may be an issue.

What I did for my short-term solution was used a kludge in pam_mount.conf to call a script rather than having to obtain pam_script.so. [The easy solution of using pam_exec.so doesn't work because the same script would be called for _both_ pam_open_session() and pam_close_session(). My kludge with pam_mount.conf is just a way to activate something only on pam_close_session() but not pam_open_session().]

The relevant lines in my /etc/pam.d/pam_mount.conf look like this:
  ...
 ### hijack these unneeded entries to use them for our kludge instead
 ###fusemount /sbin/mount.fuse %(VOLUME) %(MNTPT) "%(before=\"-o\" OPTIONS)"
 ###fuseumount /usr/bin/fusermount -u %(MNTPT)
 fusemount /bin/true
 fuseumount /usr/local/bin/termallonmount %(MNTPT)
  ...
 ### this is a kludge to call our "helper" - these are not real mounts
 ### this kludge specification goes at the end of the file so it's the last/first thing executed
 volume * fuse cube3 & /home/& - - -

I created the script /usr/local/bin/termallonmount as a fairly normal bash script that loops over the results of an 'lsof` and `kill's things, then `sleep`s for a couple seconds to give all the processes time to cleanup. Just be sure not to rely on any environment variables like $HOME (they don't exist in the pam context), and to use some logic to make sure you don't kill important generic processes (like dhclient, termallonmount [yourself]) no matter what test invocation you do.