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