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

Side by Side Diff: chrome/browser/zygote_host_linux.cc

Issue 3076020: Reland r54418 - base: Add UnSetEnv function to EnvVarGetter API. (Closed) Base URL: git://git.chromium.org/chromium.git
Patch Set: Created 10 years, 4 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 (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/zygote_host_linux.h" 5 #include "chrome/browser/zygote_host_linux.h"
6 6
7 #include <sys/socket.h> 7 #include <sys/socket.h>
8 #include <sys/stat.h> 8 #include <sys/stat.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 #include <unistd.h> 10 #include <unistd.h>
11 11
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/eintr_wrapper.h" 13 #include "base/eintr_wrapper.h"
14 #include "base/env_var.h"
14 #include "base/linux_util.h" 15 #include "base/linux_util.h"
15 #include "base/logging.h" 16 #include "base/logging.h"
16 #include "base/path_service.h" 17 #include "base/path_service.h"
17 #include "base/pickle.h" 18 #include "base/pickle.h"
18 #include "base/process_util.h" 19 #include "base/process_util.h"
19 #include "base/string_number_conversions.h" 20 #include "base/string_number_conversions.h"
20 #include "base/string_util.h" 21 #include "base/string_util.h"
22 #include "base/scoped_ptr.h"
21 #include "base/unix_domain_socket_posix.h" 23 #include "base/unix_domain_socket_posix.h"
22 24
23 #include "chrome/browser/renderer_host/render_sandbox_host_linux.h" 25 #include "chrome/browser/renderer_host/render_sandbox_host_linux.h"
24 #include "chrome/common/chrome_constants.h" 26 #include "chrome/common/chrome_constants.h"
25 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/process_watcher.h" 28 #include "chrome/common/process_watcher.h"
27 29
28 #include "sandbox/linux/suid/suid_unsafe_environment_variables.h" 30 #include "sandbox/linux/suid/suid_unsafe_environment_variables.h"
29 31
30 static void SaveSUIDUnsafeEnvironmentVariables() { 32 static void SaveSUIDUnsafeEnvironmentVariables() {
31 // The ELF loader will clear many environment variables so we save them to 33 // The ELF loader will clear many environment variables so we save them to
32 // different names here so that the SUID sandbox can resolve them for the 34 // different names here so that the SUID sandbox can resolve them for the
33 // renderer. 35 // renderer.
34 36
35 for (unsigned i = 0; kSUIDUnsafeEnvironmentVariables[i]; ++i) { 37 for (unsigned i = 0; kSUIDUnsafeEnvironmentVariables[i]; ++i) {
36 const char* const envvar = kSUIDUnsafeEnvironmentVariables[i]; 38 const char* const envvar = kSUIDUnsafeEnvironmentVariables[i];
37 char* const saved_envvar = SandboxSavedEnvironmentVariable(envvar); 39 char* const saved_envvar = SandboxSavedEnvironmentVariable(envvar);
38 if (!saved_envvar) 40 if (!saved_envvar)
39 continue; 41 continue;
40 42
41 const char* const value = getenv(envvar); 43 scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create());
42 if (value) 44 std::string value;
43 setenv(saved_envvar, value, 1 /* overwrite */); 45 if (env->GetEnv(envvar, &value))
46 env->SetEnv(saved_envvar, value);
44 else 47 else
45 unsetenv(saved_envvar); 48 env->UnSetEnv(saved_envvar);
46 49
47 free(saved_envvar); 50 free(saved_envvar);
48 } 51 }
49 } 52 }
50 53
51 ZygoteHost::ZygoteHost() 54 ZygoteHost::ZygoteHost()
52 : pid_(-1), 55 : pid_(-1),
53 init_(false), 56 init_(false),
54 using_suid_sandbox_(false), 57 using_suid_sandbox_(false),
55 have_read_sandbox_status_word_(false) { 58 have_read_sandbox_status_word_(false) {
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 !read_pickle.ReadBool(&iter, &tmp_child_exited)) { 335 !read_pickle.ReadBool(&iter, &tmp_child_exited)) {
333 LOG(WARNING) << "Error parsing DidProcessCrash response from zygote."; 336 LOG(WARNING) << "Error parsing DidProcessCrash response from zygote.";
334 return false; 337 return false;
335 } 338 }
336 339
337 if (child_exited) 340 if (child_exited)
338 *child_exited = tmp_child_exited; 341 *child_exited = tmp_child_exited;
339 342
340 return did_crash; 343 return did_crash;
341 } 344 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698