psplash-fb: Avoid racing issues on reading fb0
PATCH 1/1 psplash-fb: Avoid racing issues on reading fb0
When starting psplash as early as possible in the boot process, the fb device node might not be ready. This patch adds a loop on reading the fb0 device with a timeout of 5 seconds.
--- psplash-fb.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
psplash-fb.c +4 -1
@@ -137,6 +137,7 @@ psplash_fb_new (int angle, int fbdev_id)struct fb_fix_screeninfo fb_fix;int off;char fbdev[9 ] ="/dev/fb0" ; +int retries =0 ;PSplashFB *fb =NULL ;
@@ -156,7 +157,9 @@ psplash_fb_new (int angle, int fbdev_id) fb->fd =-1 ; -if ((fb->fd =open (fbdev,O_RDWR )) <0 ) +while ((fb->fd =open (fbdev,O_RDWR )) <0 && retries++ <=100 ) +usleep (50000 ); +if (fb->fd <0 ) { fprintf(stderr, "Error opening %s\n",
Signature · 1 line
2.17.1
Quoted 22 lines · Andrei Gherzan
When starting psplash as early as possible in the boot process, the fb device node might not be ready. This patch adds a loop on reading the fb0 device with a timeout of 5 seconds.
Signed-off-by Andrei Gherzan <[email protected]>--- psplash-fb.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)psplash-fb.c +1
-0@@ -137,6 +137,7 @@ psplash_fb_new (int angle, int fbdev_id)struct fb_fix_screeninfo fb_fix;int off;char fbdev[9 ] ="/dev/fb0" ; +int retries =0 ;PSplashFB *fb =NULL ;
psplash-fb.c psplash_fb_new (int angle, int fbdev_id) · line 162
Quoted 7 lines
psplash-fb.c +3
-1@@ -156,7 +157,9 @@ psplash_fb_new (int angle, int fbdev_id) fb->fd =-1 ; -if ((fb->fd =open (fbdev,O_RDWR )) <0 ) +while ((fb->fd =open (fbdev,O_RDWR )) <0 && retries++ <=100 ) +usleep (50000 ); +if (fb->fd <0 )
i wonder if there should be a different way to ensure this dependency perhaps sd_notify for systemd or udev notification maybe ..
Quoted 7 lines
psplash-fb.c +0
-0{ fprintf(stderr, "Error opening %s\n",
Hi,
Quoted 26 lines · Khem Raj
Quoted 25 lines · Andrei Gherzan
When starting psplash as early as possible in the boot process, the fb device node might not be ready. This patch adds a loop on reading the fb0 device with a timeout of 5 seconds.
Signed-off-by Andrei Gherzan <[email protected]>--- psplash-fb.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)psplash-fb.c +1
-0@@ -137,6 +137,7 @@ psplash_fb_new (int angle, int fbdev_id)struct fb_fix_screeninfo fb_fix;int off;char fbdev[9 ] ="/dev/fb0" ; +int retries =0 ;PSplashFB *fb =NULL ;@@ -156,7 +157,9 @@ psplash_fb_new (int angle, int fbdev_id) fb->fd =-1 ;
Quoted 8 lines
psplash-fb.c psplash_fb_new (int angle, int fbdev_id) · line 162
Quoted 4 lines
psplash-fb.c +3
-1-if ((fb->fd =open (fbdev,O_RDWR )) <0 ) +while ((fb->fd =open (fbdev,O_RDWR )) <0 && retries++ <=100 ) +usleep (50000 ); +if (fb->fd <0 )i wonder if there should be a different way to ensure this dependency perhaps
sd_notifyfor systemd or udev notification maybe ..
That makes sense. The only issue is that in my use-case, initramfs doesn't have systemd. And usually, you will be wanting to run a splash way before any init system. What is your proposal with udev notifications? Can you expand that?
Regards,
Andrei
Quoted 41 lines · Andrei Gherzan
Hi,
On Fri, Feb 14, 2020 at 7:32 AM Khem Raj <[email protected] <mailto:[email protected]>> wrote:
On 2/13/20 2:30 AM, Andrei Gherzan wrote: > When starting psplash as early as possible in the boot process, the fb > device node might not be ready. This patch adds a loop on reading the > fb0 device with a timeout of 5 seconds. > > Signed-off-by: Andrei Gherzan <[email protected] <mailto:[email protected]>> > --- > psplash-fb.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/psplash-fb.c b/psplash-fb.c > index 6603572..6700a3b 100644 > --- a/psplash-fb.c > +++ b/psplash-fb.c > @@ -137,6 +137,7 @@ psplash_fb_new (int angle, int fbdev_id) > struct fb_fix_screeninfo fb_fix; > int off; > char fbdev[9] = "/dev/fb0"; > + int retries = 0; > > PSplashFB *fb = NULL; > > @@ -156,7 +157,9 @@ psplash_fb_new (int angle, int fbdev_id) > > fb->fd = -1; > > - if ((fb->fd = open (fbdev, O_RDWR)) < 0) > + while ((fb->fd = open(fbdev, O_RDWR)) < 0 && retries++ <= 100) > + usleep(50000); > + if (fb->fd < 0) i wonder if there should be a different way to ensure this dependency perhaps sd_notify for systemd or udev notification maybe ..
Quoted 2 lines
That makes sense. The only issue is that in my use-case, initramfs doesn't have systemd. And usually, you will be wanting to run a splash way before any init system. What is your proposal with udev notifications? Can you expand that?
something like https://www.tecmint.com/udev-for-device-detection-management-in-linux/
Quoted 2 lines
Regards,
Andrei