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

Side by Side Diff: base/command_line.cc

Issue 5286010: Start using file_util symlink code, now that it's available. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review change Created 10 years 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 | Annotate | Revision Log
« no previous file with comments | « base/base_paths_linux.cc ('k') | base/file_util_posix.cc » ('j') | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/command_line.h" 5 #include "base/command_line.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #elif defined(OS_POSIX) 10 #elif defined(OS_POSIX)
11 #include <limits.h> 11 #include <limits.h>
12 #include <stdlib.h> 12 #include <stdlib.h>
13 #include <unistd.h> 13 #include <unistd.h>
14 #endif 14 #endif
15 #if defined(OS_LINUX) 15 #if defined(OS_LINUX)
16 #include <sys/prctl.h> 16 #include <sys/prctl.h>
17 #endif 17 #endif
18 18
19 #include <algorithm> 19 #include <algorithm>
20 20
21 #include "base/file_path.h" 21 #include "base/file_path.h"
22 #include "base/file_util.h"
22 #include "base/logging.h" 23 #include "base/logging.h"
23 #include "base/singleton.h" 24 #include "base/singleton.h"
24 #include "base/string_split.h" 25 #include "base/string_split.h"
25 #include "base/string_util.h" 26 #include "base/string_util.h"
26 #include "base/sys_string_conversions.h" 27 #include "base/sys_string_conversions.h"
27 #include "base/utf_string_conversions.h" 28 #include "base/utf_string_conversions.h"
28 29
29 #if defined(OS_LINUX) 30 #if defined(OS_LINUX)
30 // Linux/glibc doesn't natively have setproctitle(). 31 // Linux/glibc doesn't natively have setproctitle().
31 #include "base/setproctitle_linux.h" 32 #include "base/setproctitle_linux.h"
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 // Build a single string which consists of all the arguments separated 231 // Build a single string which consists of all the arguments separated
231 // by spaces. We can't actually keep them separate due to the way the 232 // by spaces. We can't actually keep them separate due to the way the
232 // setproctitle() function works. 233 // setproctitle() function works.
233 std::string title; 234 std::string title;
234 bool have_argv0 = false; 235 bool have_argv0 = false;
235 #if defined(OS_LINUX) 236 #if defined(OS_LINUX)
236 // In Linux we sometimes exec ourselves from /proc/self/exe, but this makes us 237 // In Linux we sometimes exec ourselves from /proc/self/exe, but this makes us
237 // show up as "exe" in process listings. Read the symlink /proc/self/exe and 238 // show up as "exe" in process listings. Read the symlink /proc/self/exe and
238 // use the path it points at for our process title. Note that this is only for 239 // use the path it points at for our process title. Note that this is only for
239 // display purposes and has no TOCTTOU security implications. 240 // display purposes and has no TOCTTOU security implications.
240 char buffer[PATH_MAX]; 241 FilePath target;
241 // Note: readlink() does not append a null byte to terminate the string. 242 FilePath self_exe("/proc/self/exe");
242 ssize_t length = readlink("/proc/self/exe", buffer, sizeof(buffer)); 243 if (file_util::ReadSymbolicLink(self_exe, &target)) {
243 DCHECK(length <= static_cast<ssize_t>(sizeof(buffer)));
244 if (length > 0) {
245 have_argv0 = true; 244 have_argv0 = true;
246 title.assign(buffer, length); 245 title = target.value();
247 // If the binary has since been deleted, Linux appends " (deleted)" to the 246 // If the binary has since been deleted, Linux appends " (deleted)" to the
248 // symlink target. Remove it, since this is not really part of our name. 247 // symlink target. Remove it, since this is not really part of our name.
249 const std::string kDeletedSuffix = " (deleted)"; 248 const std::string kDeletedSuffix = " (deleted)";
250 if (EndsWith(title, kDeletedSuffix, true)) 249 if (EndsWith(title, kDeletedSuffix, true))
251 title.resize(title.size() - kDeletedSuffix.size()); 250 title.resize(title.size() - kDeletedSuffix.size());
252 #if defined(PR_SET_NAME) 251 #if defined(PR_SET_NAME)
253 // If PR_SET_NAME is available at compile time, we try using it. We ignore 252 // If PR_SET_NAME is available at compile time, we try using it. We ignore
254 // any errors if the kernel does not support it at runtime though. When 253 // any errors if the kernel does not support it at runtime though. When
255 // available, this lets us set the short process name that shows when the 254 // available, this lets us set the short process name that shows when the
256 // full command line is not being displayed in most process listings. 255 // full command line is not being displayed in most process listings.
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 534
536 // private 535 // private
537 CommandLine::CommandLine() { 536 CommandLine::CommandLine() {
538 } 537 }
539 538
540 // static 539 // static
541 CommandLine* CommandLine::ForCurrentProcessMutable() { 540 CommandLine* CommandLine::ForCurrentProcessMutable() {
542 DCHECK(current_process_commandline_); 541 DCHECK(current_process_commandline_);
543 return current_process_commandline_; 542 return current_process_commandline_;
544 } 543 }
OLDNEW
« no previous file with comments | « base/base_paths_linux.cc ('k') | base/file_util_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698