summary refs log tree commit diff
path: root/sys_util/src/handle_eintr.rs
diff options
context:
space:
mode:
authorDmitry Torokhov <dtor@chromium.org>2018-02-27 16:41:52 -0800
committerchrome-bot <chrome-bot@chromium.org>2018-03-01 16:13:05 -0800
commit3cbbbe68840e738aae957b1b4c0aa2f54178d576 (patch)
tree6edb7505576f8dea7d3c0f125a245669e230fc4c /sys_util/src/handle_eintr.rs
parent8b32d55ae2b8c3a199856759ef16ab7c4435024e (diff)
downloadcrosvm-3cbbbe68840e738aae957b1b4c0aa2f54178d576.tar
crosvm-3cbbbe68840e738aae957b1b4c0aa2f54178d576.tar.gz
crosvm-3cbbbe68840e738aae957b1b4c0aa2f54178d576.tar.bz2
crosvm-3cbbbe68840e738aae957b1b4c0aa2f54178d576.tar.lz
crosvm-3cbbbe68840e738aae957b1b4c0aa2f54178d576.tar.xz
crosvm-3cbbbe68840e738aae957b1b4c0aa2f54178d576.tar.zst
crosvm-3cbbbe68840e738aae957b1b4c0aa2f54178d576.zip
sys_util: do not treat EINTR as negative in handle_eintr
System error codes are positive, we should not try to use the negative
(kernel) form when working with it.

TEST=cargo test --features plugin; cargo test -p sys_util
BUG=None

Change-Id: I8dea773e6148d1814ca0ea5019d5fb7824dc80ac
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/940611
Reviewed-by: Zach Reizner <zachr@chromium.org>
Diffstat (limited to 'sys_util/src/handle_eintr.rs')
-rw-r--r--sys_util/src/handle_eintr.rs14
1 files changed, 7 insertions, 7 deletions
diff --git a/sys_util/src/handle_eintr.rs b/sys_util/src/handle_eintr.rs
index 318afec..af177b7 100644
--- a/sys_util/src/handle_eintr.rs
+++ b/sys_util/src/handle_eintr.rs
@@ -17,14 +17,14 @@ pub trait InterruptibleResult {
 
 impl InterruptibleResult for i32 {
     fn is_interrupted(&self) -> bool {
-        *self == -EINTR
+        *self == EINTR
     }
 }
 
 impl<T> InterruptibleResult for ::Result<T> {
     fn is_interrupted(&self) -> bool {
         match self {
-            &Err(e) if e.errno() == -EINTR => true,
+            &Err(e) if e.errno() == EINTR => true,
             _ => false,
         }
     }
@@ -45,8 +45,8 @@ impl<T> InterruptibleResult for io::Result<T> {
 ///
 /// The given expression `$x` can return
 ///
-/// * `i32` in which case the expression is retried if equal to `-EINTR`.
-/// * `sys_util::Result` in which case the expression is retried if the `Error::errno()` is `-EINTR`.
+/// * `i32` in which case the expression is retried if equal to `EINTR`.
+/// * `sys_util::Result` in which case the expression is retried if the `Error::errno()` is `EINTR`.
 /// * `std::io::Result` in which case the expression is retried if the `ErrorKind` is `ErrorKind::Interrupted`.
 ///
 /// In all cases where the result does not indicate that the expression was interrupted, the result
@@ -155,10 +155,10 @@ mod tests {
         {
             let mut dummy = || {
                 count -= 1;
-                if count > 0 { -EINTR } else { 56 }
+                if count > 0 { EINTR } else { 0 }
             };
             let res = handle_eintr!(dummy());
-            assert_eq!(res, 56);
+            assert_eq!(res, 0);
         }
         assert_eq!(count, 0);
     }
@@ -170,7 +170,7 @@ mod tests {
             let mut dummy = || {
                 count -= 1;
                 if count > 1 {
-                    Err(SysError::new(-EINTR))
+                    Err(SysError::new(EINTR))
                 } else {
                     Ok(101)
                 }