| 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 "content/common/set_process_title.h" | 5 #include "content/common/set_process_title.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_SOLARIS) | 9 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_SOLARIS) |
| 10 #include <limits.h> | 10 #include <limits.h> |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 #if defined(OS_LINUX) | 43 #if defined(OS_LINUX) |
| 44 if (main_argv) | 44 if (main_argv) |
| 45 setproctitle_init(main_argv); | 45 setproctitle_init(main_argv); |
| 46 | 46 |
| 47 // In Linux we sometimes exec ourselves from /proc/self/exe, but this makes us | 47 // In Linux we sometimes exec ourselves from /proc/self/exe, but this makes us |
| 48 // show up as "exe" in process listings. Read the symlink /proc/self/exe and | 48 // show up as "exe" in process listings. Read the symlink /proc/self/exe and |
| 49 // use the path it points at for our process title. Note that this is only for | 49 // use the path it points at for our process title. Note that this is only for |
| 50 // display purposes and has no TOCTTOU security implications. | 50 // display purposes and has no TOCTTOU security implications. |
| 51 base::FilePath target; | 51 base::FilePath target; |
| 52 base::FilePath self_exe(base::kProcSelfExe); | 52 base::FilePath self_exe(base::kProcSelfExe); |
| 53 if (file_util::ReadSymbolicLink(self_exe, &target)) { | 53 if (base::ReadSymbolicLink(self_exe, &target)) { |
| 54 have_argv0 = true; | 54 have_argv0 = true; |
| 55 title = target.value(); | 55 title = target.value(); |
| 56 // If the binary has since been deleted, Linux appends " (deleted)" to the | 56 // If the binary has since been deleted, Linux appends " (deleted)" to the |
| 57 // symlink target. Remove it, since this is not really part of our name. | 57 // symlink target. Remove it, since this is not really part of our name. |
| 58 const std::string kDeletedSuffix = " (deleted)"; | 58 const std::string kDeletedSuffix = " (deleted)"; |
| 59 if (EndsWith(title, kDeletedSuffix, true)) | 59 if (EndsWith(title, kDeletedSuffix, true)) |
| 60 title.resize(title.size() - kDeletedSuffix.size()); | 60 title.resize(title.size() - kDeletedSuffix.size()); |
| 61 #if defined(PR_SET_NAME) | 61 #if defined(PR_SET_NAME) |
| 62 // If PR_SET_NAME is available at compile time, we try using it. We ignore | 62 // If PR_SET_NAME is available at compile time, we try using it. We ignore |
| 63 // any errors if the kernel does not support it at runtime though. When | 63 // any errors if the kernel does not support it at runtime though. When |
| (...skipping 17 matching lines...) Expand all Loading... |
| 81 #else | 81 #else |
| 82 | 82 |
| 83 // All other systems (basically Windows & Mac) have no need or way to implement | 83 // All other systems (basically Windows & Mac) have no need or way to implement |
| 84 // this function. | 84 // this function. |
| 85 void SetProcessTitleFromCommandLine(const char** /* main_argv */) { | 85 void SetProcessTitleFromCommandLine(const char** /* main_argv */) { |
| 86 } | 86 } |
| 87 | 87 |
| 88 #endif | 88 #endif |
| 89 | 89 |
| 90 } // namespace content | 90 } // namespace content |
| OLD | NEW |