| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 109 |
| 110 std::vector<std::string> argv; | 110 std::vector<std::string> argv; |
| 111 argv.push_back("/usr/bin/top"); | 111 argv.push_back("/usr/bin/top"); |
| 112 argv.push_back("-l"); | 112 argv.push_back("-l"); |
| 113 argv.push_back("0"); | 113 argv.push_back("0"); |
| 114 | 114 |
| 115 base::ProcessHandle process_handle; | 115 base::ProcessHandle process_handle; |
| 116 base::LaunchOptions options; | 116 base::LaunchOptions options; |
| 117 options.fds_to_remap = &fds_to_remap; | 117 options.fds_to_remap = &fds_to_remap; |
| 118 ASSERT_TRUE(base::LaunchProcess(argv, options, &process_handle)); | 118 ASSERT_TRUE(base::LaunchProcess(argv, options, &process_handle)); |
| 119 PCHECK(HANDLE_EINTR(close(fds[1])) == 0); | 119 PCHECK(IGNORE_EINTR(close(fds[1])) == 0); |
| 120 | 120 |
| 121 // Wait until there's some output form top. This is an easy way to tell that | 121 // Wait until there's some output form top. This is an easy way to tell that |
| 122 // the exec() call is done and top is actually running. | 122 // the exec() call is done and top is actually running. |
| 123 char buf[1]; | 123 char buf[1]; |
| 124 PCHECK(HANDLE_EINTR(read(fds[0], buf, 1)) == 1); | 124 PCHECK(HANDLE_EINTR(read(fds[0], buf, 1)) == 1); |
| 125 | 125 |
| 126 std::vector<base::ProcessId> pid_list; | 126 std::vector<base::ProcessId> pid_list; |
| 127 pid_list.push_back(process_handle); | 127 pid_list.push_back(process_handle); |
| 128 ProcessInfoSnapshot snapshot; | 128 ProcessInfoSnapshot snapshot; |
| 129 ASSERT_TRUE(snapshot.Sample(pid_list)); | 129 ASSERT_TRUE(snapshot.Sample(pid_list)); |
| 130 | 130 |
| 131 ProcessInfoSnapshot::ProcInfoEntry proc_info; | 131 ProcessInfoSnapshot::ProcInfoEntry proc_info; |
| 132 ASSERT_TRUE(snapshot.GetProcInfo(process_handle, &proc_info)); | 132 ASSERT_TRUE(snapshot.GetProcInfo(process_handle, &proc_info)); |
| 133 // Effective user ID should be 0 (root). | 133 // Effective user ID should be 0 (root). |
| 134 EXPECT_EQ(proc_info.euid, 0u); | 134 EXPECT_EQ(proc_info.euid, 0u); |
| 135 // Real user ID should match the calling process's user id. | 135 // Real user ID should match the calling process's user id. |
| 136 EXPECT_EQ(proc_info.uid, geteuid()); | 136 EXPECT_EQ(proc_info.uid, geteuid()); |
| 137 | 137 |
| 138 ASSERT_TRUE(base::KillProcess(process_handle, 0, true)); | 138 ASSERT_TRUE(base::KillProcess(process_handle, 0, true)); |
| 139 PCHECK(HANDLE_EINTR(close(fds[0])) == 0); | 139 PCHECK(IGNORE_EINTR(close(fds[0])) == 0); |
| 140 } | 140 } |
| OLD | NEW |