src: add --title command line argument

Simple utility command line argument for setting the process
title on process startup.

PR-URL: https://github.com/nodejs/node/pull/21477
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
James M Snell 2018-06-22 16:16:03 -07:00
parent 67053568ee
commit 9d71619bbe
4 changed files with 34 additions and 0 deletions

View File

@ -278,6 +278,13 @@ added: v0.11.14
Throw errors for deprecations. Throw errors for deprecations.
### `--title=title`
<!-- YAML
added: REPLACEME
-->
Set `process.title` on startup.
### `--tls-cipher-list=list` ### `--tls-cipher-list=list`
<!-- YAML <!-- YAML
added: v4.0.0 added: v4.0.0
@ -539,6 +546,7 @@ Node options that are allowed are:
- `--redirect-warnings` - `--redirect-warnings`
- `--require`, `-r` - `--require`, `-r`
- `--throw-deprecation` - `--throw-deprecation`
- `--title`
- `--tls-cipher-list` - `--tls-cipher-list`
- `--trace-deprecation` - `--trace-deprecation`
- `--trace-event-categories` - `--trace-event-categories`

View File

@ -167,6 +167,9 @@ instead of printing to stderr.
.It Fl -throw-deprecation .It Fl -throw-deprecation
Throw errors for deprecations. Throw errors for deprecations.
. .
.It Fl -title Ns = Ns Ar title
Specify process.title on startup.
.
.It Fl -tls-cipher-list Ns = Ns Ar list .It Fl -tls-cipher-list Ns = Ns Ar list
Specify an alternative default TLS cipher list. Specify an alternative default TLS cipher list.
Requires Node.js to be built with crypto support. (Default) Requires Node.js to be built with crypto support. (Default)

View File

@ -275,6 +275,8 @@ std::string config_warning_file; // NOLINT(runtime/string)
// that is used by lib/internal/bootstrap/node.js // that is used by lib/internal/bootstrap/node.js
bool config_expose_internals = false; bool config_expose_internals = false;
std::string config_process_title; // NOLINT(runtime/string)
bool v8_initialized = false; bool v8_initialized = false;
bool linux_at_secure = false; bool linux_at_secure = false;
@ -2521,6 +2523,7 @@ static void PrintHelp() {
" write warnings to file instead of\n" " write warnings to file instead of\n"
" stderr\n" " stderr\n"
" --throw-deprecation throw an exception on deprecations\n" " --throw-deprecation throw an exception on deprecations\n"
" --title=title the process title to use on start up\n"
#if HAVE_OPENSSL #if HAVE_OPENSSL
" --tls-cipher-list=val use an alternative default TLS cipher " " --tls-cipher-list=val use an alternative default TLS cipher "
"list\n" "list\n"
@ -2658,6 +2661,7 @@ static void CheckIfAllowedInEnv(const char* exe, bool is_env,
"--redirect-warnings", "--redirect-warnings",
"--require", "--require",
"--throw-deprecation", "--throw-deprecation",
"--title",
"--tls-cipher-list", "--tls-cipher-list",
"--trace-deprecation", "--trace-deprecation",
"--trace-event-categories", "--trace-event-categories",
@ -2828,6 +2832,8 @@ static void ParseArgs(int* argc,
} else if (strncmp(arg, "--security-revert=", 18) == 0) { } else if (strncmp(arg, "--security-revert=", 18) == 0) {
const char* cve = arg + 18; const char* cve = arg + 18;
Revert(cve); Revert(cve);
} else if (strncmp(arg, "--title=", 8) == 0) {
config_process_title = arg + 8;
} else if (strcmp(arg, "--preserve-symlinks") == 0) { } else if (strcmp(arg, "--preserve-symlinks") == 0) {
config_preserve_symlinks = true; config_preserve_symlinks = true;
} else if (strcmp(arg, "--preserve-symlinks-main") == 0) { } else if (strcmp(arg, "--preserve-symlinks-main") == 0) {
@ -3319,6 +3325,10 @@ void Init(int* argc,
ProcessArgv(argc, argv, exec_argc, exec_argv); ProcessArgv(argc, argv, exec_argc, exec_argv);
// Set the process.title immediately after processing argv if --title is set.
if (!config_process_title.empty())
uv_set_process_title(config_process_title.c_str());
#if defined(NODE_HAVE_I18N_SUPPORT) #if defined(NODE_HAVE_I18N_SUPPORT)
// If the parameter isn't given, use the env variable. // If the parameter isn't given, use the env variable.
if (icu_data_dir.empty()) if (icu_data_dir.empty())

View File

@ -0,0 +1,13 @@
// Flags: --title=foo
'use strict';
const common = require('../common');
if (common.isSunOS)
common.skip(`Unsupported platform [${process.platform}]`);
const assert = require('assert');
// Verifies that the --title=foo command line flag set the process
// title on startup.
assert.strictEqual(process.title, 'foo');