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

Side by Side Diff: content/common/set_process_title.cc

Issue 8598004: Linux: Fix bad #define for SetProcessTitleFromCommandLine(). (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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 | « 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) 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 "content/common/set_process_title.h" 5 #include "content/common/set_process_title.h"
6 6
7 #include "base/command_line.h"
8 #include "base/file_path.h"
9 #include "base/file_util.h"
10 #include "base/string_util.h"
11 #include "build/build_config.h" 7 #include "build/build_config.h"
12 8
13 #if defined(OS_POSIX) 9 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_SOLARIS)
14 #include <limits.h> 10 #include <limits.h>
15 #include <stdlib.h> 11 #include <stdlib.h>
16 #include <unistd.h> 12 #include <unistd.h>
17 #endif 13
14 #include <string>
15
16 #include "base/command_line.h"
17 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_SOLARIS)
18 18
19 #if defined(OS_LINUX) 19 #if defined(OS_LINUX)
20 #include <sys/prctl.h> 20 #include <sys/prctl.h>
21 21
22 #include "base/file_path.h"
23 #include "base/file_util.h"
24 #include "base/string_util.h"
22 // Linux/glibc doesn't natively have setproctitle(). 25 // Linux/glibc doesn't natively have setproctitle().
23 #include "content/common/set_process_title_linux.h" 26 #include "content/common/set_process_title_linux.h"
24 #endif 27 #endif // defined(OS_LINUX)
25 28
26 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_SOLARIS) && \ 29 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_SOLARIS)
27 defined(OS_OPENBSD)
28 30
29 void SetProcessTitleFromCommandLine(const char** main_argv) { 31 void SetProcessTitleFromCommandLine(const char** main_argv) {
30 // Build a single string which consists of all the arguments separated 32 // Build a single string which consists of all the arguments separated
31 // by spaces. We can't actually keep them separate due to the way the 33 // by spaces. We can't actually keep them separate due to the way the
32 // setproctitle() function works. 34 // setproctitle() function works.
33 std::string title; 35 std::string title;
34 bool have_argv0 = false; 36 bool have_argv0 = false;
35 37
36 #if defined(OS_LINUX) 38 #if defined(OS_LINUX)
37 if (main_argv) 39 if (main_argv)
(...skipping 12 matching lines...) Expand all
50 // symlink target. Remove it, since this is not really part of our name. 52 // symlink target. Remove it, since this is not really part of our name.
51 const std::string kDeletedSuffix = " (deleted)"; 53 const std::string kDeletedSuffix = " (deleted)";
52 if (EndsWith(title, kDeletedSuffix, true)) 54 if (EndsWith(title, kDeletedSuffix, true))
53 title.resize(title.size() - kDeletedSuffix.size()); 55 title.resize(title.size() - kDeletedSuffix.size());
54 #if defined(PR_SET_NAME) 56 #if defined(PR_SET_NAME)
55 // If PR_SET_NAME is available at compile time, we try using it. We ignore 57 // If PR_SET_NAME is available at compile time, we try using it. We ignore
56 // any errors if the kernel does not support it at runtime though. When 58 // any errors if the kernel does not support it at runtime though. When
57 // available, this lets us set the short process name that shows when the 59 // available, this lets us set the short process name that shows when the
58 // full command line is not being displayed in most process listings. 60 // full command line is not being displayed in most process listings.
59 prctl(PR_SET_NAME, FilePath(title).BaseName().value().c_str()); 61 prctl(PR_SET_NAME, FilePath(title).BaseName().value().c_str());
60 #endif 62 #endif // defined(PR_SET_NAME)
61 } 63 }
62 #endif 64 #endif // defined(OS_LINUX)
63 65
64 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 66 const CommandLine* command_line = CommandLine::ForCurrentProcess();
65 for (size_t i = 1; i < command_line->argv().size(); ++i) { 67 for (size_t i = 1; i < command_line->argv().size(); ++i) {
66 if (!title.empty()) 68 if (!title.empty())
67 title += " "; 69 title += " ";
68 title += command_line->argv()[i]; 70 title += command_line->argv()[i];
69 } 71 }
70 // Disable prepending argv[0] with '-' if we prepended it ourselves above. 72 // Disable prepending argv[0] with '-' if we prepended it ourselves above.
71 setproctitle(have_argv0 ? "-%s" : "%s", title.c_str()); 73 setproctitle(have_argv0 ? "-%s" : "%s", title.c_str());
72 } 74 }
73 75
74 #else 76 #else
75 77
76 // All other systems (basically Windows & Mac) have no need or way to implement 78 // All other systems (basically Windows & Mac) have no need or way to implement
77 // this function. 79 // this function.
78 void SetProcessTitleFromCommandLine(const char** /* main_argv */) { 80 void SetProcessTitleFromCommandLine(const char** /* main_argv */) {
79 } 81 }
80 82
81 #endif 83 #endif
82
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