Skip to content

Commit

Permalink
fix: handle EINTR correctly in get_cpu_mask_from_sysfs
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I565030d4625ae199cabc4c2ab5eb8ac49ea4dfcb
  • Loading branch information
Benjamin Marzinski via lttng-dev authored and compudj committed May 2, 2024
1 parent 02a024d commit 9922f33
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/compat-smp.h
Expand Up @@ -164,7 +164,7 @@ static inline int get_cpu_mask_from_sysfs(char *buf, size_t max_bytes, const cha

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.
Expand Down

0 comments on commit 9922f33

Please sign in to comment.