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
5#include "sandbox/linux/syscall_broker/broker_channel.h"
6
7#include <sys/socket.h>
8#include <sys/types.h>
9
10#include "base/logging.h"
11
12namespace sandbox {
13
14namespace syscall_broker {
15
16// static
17void BrokerChannel::CreatePair(EndPoint* reader, EndPoint* writer) {
18  DCHECK(reader);
19  DCHECK(writer);
20  int socket_pair[2];
21  // Use SOCK_SEQPACKET, to preserve message boundaries but we also want to be
22  // notified (recvmsg should return and not block) when the connection has
23  // been broken which could mean that the other end has been closed.
24  PCHECK(0 == socketpair(AF_UNIX, SOCK_SEQPACKET, 0, socket_pair));
25
26  reader->reset(socket_pair[0]);
27  PCHECK(0 == shutdown(reader->get(), SHUT_WR));
28
29  writer->reset(socket_pair[1]);
30  PCHECK(0 == shutdown(writer->get(), SHUT_RD));
31}
32
33}  // namespace syscall_broker
34
35}  // namespace sandbox
36