OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/process_info_snapshot.h" | 5 #include "chrome/browser/process_info_snapshot.h" |
6 | 6 |
7 #include <sys/types.h> // For |uid_t| (and |pid_t|). | 7 #include <sys/types.h> // For |uid_t| (and |pid_t|). |
8 #include <unistd.h> // For |getpid()|, |getuid()|, etc. | 8 #include <unistd.h> // For |getpid()|, |getuid()|, etc. |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 104 |
105 // Hook up top's stderr to the test process' stderr. | 105 // Hook up top's stderr to the test process' stderr. |
106 fds_to_remap.push_back(std::make_pair(fileno(stderr), 2)); | 106 fds_to_remap.push_back(std::make_pair(fileno(stderr), 2)); |
107 | 107 |
108 std::vector<std::string> argv; | 108 std::vector<std::string> argv; |
109 argv.push_back("/usr/bin/top"); | 109 argv.push_back("/usr/bin/top"); |
110 argv.push_back("-l"); | 110 argv.push_back("-l"); |
111 argv.push_back("0"); | 111 argv.push_back("0"); |
112 | 112 |
113 base::ProcessHandle process_handle; | 113 base::ProcessHandle process_handle; |
114 ASSERT_TRUE(base::LaunchApp(argv, fds_to_remap, false, &process_handle)); | 114 base::LaunchOptions options; |
| 115 options.fds_to_remap = &fds_to_remap; |
| 116 options.process_handle = &process_handle; |
| 117 ASSERT_TRUE(base::LaunchProcess(argv, options)); |
115 PCHECK(HANDLE_EINTR(close(fds[1])) == 0); | 118 PCHECK(HANDLE_EINTR(close(fds[1])) == 0); |
116 | 119 |
117 // Wait until there's some output form top. This is an easy way to tell that | 120 // Wait until there's some output form top. This is an easy way to tell that |
118 // the exec() call is done and top is actually running. | 121 // the exec() call is done and top is actually running. |
119 char buf[1]; | 122 char buf[1]; |
120 PCHECK(HANDLE_EINTR(read(fds[0], buf, 1)) == 1); | 123 PCHECK(HANDLE_EINTR(read(fds[0], buf, 1)) == 1); |
121 | 124 |
122 std::vector<base::ProcessId> pid_list; | 125 std::vector<base::ProcessId> pid_list; |
123 pid_list.push_back(process_handle); | 126 pid_list.push_back(process_handle); |
124 ProcessInfoSnapshot snapshot; | 127 ProcessInfoSnapshot snapshot; |
125 ASSERT_TRUE(snapshot.Sample(pid_list)); | 128 ASSERT_TRUE(snapshot.Sample(pid_list)); |
126 | 129 |
127 ProcessInfoSnapshot::ProcInfoEntry proc_info; | 130 ProcessInfoSnapshot::ProcInfoEntry proc_info; |
128 ASSERT_TRUE(snapshot.GetProcInfo(process_handle, &proc_info)); | 131 ASSERT_TRUE(snapshot.GetProcInfo(process_handle, &proc_info)); |
129 // Effective user ID should be 0 (root). | 132 // Effective user ID should be 0 (root). |
130 EXPECT_EQ(proc_info.euid, 0u); | 133 EXPECT_EQ(proc_info.euid, 0u); |
131 // Real user ID should match the calling process's user id. | 134 // Real user ID should match the calling process's user id. |
132 EXPECT_EQ(proc_info.uid, geteuid()); | 135 EXPECT_EQ(proc_info.uid, geteuid()); |
133 | 136 |
134 ASSERT_TRUE(base::KillProcess(process_handle, 0, true)); | 137 ASSERT_TRUE(base::KillProcess(process_handle, 0, true)); |
135 PCHECK(HANDLE_EINTR(close(fds[0])) == 0); | 138 PCHECK(HANDLE_EINTR(close(fds[0])) == 0); |
136 } | 139 } |
OLD | NEW |