[gtk-server] Re: busy loop on startup with fifo method

  • From: Peter van Eerten <administrator@xxxxxxxxxxxxxx>
  • To: gtk-server@xxxxxxxxxxxxx, Frantisek Dufka <dufkaf@xxxxxxxxx>
  • Date: Mon, 16 Apr 2007 18:11:23 +0200

Hi Frantisek,

Thanks for your feedback!

The lack of a '|&' in BASH indeed is a bit annoying. The FIFO-interface can be used instead, but personally, I find it a little bit clumsy too.

Therefore, I would recommend using the IPC interface instead. It is one of the reasons that this interface exists at all, because I wanted to have a good protocol for BASH as well.

For your second suggestion, I did not implement it this way, because the logic I tried to follow for the FIFO-interface is that the GTK-server creates the file and also cleans it up after exit; the programmer should not be worried about creating and cleaning up FIFO files. But maybe I should leave this logic.

But your first suggestion is a good idea, I think. I am already working on 2.1.4 and will make the necessary changes according to your remarks.

Thanks again,

Regards
Peter

Quoting Frantisek Dufka <dufkaf@xxxxxxxxx>:

Hello,

I tried gtk-server from busybox shell and since it doesn't support |&
two-way pipe method the second best method to use seems to be FIFO.

The only clumsy thing is waiting for the fifo to be created at startup.
The bash example runs gtk-server via & and then busy loops waiting for
fifo file to appear while burning CPU (forking true command) and
slowing gtk-server startup.

# Start gtk-server
gtk-server fifo=$PIPE log &
# Wait for the server to initialize
while [ ! -p $PIPE ]; do true; done

I tried to make fifo if advance but gtk-server doesn't like it. Since
there is also no sleep shell command with milisecond precision there is
no easy way to wait without burning CPU.

It would be nice to have some functionality helping with this. Some ideas:

1. Fork gtk-server to background after fifo is created so you could use
something like

gtk-server fifo=$PIPE log detach
gtk "gtk_init NULL NULL"

2. Allow gtk-server to use pre-created fifo file (via mkfifo) so client
doesn't need to loop waiting for file to appear.

mkfifo $PIPE
gtk-server fifo=$PIPE log &
gtk "gtk_init NULL NULL"

I tried to simply comment out Print_Error on line 2926
        //Print_Error("%s%s", 2, "Could not create FIFO! ERROR:
",strerror(errno)); and it works exactly as expected solving this
problem. Is there some reason why this is not a good idea?

Or is there some easy way to wait for fifo file to appear without busy
loop? Thanks a lot and thanks for gtk-server.


Frantisek

--
http://www.gtk-server.org

Other related posts: