sys_util: properly convert errors in sock_ctrl_msg

scm_sendmsg() and scm_recvmsg() return negative errors derived from
errnos that are normally positive. When constructing errno::Error from
these error codes we should convert them back into positive values for
error codes to make proper sense.

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

Change-Id: Ibf9065b72602e43cb6badd06f85044329d714276
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/940562
Reviewed-by: Zach Reizner <zachr@chromium.org>
This commit is contained in:
Dmitry Torokhov 2018-02-27 10:26:34 -08:00 committed by chrome-bot
parent 9c7508593d
commit 8b32d55ae2

View file

@ -154,7 +154,7 @@ impl Scm {
};
if write_count < 0 {
Err(Error::new(write_count as i32))
Err(Error::new(-write_count as i32))
} else {
Ok(write_count as usize)
}
@ -201,7 +201,7 @@ impl Scm {
};
if read_count < 0 {
Err(Error::new(read_count as i32))
Err(Error::new(-read_count as i32))
} else {
// Safe because we have unqiue ownership of each fd we wrap with File.
for &fd in &self.fds[0..fd_count] {