lib/ffi/libfuse/fuse_common.rb in ffi-libfuse-0.3.4 vs lib/ffi/libfuse/fuse_common.rb in ffi-libfuse-0.4.0

- old
+ new

@@ -50,15 +50,17 @@ -1 ensure teardown end - # @api private # @param [Boolean] foreground # @param [Boolean] single_thread - # @param [Hash<String,Proc>] traps see {Ackbar.trap} - # + # @param [Hash<String,Proc|nil>] traps as per Signal.trap + # these are merged over {default_traps} for INT, HUP, TERM that unmount and exit filesystem. A nil + # value for these default signals will leave any existing signal handle in place. + # @param [Integer] remember fuse cache timeout + # @api private # Implement fuse loop in ruby # # Pros: # # * multi-threading works @@ -69,10 +71,11 @@ # Cons: # # * clone_fd is ignored # * filesystem interrupts probably can't work def run_ruby(foreground: true, single_thread: true, traps: {}, remember: false, **options) + traps = default_traps.merge(traps).keep_if { |_, v| v } Ackbar.trap(default_traps.merge(traps)) do |signals| daemonize unless foreground # Monitor for signals (and cache cleaning if required) signals.monitor { fuse_cache_timeout(remember) } @@ -110,11 +113,13 @@ ensure (se = session) && Libfuse.fuse_remove_signal_handlers(se) end # Ruby implementation of fuse default traps - # @see Ackbar + # + # * INT, HUP, TERM, TSTP to unmount and exit filesystem + # * PIPE is ignored def default_traps exproc = ->(signame) { exit(signame) } @default_traps ||= { INT: exproc, HUP: exproc, TERM: exproc, TSTP: exproc, PIPE: 'IGNORE' } end @@ -188,9 +193,10 @@ def safe_fuse_process # sometimes we get null on unmount, and exit needs a chance to finish to avoid hangs fuse_process || (sleep(0.1) && false) end + # @!visibility private def teardown return unless @fuse self.exit&.join