broker_channel.cc 1001 B

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "sandbox/linux/syscall_broker/broker_channel.h"
  5. #include <sys/socket.h>
  6. #include <sys/types.h>
  7. #include "base/check.h"
  8. namespace sandbox {
  9. namespace syscall_broker {
  10. // static
  11. void BrokerChannel::CreatePair(EndPoint* reader, EndPoint* writer) {
  12. DCHECK(reader);
  13. DCHECK(writer);
  14. int socket_pair[2];
  15. // Use SOCK_SEQPACKET, to preserve message boundaries but we also want to be
  16. // notified (recvmsg should return and not block) when the connection has
  17. // been broken which could mean that the other end has been closed.
  18. PCHECK(0 == socketpair(AF_UNIX, SOCK_SEQPACKET, 0, socket_pair));
  19. reader->reset(socket_pair[0]);
  20. PCHECK(0 == shutdown(reader->get(), SHUT_WR));
  21. writer->reset(socket_pair[1]);
  22. PCHECK(0 == shutdown(writer->get(), SHUT_RD));
  23. }
  24. } // namespace syscall_broker
  25. } // namespace sandbox