'Delay in wayland socket access

I am working on a project where I want to use Weston and a wayland client(myapp) trying to connect to it right after Weston is started on startup.

Below are few lines from my startup script.


    export XDG_RUNTIME_DIR=/tmp/mydir
    /weston &
    /myapp &

I have set the env variable "XDG_RUNTIME_DIR=/tmp/mydir" properly. The weston and the wayland client both as access to the path set in 'XDG_RUNTIME_DIR'.

So the weston creates the socket as "PATH/wayland-0". But the client trying to connect to this fails with error "No such file or directory".

Following this https://unix.stackexchange.com/a/539011/514997 I tried to add sleep of 2 between client(myapp) start and weston launch, it works fine.

My question is:

  1. Why is this sleep required at all? I know the socket file is not available by the time the client is trying to connect to it. But is this normal with Weston and wayland client?
  2. How much time does it take to create the socket file?
  3. Is there any better solution than using sleep.

PS: Same issue observed with QT application which uses wayland.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source