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

Side by Side Diff: base/process_util_linux.cc

Issue 159275: Linux: Use _exit() instead of exit() in the child after fork() in failure conditions. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | base/process_util_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2008 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 "base/process_util.h" 5 #include "base/process_util.h"
6 6
7 #include <ctype.h> 7 #include <ctype.h>
8 #include <dirent.h> 8 #include <dirent.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <sys/types.h> 10 #include <sys/types.h>
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 it != environ.end(); ++it) { 106 it != environ.end(); ++it) {
107 if (it->first) { 107 if (it->first) {
108 if (it->second) { 108 if (it->second) {
109 setenv(it->first, it->second, 1); 109 setenv(it->first, it->second, 1);
110 } else { 110 } else {
111 unsetenv(it->first); 111 unsetenv(it->first);
112 } 112 }
113 } 113 }
114 } 114 }
115 115
116 // Obscure fork() rule: in the child, if you don't end up doing exec*(),
117 // you call _exit() instead of exit(). This is because _exit() does not
118 // call any previously-registered (in the parent) exit handlers, which
119 // might do things like block waiting for threads that don't even exist
120 // in the child.
116 if (!ShuffleFileDescriptors(fd_shuffle)) 121 if (!ShuffleFileDescriptors(fd_shuffle))
117 exit(127); 122 _exit(127);
118 123
119 // If we are using the SUID sandbox, it sets a magic environment variable 124 // If we are using the SUID sandbox, it sets a magic environment variable
120 // ("SBX_D"), so we remove that variable from the environment here on the 125 // ("SBX_D"), so we remove that variable from the environment here on the
121 // off chance that it's already set. 126 // off chance that it's already set.
122 unsetenv("SBX_D"); 127 unsetenv("SBX_D");
123 128
124 CloseSuperfluousFds(fd_shuffle); 129 CloseSuperfluousFds(fd_shuffle);
125 130
126 scoped_array<char*> argv_cstr(new char*[argv.size() + 1]); 131 scoped_array<char*> argv_cstr(new char*[argv.size() + 1]);
127 for (size_t i = 0; i < argv.size(); i++) 132 for (size_t i = 0; i < argv.size(); i++)
128 argv_cstr[i] = const_cast<char*>(argv[i].c_str()); 133 argv_cstr[i] = const_cast<char*>(argv[i].c_str());
129 argv_cstr[argv.size()] = NULL; 134 argv_cstr[argv.size()] = NULL;
130 execvp(argv_cstr[0], argv_cstr.get()); 135 execvp(argv_cstr[0], argv_cstr.get());
131 LOG(ERROR) << "LaunchApp: exec failed!, argv_cstr[0] " << argv_cstr[0] 136 LOG(ERROR) << "LaunchApp: exec failed!, argv_cstr[0] " << argv_cstr[0]
132 << ", errno " << errno; 137 << ", errno " << errno;
133 exit(127); 138 _exit(127);
134 } else { 139 } else {
135 // Parent process 140 // Parent process
136 if (wait) 141 if (wait)
137 HANDLE_EINTR(waitpid(pid, 0, 0)); 142 HANDLE_EINTR(waitpid(pid, 0, 0));
138 143
139 if (process_handle) 144 if (process_handle)
140 *process_handle = pid; 145 *process_handle = pid;
141 } 146 }
142 147
143 return true; 148 return true;
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 (*io_counters).WriteTransferCount = StringToInt64(tokenizer.token()); 411 (*io_counters).WriteTransferCount = StringToInt64(tokenizer.token());
407 } 412 }
408 state = KEY_NAME; 413 state = KEY_NAME;
409 break; 414 break;
410 } 415 }
411 } 416 }
412 return true; 417 return true;
413 } 418 }
414 419
415 } // namespace base 420 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/process_util_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698