Making sshfs friendlier
I’ve wanted to make a nice friendly front-end to sshfs and various other mount-related programs for a while. The other day I finally realised that I could do it via a launcher on the xfce4 panel.
Creating the launcher is easy enough. One button does an sshfs mount, in a terminal so that a password can be supplied. Another unmounts. The problem is that it all works beautifully in a test environment, but doesn’t work at all when run from the launcher. Why?!?
It turns out that as soon as the pseudo-terminal (pty) that sshfs was run from is obliterated (eg by closing the window, which happens automatically when a launcher runs something in a terminal), all the processes attached to it are killed.
Solving this took quite a while, particularly since I wasn’t about to install and learn `screen’ or some other program for such a trivial task, and other ideas like double-forking were a wild goose chase. In the end it looks like this:
bash -c ’trap "" SIGHUP && sshfs user@machine:/some/path /home/me/sshfs && rox /home/me/sshfs’
Bash is used to put the rest of the commandline into a new shell. Then `trap’ traps the SIGHUP signal that’s normally sent to the process when its pty disappears, the sshfs command is run, and the mountpoint is opened in a file manager window for good measure.
Posted Tuesday, June 19, 2012