Commit 01edeaf9 authored by Yuta Hijikata's avatar Yuta Hijikata Committed by Commit Bot

Fixes setproctitle breaking program_invocation_short_name on linux

setproctitle sets argv[0] to space delimited string which causes
program_invocation_short_name to include all the switches until NULL
delimiter. This prevents such breakage by making
program_invocation_short_name point to a copy of the program name.

BUG=chromium:1110865
TEST=content_unittests

Change-Id: Iece5fa626e027a0145e7321cdbbda915f73b6c4f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2326511
Commit-Queue: Lei Zhang <thestig@chromium.org>
Auto-Submit: Yuta Hijikata <ythjkt@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarShuhei Takahashi <nya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795558}
parent 84748baf
...@@ -2,6 +2,14 @@ ...@@ -2,6 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// Define _GNU_SOURCE to ensure that <error.h> defines
// program_invocation_short_name. Keep this at the top of the file since some
// system headers might include <error.h> and the header could be skipped on
// subsequent includes.
#if defined(OS_LINUX) && !defined(_GNU_SOURCE)
#define _GNU_SOURCE
#endif
#include "services/service_manager/embedder/set_process_title.h" #include "services/service_manager/embedder/set_process_title.h"
#include <stddef.h> #include <stddef.h>
...@@ -19,6 +27,7 @@ ...@@ -19,6 +27,7 @@
#endif // defined(OS_POSIX) && !defined(OS_MAC) && !defined(OS_SOLARIS) #endif // defined(OS_POSIX) && !defined(OS_MAC) && !defined(OS_SOLARIS)
#if defined(OS_LINUX) #if defined(OS_LINUX)
#include <error.h> // Get program_invocation_short_name declaration.
#include <sys/prctl.h> #include <sys/prctl.h>
#include "base/files/file_path.h" #include "base/files/file_path.h"
...@@ -64,11 +73,17 @@ void SetProcessTitleFromCommandLine(const char** main_argv) { ...@@ -64,11 +73,17 @@ void SetProcessTitleFromCommandLine(const char** main_argv) {
if (base::EndsWith(title, kDeletedSuffix, base::CompareCase::SENSITIVE)) if (base::EndsWith(title, kDeletedSuffix, base::CompareCase::SENSITIVE))
title.resize(title.size() - kDeletedSuffix.size()); title.resize(title.size() - kDeletedSuffix.size());
base::FilePath::StringType base_name =
base::FilePath(title).BaseName().value();
// PR_SET_NAME is available in Linux 2.6.9 and newer. // PR_SET_NAME is available in Linux 2.6.9 and newer.
// When available at run time, this sets the short process name that shows // When available at run time, this sets the short process name that shows
// when the full command line is not being displayed in most process // when the full command line is not being displayed in most process
// listings. // listings.
prctl(PR_SET_NAME, base::FilePath(title).BaseName().value().c_str()); prctl(PR_SET_NAME, base_name.c_str());
// This prevents program_invocation_short_name from being broken by
// setproctitle().
program_invocation_short_name = strdup(base_name.c_str());
} }
#endif // defined(OS_LINUX) #endif // defined(OS_LINUX)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment