Hi Stuart,

Stuart Henderson wrote on Fri, Oct 29, 2021 at 10:53:41AM +0100:
> On 2021/10/28 23:19, Klemens Nanni wrote:
>> On Fri, Oct 29, 2021 at 12:57:54AM +0200, Ingo Schwarze wrote:

>>>   MANPAGER=firefox man -T html $(ifconfig -C)

>> This doesn't work if firefox is already running as the MANPAGER firefox
>> process exits immediately after sending the file/link to the running
>> process, which causes mandoc to exit after removing the temporary file,
>> by which time firefox fails to open the no longer exiting file.
>> 

> I use mutt_bgrun for things like this

I don't see how that can possibly help.  Accoring to
  https://gist.github.com/tabletick/4129818 ,
the mutt_bgrun program essentially does this:

        cp "$file" "$tmpfile"
        (
                "$viewer" $options "$tmpfile"
                rm -f "$tmpfile"
                rmdir "$tmpdir"
        ) &

Assume that $file is the temporary HTML file written by man(1),
$tmpfile is the temporary filename (very poorly) generated
by mutt_bgrun, $viewer is firefox and $options is empty.

Then mutt_bgrun is defeated by the firefox bug that i described
in exactly the same way as that bug defeats man(1) itself.
The following sequence of events will sometimes occur:

 1. man(1) writes $file
 2. man(1) calls mutt_bgrun
 3. mutt_bgrun copies $file to $tmpfile
 4. mutt_bgrun spawns a subshell in the background
 5. mutt_bgrun exits
 6. man(1) deletes $file, which is harmless at this point
    because $tmpfile still exists
 7. man(1) exits

 8. the mutt_bgrun subshell calls firefox
 9. That temporary firefox process hands the $tmpfile name
    to the main running firefox application via IPC.
 10. the mutt_bgrun subshell deletes "$tmpfile"
 11. the mutt_bgrun subshell exits

Then, much later, because firefox is a monster and a slug:

 12. firefox attempts to open "$tmpfile",
     which was already deleted long before

If i understand correctly, mutt_bgrun is designed to solve
exactly the opposite problem we are having here:  When a viewer
(like, for example, xpdf(1)) blocks the formatter (like, for
example, mutt(1) or man(1)) until the user exits the viewer,
then mutt_bgrun does the job of putting the viewer into the
background such that the formatter can proceed before the user
exits the viewer.

But the problem here is that firefox is already doing too much
in the background (specifically, opening the $file, which it
really ought to do in the foreground before returning), not that
it does too little in the background.

Yours,
  Ingo

Reply via email to