Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(574)

Side by Side Diff: services/native_support/make_pty_pair.cc

Issue 1321253010: Add a "native_support" service. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: fix android? Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 "services/native_support/make_pty_pair.h"
6
7 #include <errno.h>
8 #include <fcntl.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11
12 #include "base/logging.h"
13 #include "base/posix/eintr_wrapper.h"
14
15 namespace native_support {
16
17 bool MakePtyPair(base::ScopedFD* master_fd,
18 base::ScopedFD* slave_fd,
19 int* errno_value) {
20 DCHECK(master_fd);
21 DCHECK(!master_fd->is_valid()); // Not very wrong, but unlikely.
22 DCHECK(slave_fd);
23 DCHECK(!slave_fd->is_valid()); // Not very wrong, but unlikely.
24 DCHECK(errno_value);
25
26 // TODO(vtl): |getpt()| is a glibc extension.
27 base::ScopedFD master(getpt());
28 if (!master.is_valid()) {
29 *errno_value = errno;
30 PLOG(ERROR) << "getpt()";
31 return false;
32 }
33
34 if (grantpt(master.get()) < 0) {
35 *errno_value = errno;
36 PLOG(ERROR) << "grantpt()";
37 return false;
38 }
39
40 if (unlockpt(master.get()) < 0) {
41 *errno_value = errno;
42 PLOG(ERROR) << "unlockpt()";
43 return false;
44 }
45
46 const char* name = ptsname(master.get());
47 if (!name) {
48 *errno_value = errno;
49 PLOG(ERROR) << "ptsname()";
50 return false;
51 }
52
53 base::ScopedFD slave(HANDLE_EINTR(open(name, O_RDWR)));
54 if (!slave.is_valid()) {
55 *errno_value = errno;
56 PLOG(ERROR) << "open()";
57 return false;
58 }
59
60 *master_fd = master.Pass();
61 *slave_fd = slave.Pass();
62 return true;
63 }
64
65 } // namespace native_support
OLDNEW
« no previous file with comments | « services/native_support/make_pty_pair.h ('k') | services/native_support/process_controller_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698