OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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> |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 base::Process process = base::LaunchProcess(argv, options); | 125 base::Process process = base::LaunchProcess(argv, options); |
126 ASSERT_TRUE(process.IsValid()); | 126 ASSERT_TRUE(process.IsValid()); |
127 PCHECK(IGNORE_EINTR(close(fds[1])) == 0); | 127 PCHECK(IGNORE_EINTR(close(fds[1])) == 0); |
128 | 128 |
129 // Wait until there's some output form top. This is an easy way to tell that | 129 // Wait until there's some output form top. This is an easy way to tell that |
130 // the exec() call is done and top is actually running. | 130 // the exec() call is done and top is actually running. |
131 char buf[1]; | 131 char buf[1]; |
132 PCHECK(HANDLE_EINTR(read(fds[0], buf, 1)) == 1); | 132 PCHECK(HANDLE_EINTR(read(fds[0], buf, 1)) == 1); |
133 | 133 |
134 std::vector<base::ProcessId> pid_list; | 134 std::vector<base::ProcessId> pid_list; |
135 pid_list.push_back(process.pid()); | 135 pid_list.push_back(process.Pid()); |
136 ProcessInfoSnapshot snapshot; | 136 ProcessInfoSnapshot snapshot; |
137 ASSERT_TRUE(snapshot.Sample(pid_list)); | 137 ASSERT_TRUE(snapshot.Sample(pid_list)); |
138 | 138 |
139 ProcessInfoSnapshot::ProcInfoEntry proc_info; | 139 ProcessInfoSnapshot::ProcInfoEntry proc_info; |
140 ASSERT_TRUE(snapshot.GetProcInfo(process.pid(), &proc_info)); | 140 ASSERT_TRUE(snapshot.GetProcInfo(process.Pid(), &proc_info)); |
141 // Effective user ID should be 0 (root). | 141 // Effective user ID should be 0 (root). |
142 EXPECT_EQ(proc_info.euid, 0u); | 142 EXPECT_EQ(proc_info.euid, 0u); |
143 // Real user ID should match the calling process's user id. | 143 // Real user ID should match the calling process's user id. |
144 EXPECT_EQ(proc_info.uid, geteuid()); | 144 EXPECT_EQ(proc_info.uid, geteuid()); |
145 | 145 |
146 ASSERT_TRUE(base::KillProcess(process.Handle(), 0, true)); | 146 ASSERT_TRUE(base::KillProcess(process.Handle(), 0, true)); |
147 PCHECK(IGNORE_EINTR(close(fds[0])) == 0); | 147 PCHECK(IGNORE_EINTR(close(fds[0])) == 0); |
148 } | 148 } |
OLD | NEW |