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

Side by Side Diff: sandbox/linux/services/scoped_process.cc

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sandbox/linux/services/scoped_process.h" 5 #include "sandbox/linux/services/scoped_process.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <signal.h> 8 #include <signal.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 #include <sys/syscall.h> 10 #include <sys/syscall.h>
(...skipping 21 matching lines...) Expand all
32 } 32 }
33 } 33 }
34 34
35 } // namespace 35 } // namespace
36 36
37 ScopedProcess::ScopedProcess(const base::Closure& child_callback) 37 ScopedProcess::ScopedProcess(const base::Closure& child_callback)
38 : child_process_id_(-1), process_id_(getpid()) { 38 : child_process_id_(-1), process_id_(getpid()) {
39 PCHECK(0 == pipe(pipe_fds_)); 39 PCHECK(0 == pipe(pipe_fds_));
40 #if !defined(THREAD_SANITIZER) 40 #if !defined(THREAD_SANITIZER)
41 // Make sure that we can safely fork(). 41 // Make sure that we can safely fork().
42 CHECK(ThreadHelpers::IsSingleThreaded(-1)); 42 CHECK(ThreadHelpers::IsSingleThreaded());
43 #endif 43 #endif
44 child_process_id_ = fork(); 44 child_process_id_ = fork();
45 PCHECK(0 <= child_process_id_); 45 PCHECK(0 <= child_process_id_);
46 46
47 if (0 == child_process_id_) { 47 if (0 == child_process_id_) {
48 PCHECK(0 == IGNORE_EINTR(close(pipe_fds_[0]))); 48 PCHECK(0 == IGNORE_EINTR(close(pipe_fds_[0])));
49 pipe_fds_[0] = -1; 49 pipe_fds_[0] = -1;
50 child_callback.Run(); 50 child_callback.Run();
51 // Notify the parent that the closure has run. 51 // Notify the parent that the closure has run.
52 CHECK_EQ(1, HANDLE_EINTR(write(pipe_fds_[1], kSynchronisationChar, 1))); 52 CHECK_EQ(1, HANDLE_EINTR(write(pipe_fds_[1], kSynchronisationChar, 1)));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 // It would be problematic if after a fork(), another process would start using 111 // It would be problematic if after a fork(), another process would start using
112 // this object. 112 // this object.
113 // This method allows to assert it is not happening. 113 // This method allows to assert it is not happening.
114 bool ScopedProcess::IsOriginalProcess() { 114 bool ScopedProcess::IsOriginalProcess() {
115 // Make a direct syscall to bypass glibc caching of PIDs. 115 // Make a direct syscall to bypass glibc caching of PIDs.
116 pid_t pid = sys_getpid(); 116 pid_t pid = sys_getpid();
117 return pid == process_id_; 117 return pid == process_id_;
118 } 118 }
119 119
120 } // namespace sandbox 120 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/linux/services/resource_limits_unittests.cc ('k') | sandbox/linux/services/syscall_wrappers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698