poll.2: Set fd to its bitwise complement to ignore
PATCH 1/1 poll.2: Set fd to its bitwise complement to ignore
Unlike negating the fd, this works even for fd 0. It is a better fix for
https://bugzilla.kernel.org/show_bug.cgi?id=79411.
--- man2/poll.2 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
man2/poll.2 +2 -3
@@ -83,10 +83,9 @@ field returns zero. (This provides an easy way of ignoring a file descriptor for a single .BR poll () -call: simply negate the +call: simply set the .I fd -field. -Note, however, that this technique can't be used to ignore file descriptor 0.) +field to its bitwise complement.) .PP The field .I events
PATCH RESEND 1/1 poll.2: Set fd to its bitwise complement to ignore
Unlike negating the fd, this works even for fd 0. It is a better fix for
https://bugzilla.kernel.org/show_bug.cgi?id=79411.
--- man2/poll.2 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
man2/poll.2 +2 -3
@@ -83,10 +83,9 @@ field returns zero. (This provides an easy way of ignoring a file descriptor for a single .BR poll () -call: simply negate the +call: simply set the .I fd -field. -Note, however, that this technique can't be used to ignore file descriptor 0.) +field to its bitwise complement.) .PP The field .I events
Hi David,
Quoted 4 lines · David Ward
Unlike negating the fd, this works even for fd 0. It is a better fix for
https://bugzilla.kernel.org/show_bug.cgi?id=79411.Signed-off-by David Ward <[email protected]>
Thanks for the patch.
Could you please add some more detailed explanation of how this works better in the commit message?
I kind of imagine why, but I'm not very inspired at the moment to do some calculations, and would like to see some example numbers to visualize it and make sure I'm getting it right.
Thanks,
Alex
Quoted 21 lines
--- man2/poll.2 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)man2/poll.2 +2
-3@@ -83,10 +83,9 @@ field returns zero. (This provides an easy way of ignoring a file descriptor for a single .BR poll () -call: simply negate the +call: simply set the .I fd -field. -Note, however, that this technique can't be used to ignore file descriptor 0.) +field to its bitwise complement.) .PP The field .I events
Signature · 2 lines
Alejandro Colomar <http://www.alejandro-colomar.es/>
PATCH v2 1/1 poll.2: Set fd to its bitwise complement to ignore
A valid file descriptor will be non-negative, i.e., 0 <= fd <= INT_MAX. When all of the bits of a valid file descriptor are flipped, the result is a negative value: ~0 = -1, ~1 = -2, ..., ~INT_MAX = INT_MIN. If all of these bits are flipped again, then the file descriptor is recovered.
Negating the file descriptor does not quite achieve this, because there will be no change for fd 0. (Likewise, negating INT_MIN would not cause any change in value, but it is never a valid file descriptor.)
--- man2/poll.2 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
man2/poll.2 +2 -3
@@ -83,10 +83,9 @@ field returns zero. (This provides an easy way of ignoring a file descriptor for a single .BR poll () -call: simply negate the +call: simply set the .I fd -field. -Note, however, that this technique can't be used to ignore file descriptor 0.) +field to its bitwise complement.) .PP The field .I events
Hi David,
Quoted 11 lines · David Ward
A valid file descriptor will be non-negative, i.e., 0 <= fd <=
INT_MAX. When all of the bits of a valid file descriptor are flipped, the result is a negative value: ~0 = -1, ~1 = -2, ..., ~INT_MAX =INT_MIN. If all of these bits are flipped again, then the file descriptor is recovered.Negating the file descriptor does not quite achieve this, because there will be no change for fd 0. (Likewise, negating
INT_MINwould not cause any change in value, but it is never a valid file descriptor.)
Now it makes a lot of sense :)
Patch applied.
Cheers,
Alex
Quoted 21 lines
--- man2/poll.2 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)man2/poll.2 +2
-3@@ -83,10 +83,9 @@ field returns zero. (This provides an easy way of ignoring a file descriptor for a single .BR poll () -call: simply negate the +call: simply set the .I fd -field. -Note, however, that this technique can't be used to ignore file descriptor 0.) +field to its bitwise complement.) .PP The field .I events
Signature · 3 lines
Alejandro Colomar Linux man-pages comaintainer; http://www.kernel.org/doc/man-pages/ http://www.alejandro-colomar.es/