system: fix failing image validation due to EINTR
authorPetr Štetiar <ynezz@true.cz>
Sun, 29 Dec 2019 20:25:33 +0000 (21:25 +0100)
committerPetr Štetiar <ynezz@true.cz>
Sun, 5 Jan 2020 10:45:52 +0000 (11:45 +0100)
commitea45c4a0f07c699aec073f72daa5029438fab2c6
treeca607bf1dc505fa298a68283b9ac124a9d1fd03d
parent4fde955062433d76f0601e0cd86219ce0a2f908a
system: fix failing image validation due to EINTR

It was quite common to see following error during sysupgrade on serial
console:

 Failed to parse JSON: 4

This is happening due to the fact, that validate_firmware_image_call
fork()s then waits in blocking read() for the input from the child
process, but child finishes its tasks and exits, thus emitting SIGCHLD
signal which then leads to the interruption of the blocking read() in
the parent process with EINTR error.

It seems like the recent fixes in the libubox library, particulary in
the jshn sub-component (which empowers json_dump used in the shell
script executed by the child process) made the execution somehow faster,
thus exposing this racy behaviour in the validate_firmware_image_call at
least on RPi-4 (Cortex-A72) target.

So this patch fixes this issue by checking the read() return value and
retrying the read() if interrupted due to the EINTR error.

Ref: http://lists.infradead.org/pipermail/openwrt-devel/2020-January/020994.html
Fixes: e990e215e8a3 ("system: add "validate_firmware_image" ubus method")
Cc: Rafał Miłecki <rafal@milecki.pl>
Tested-by: Kuan-Yi Li <kyli@abysm.org>
Tested-by: Petr Novák <petrn@me.com>
Reported-by: Petr Novák <petrn@me.com>
Reviewed-by: Hauke Mehrtens <hauke@hauke-m.de>
Signed-off-by: Petr Štetiar <ynezz@true.cz>
system.c