diff options
6 files changed, 61 insertions, 13 deletions
diff --git a/src/client/linux/crash_generation/crash_generation_client.cc b/src/client/linux/crash_generation/crash_generation_client.cc index 3cc7eb44..6ede7791 100644 --- a/src/client/linux/crash_generation/crash_generation_client.cc +++ b/src/client/linux/crash_generation/crash_generation_client.cc @@ -35,6 +35,7 @@ #include "client/linux/crash_generation/crash_generation_client.h" #include "common/linux/eintr_wrapper.h" +#include "common/linux/ignore_ret.h" #include "common/linux/linux_libc_support.h" #include "third_party/lss/linux_syscall_support.h" @@ -67,12 +68,14 @@ CrashGenerationClient::RequestDump(const void* blob, size_t blob_size) int* p = reinterpret_cast<int*>(CMSG_DATA(hdr)); *p = fds[1]; - HANDLE_EINTR(sys_sendmsg(server_fd_, &msg, 0)); + ssize_t ret = HANDLE_EINTR(sys_sendmsg(server_fd_, &msg, 0)); sys_close(fds[1]); + if (ret <= 0) + return false; // wait for an ACK from the server char b; - HANDLE_EINTR(sys_read(fds[0], &b, 1)); + IGNORE_RET(HANDLE_EINTR(sys_read(fds[0], &b, 1))); return true; } diff --git a/src/client/linux/handler/exception_handler_unittest.cc b/src/client/linux/handler/exception_handler_unittest.cc index 2bad5fb5..3ce93adc 100644 --- a/src/client/linux/handler/exception_handler_unittest.cc +++ b/src/client/linux/handler/exception_handler_unittest.cc @@ -43,6 +43,7 @@ #include "client/linux/minidump_writer/minidump_writer.h" #include "common/linux/eintr_wrapper.h" #include "common/linux/file_id.h" +#include "common/linux/ignore_ret.h" #include "common/linux/linux_libc_support.h" #include "common/tests/auto_tempdir.h" #include "common/using_std_string.h" @@ -88,8 +89,8 @@ static bool DoneCallback(const char* dump_path, int fd = (intptr_t) context; uint32_t len = my_strlen(minidump_id); - HANDLE_EINTR(sys_write(fd, &len, sizeof(len))); - HANDLE_EINTR(sys_write(fd, minidump_id, len)); + IGNORE_RET(HANDLE_EINTR(sys_write(fd, &len, sizeof(len)))); + IGNORE_RET(HANDLE_EINTR(sys_write(fd, minidump_id, len))); sys_close(fd); return true; @@ -703,11 +704,13 @@ CrashHandler(const void* crash_context, size_t crash_context_size, cred->gid = getgid(); cred->pid = getpid(); - HANDLE_EINTR(sys_sendmsg(fd, &msg, 0)); + ssize_t ret = HANDLE_EINTR(sys_sendmsg(fd, &msg, 0)); sys_close(fds[1]); + if (ret <= 0) + return false; char b; - HANDLE_EINTR(sys_read(fds[0], &b, 1)); + IGNORE_RET(HANDLE_EINTR(sys_read(fds[0], &b, 1))); return true; } @@ -772,7 +775,7 @@ TEST(ExceptionHandlerTest, ExternalDumper) { ASSERT_TRUE(WriteMinidump(templ.c_str(), crashing_pid, context, kCrashContextSize)); static const char b = 0; - HANDLE_EINTR(write(signal_fd, &b, 1)); + ASSERT_EQ(1U, (HANDLE_EINTR(write(signal_fd, &b, 1)))); ASSERT_EQ(close(signal_fd), 0); int status; diff --git a/src/client/linux/minidump_writer/linux_ptrace_dumper_unittest.cc b/src/client/linux/minidump_writer/linux_ptrace_dumper_unittest.cc index 6fabfd84..61f21b86 100644 --- a/src/client/linux/minidump_writer/linux_ptrace_dumper_unittest.cc +++ b/src/client/linux/minidump_writer/linux_ptrace_dumper_unittest.cc @@ -52,6 +52,7 @@ #include "client/linux/minidump_writer/minidump_writer_unittest_utils.h" #include "common/linux/eintr_wrapper.h" #include "common/linux/file_id.h" +#include "common/linux/ignore_ret.h" #include "common/linux/safe_readlink.h" #include "common/memory.h" #include "common/using_std_string.h" @@ -343,7 +344,7 @@ TEST(LinuxPtraceDumperTest, LinuxGateMappingIDChild) { close(fds[1]); // Now wait forever for the parent. char b; - HANDLE_EINTR(read(fds[0], &b, sizeof(b))); + IGNORE_RET(HANDLE_EINTR(read(fds[0], &b, sizeof(b)))); close(fds[0]); syscall(__NR_exit); } @@ -395,7 +396,7 @@ TEST(LinuxPtraceDumperTest, FileIDsMatch) { close(fds[1]); // Now wait forever for the parent. char b; - HANDLE_EINTR(read(fds[0], &b, sizeof(b))); + IGNORE_RET(HANDLE_EINTR(read(fds[0], &b, sizeof(b)))); close(fds[0]); syscall(__NR_exit); } diff --git a/src/client/linux/minidump_writer/minidump_writer_unittest.cc b/src/client/linux/minidump_writer/minidump_writer_unittest.cc index be6be139..4f69013a 100644 --- a/src/client/linux/minidump_writer/minidump_writer_unittest.cc +++ b/src/client/linux/minidump_writer/minidump_writer_unittest.cc @@ -44,6 +44,7 @@ #include "client/linux/minidump_writer/minidump_writer_unittest_utils.h" #include "common/linux/eintr_wrapper.h" #include "common/linux/file_id.h" +#include "common/linux/ignore_ret.h" #include "common/linux/safe_readlink.h" #include "common/tests/auto_tempdir.h" #include "common/using_std_string.h" @@ -68,7 +69,7 @@ TEST(MinidumpWriterTest, Setup) { if (child == 0) { close(fds[1]); char b; - HANDLE_EINTR(read(fds[0], &b, sizeof(b))); + IGNORE_RET(HANDLE_EINTR(read(fds[0], &b, sizeof(b)))); close(fds[0]); syscall(__NR_exit); } @@ -132,7 +133,7 @@ TEST(MinidumpWriterTest, MappingInfo) { if (child == 0) { close(fds[1]); char b; - HANDLE_EINTR(read(fds[0], &b, sizeof(b))); + IGNORE_RET(HANDLE_EINTR(read(fds[0], &b, sizeof(b)))); close(fds[0]); syscall(__NR_exit); } @@ -237,7 +238,7 @@ TEST(MinidumpWriterTest, MappingInfoContained) { if (child == 0) { close(fds[1]); char b; - HANDLE_EINTR(read(fds[0], &b, sizeof(b))); + IGNORE_RET(HANDLE_EINTR(read(fds[0], &b, sizeof(b)))); close(fds[0]); syscall(__NR_exit); } diff --git a/src/common/linux/eintr_wrapper.h b/src/common/linux/eintr_wrapper.h index 225311e6..20b6bed1 100644 --- a/src/common/linux/eintr_wrapper.h +++ b/src/common/linux/eintr_wrapper.h @@ -44,4 +44,4 @@ __eintr_result__;\ }) -#endif // ifndef COMMON_LINUX_EINTR_WRAPPER_H_ +#endif // COMMON_LINUX_EINTR_WRAPPER_H_ diff --git a/src/common/linux/ignore_ret.h b/src/common/linux/ignore_ret.h new file mode 100644 index 00000000..f60384bb --- /dev/null +++ b/src/common/linux/ignore_ret.h @@ -0,0 +1,40 @@ +// Copyright (c) 2012 Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef COMMON_LINUX_IGNORE_RET_H_ +#define COMMON_LINUX_IGNORE_RET_H_ + +// Some compilers are prone to warn about unused return values. In cases where +// either a) the call cannot fail, or b) there is nothing that can be done when +// the call fails, IGNORE_RET() can be used to mark the return code as ignored. +// This avoids spurious compiler warnings. + +#define IGNORE_RET(x) do { if (x); } while (0) + +#endif // COMMON_LINUX_IGNORE_RET_H_ |