This source file includes following definitions.
- SetProcessTitleFromCommandLine
- SetProcessTitleFromCommandLine
#include "content/common/set_process_title.h"
#include "build/build_config.h"
#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_SOLARIS)
#include <limits.h>
#include <stdlib.h>
#include <unistd.h>
#include <string>
#include "base/command_line.h"
#endif
#if defined(OS_LINUX)
#include <sys/prctl.h>
#include "base/file_util.h"
#include "base/files/file_path.h"
#include "base/process/process_metrics.h"
#include "base/strings/string_util.h"
#include "base/threading/platform_thread.h"
#include "content/common/set_process_title_linux.h"
#endif
namespace content {
#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_SOLARIS) && \
!defined(OS_ANDROID)
void SetProcessTitleFromCommandLine(const char** main_argv) {
std::string title;
bool have_argv0 = false;
#if defined(OS_LINUX)
DCHECK_EQ(base::PlatformThread::CurrentId(), getpid());
if (main_argv)
setproctitle_init(main_argv);
base::FilePath target;
base::FilePath self_exe(base::kProcSelfExe);
if (base::ReadSymbolicLink(self_exe, &target)) {
have_argv0 = true;
title = target.value();
const std::string kDeletedSuffix = " (deleted)";
if (EndsWith(title, kDeletedSuffix, true))
title.resize(title.size() - kDeletedSuffix.size());
prctl(PR_SET_NAME, base::FilePath(title).BaseName().value().c_str());
}
#endif
const CommandLine* command_line = CommandLine::ForCurrentProcess();
for (size_t i = 1; i < command_line->argv().size(); ++i) {
if (!title.empty())
title += " ";
title += command_line->argv()[i];
}
setproctitle(have_argv0 ? "-%s" : "%s", title.c_str());
}
#else
void SetProcessTitleFromCommandLine(const char** ) {
}
#endif
}