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

Side by Side Diff: base/process/process_iterator_linux.cc

Issue 1642663003: [Linux] Do not try to call readdir() on a null DIR* in base::ProcessIterator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "base/process/process_iterator.h" 5 #include "base/process/process_iterator.h"
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/process/internal_linux.h" 9 #include "base/process/internal_linux.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 *proc_cmd_line_args = SplitString(cmd_line, delimiters, KEEP_WHITESPACE, 52 *proc_cmd_line_args = SplitString(cmd_line, delimiters, KEEP_WHITESPACE,
53 SPLIT_WANT_NONEMPTY); 53 SPLIT_WANT_NONEMPTY);
54 return true; 54 return true;
55 } 55 }
56 56
57 } // namespace 57 } // namespace
58 58
59 ProcessIterator::ProcessIterator(const ProcessFilter* filter) 59 ProcessIterator::ProcessIterator(const ProcessFilter* filter)
60 : filter_(filter) { 60 : filter_(filter) {
61 procfs_dir_ = opendir(internal::kProcDir); 61 procfs_dir_ = opendir(internal::kProcDir);
62 if (!procfs_dir_) {
Nico 2016/01/27 18:54:34 Can you add a comment when this can happen? From t
Robert Sesek 2016/01/27 18:58:42 Added a comment. This *shouldn't* happen every tim
Robert Sesek 2016/01/27 19:11:11 Filed https://code.google.com/p/chromium/issues/de
63 PLOG(ERROR) << "opendir " << internal::kProcDir;
64 }
62 } 65 }
63 66
64 ProcessIterator::~ProcessIterator() { 67 ProcessIterator::~ProcessIterator() {
65 if (procfs_dir_) { 68 if (procfs_dir_) {
66 closedir(procfs_dir_); 69 closedir(procfs_dir_);
67 procfs_dir_ = NULL; 70 procfs_dir_ = nullptr;
68 } 71 }
69 } 72 }
70 73
71 bool ProcessIterator::CheckForNextProcess() { 74 bool ProcessIterator::CheckForNextProcess() {
72 // TODO(port): skip processes owned by different UID 75 // TODO(port): skip processes owned by different UID
73 76
77 if (!procfs_dir_) {
78 DLOG(ERROR) << "Skipping CheckForNextProcess(), no procfs_dir_";
79 return false;
80 }
81
74 pid_t pid = kNullProcessId; 82 pid_t pid = kNullProcessId;
75 std::vector<std::string> cmd_line_args; 83 std::vector<std::string> cmd_line_args;
76 std::string stats_data; 84 std::string stats_data;
77 std::vector<std::string> proc_stats; 85 std::vector<std::string> proc_stats;
78 86
79 // Arbitrarily guess that there will never be more than 200 non-process 87 // Arbitrarily guess that there will never be more than 200 non-process
80 // files in /proc. Hardy has 53 and Lucid has 61. 88 // files in /proc. Hardy has 53 and Lucid has 61.
81 int skipped = 0; 89 int skipped = 0;
82 const int kSkipLimit = 200; 90 const int kSkipLimit = 200;
83 while (skipped < kSkipLimit) { 91 while (skipped < kSkipLimit) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 return true; 138 return true;
131 } 139 }
132 140
133 bool NamedProcessIterator::IncludeEntry() { 141 bool NamedProcessIterator::IncludeEntry() {
134 if (executable_name_ != entry().exe_file()) 142 if (executable_name_ != entry().exe_file())
135 return false; 143 return false;
136 return ProcessIterator::IncludeEntry(); 144 return ProcessIterator::IncludeEntry();
137 } 145 }
138 146
139 } // namespace base 147 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698