Following PEP 3143, daemon.DaemonContext drops all open file
descriptors by default. This causes arv-mount to fail, because
llfuse.init() opens /dev/fuse, and llfuse.main() uses that file
descriptor. We now daemonize before doing real work to prevent this
unintentional breakage.
This effectively reverts
83c873af. An alternative approach would've
been to call DaemonContext with a preserve_files argument. I decided
against that because I couldn't find a reliable way to determine
which file descriptors llfuse needs. If we really need the daemon to
report errors, and debugging with --foreground isn't sufficient, I
think we should implement proper logging to a file or syslog.
No issue #.
#!/usr/bin/env python
-from arvados_fuse import *
-import arvados
-import subprocess
import argparse
+import arvados
import daemon
+import os
import signal
+import subprocess
+
+from arvados_fuse import *
if __name__ == '__main__':
# Handle command line parameters
exit(rc)
else:
- if args.foreground:
- # Initialize the fuse connection
- llfuse.init(operations, args.mountpoint, opts)
- llfuse.main()
- else:
- # Initialize the fuse connection
- llfuse.init(operations, args.mountpoint, opts)
- with daemon.DaemonContext():
- llfuse.main()
+ os.chdir(args.mountpoint)
+ if not args.foreground:
+ daemon_ctx = daemon.DaemonContext(working_directory='.')
+ daemon_ctx.open()
+ llfuse.init(operations, '.', opts)
+ llfuse.main()