Subject: Re: bug#16519: 24.3.50; gfile notifications not received in batch mode

From: Michael Albinus <[email-masked]>
Date: Fri, 24 Jan 2014 12:23:44 +0100

Eli Zaretskii <[email-masked]> writes:

>> File notifications via gfilenotify are not received in batch
>> mode. Likely, the following actions must be taken (quoting Jan Djärv):
>>
>>   So just switching to xg_select will not do.  You have to explicitly
>>   check if in batch mode, then check if GLib has file descriptors we
>>   don't know about, and then call xg_select in the main thread.
>
> You will see that I needed to do something very similar for the w32
> build.

Thanks for the pointer.

However, gio's file notifications are not handled by selects, AFAIU. The
events are put into the main context of glib, and must be read by
g_main_context_dispatch.

In the interactive case, this is done by xg_select indeed, but that is
activated by other file descriptors not related to the file
notifications machinery. So we must apply g_main_context_dispatch
somewhere in Emacs' main loop, when we are in noninteractive mode.

I'm not so skilled with the main loop, so I have no idea where to
do. When I add something like this in wait_reading_process_output, I
don't get the file notification events, but an error message:

#if defined (HAVE_GLIB)
      if (noninteractive)
      {
        GMainContext *context;
        context = g_main_context_default ();
        while (g_main_context_pending (context))
          g_main_context_dispatch (context);
      }
#endif

The error message is

(file-error "Failed select" "resource temporarily unavailable")

I don't know what to check further :-( Maybe some missing initialization?

Best regards, Michael.