Ticket #3679 (new defect)

Opened 8 years ago

Last modified 8 years ago

proper forking of xdg-open

Reported by: boruch Owned by:
Priority: minor Milestone: Future Releases
Component: mc-core Version: master
Keywords: xdg-open Cc:
Blocked By: Blocking:
Branch state: no branch Votes for changeset:

Description

The current script /usr/lib/mc/ext.d/doc.sh (and possibly others) invoke xdg-open without properly forking it. The result is that mc can not continue to be used until the spawned process is killed.

The current code (from https://www.midnight-commander.org/browser/misc/ext.d/doc.sh.in, line 190 is:

   ("${MC_XDG_OPEN}" "${MC_EXT_FILENAME}" >/dev/null 2>&1) || \

This is an improvement over the version currently being distributed in debian stable (v4.8.13) in that it doesn't pollute the mc screen with xdg-open's stdout. However, while according to the dash man page, it does spawn and fork a sub-shell, it also waits until that sub-shell exits. The result is that mc switches to its internal shell (ie. the same a performing 'C-o'), and displays 'C-c' at the bottom of the screen. Attempting to 'C-o' back to the file-management window just echos back 'C-o'. Midnight Commander is effectively frozen in its shell window until the launched program exits, or until typing 'C-c' at the mc shell window.

An example of a correct way to fork (ie. what works for me) is:

   if ! "${MC_XDG_OPEN}" "${MC_EXT_FILENAME}" >/dev/null 2>&1 &
   then
     do_open_action "${filetype}"
   fi

This was tested using the version currently being distributed in debian stable (v4.8.13), opening a libreoffice-writer document.

Change History

comment:1 Changed 8 years ago by boruch

  • Priority changed from major to minor

comment:2 Changed 8 years ago by boruch

While my suggested fix does properly fork, it introduces another error; it always exits false and passes control to 'do_open_action'. This isn't always readily apparent, as the two actions may be identical and display over one another; when one exits the first and sees the second, one may think one mis-typed the exit command.

The modified suggested fix is:

eval "${MC_XDG_OPEN}" "${MC_EXT_FILENAME}" >/dev/null 2>&1 &
[ $? -ne 0 ] && do_open_action "${filetype}"
Note: See TracTickets for help on using tickets.