From: Mathieu Desnoyers Date: Thu, 2 May 2024 14:41:49 +0000 (-0400) Subject: fix: handle EINTR correctly in get_cpu_mask_from_sysfs X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=7e06b1378b72fb9c3c28a91162dbae9801c5479f;p=lttng-ust.git fix: handle EINTR correctly in get_cpu_mask_from_sysfs If the read() in get_cpu_mask_from_sysfs() fails with EINTR, the code is supposed to retry, but the while loop condition has (bytes_read > 0), which is false when read() fails with EINTR. The result is that the code exits the loop, having only read part of the string. Use (bytes_read != 0) in the while loop condition instead, since the (bytes_read < 0) case is already handled in the loop. Original fix in liburcu from Benjamin Marzinski : commit 9922f33e2986 ("fix: handle EINTR correctly in get_cpu_mask_from_sysfs") Signed-off-by: Mathieu Desnoyers Change-Id: I885a0fb98e5a7cfb9a8bd180c8e64b20926ff58c --- diff --git a/libringbuffer/smp.c b/libringbuffer/smp.c index 73804b66..8a65c405 100644 --- a/libringbuffer/smp.c +++ b/libringbuffer/smp.c @@ -142,7 +142,7 @@ int get_possible_cpu_mask_from_sysfs(char *buf, size_t max_bytes) total_bytes_read += bytes_read; assert(total_bytes_read <= max_bytes); - } while (max_bytes > total_bytes_read && bytes_read > 0); + } while (max_bytes > total_bytes_read && bytes_read != 0); /* * Make sure the mask read is a null terminated string.