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:
parent
67053568ee
commit
9d71619bbe
@ -278,6 +278,13 @@ added: v0.11.14
|
||||
|
||||
Throw errors for deprecations.
|
||||
|
||||
### `--title=title`
|
||||
<!-- YAML
|
||||
added: REPLACEME
|
||||
-->
|
||||
|
||||
Set `process.title` on startup.
|
||||
|
||||
### `--tls-cipher-list=list`
|
||||
<!-- YAML
|
||||
added: v4.0.0
|
||||
@ -539,6 +546,7 @@ Node options that are allowed are:
|
||||
- `--redirect-warnings`
|
||||
- `--require`, `-r`
|
||||
- `--throw-deprecation`
|
||||
- `--title`
|
||||
- `--tls-cipher-list`
|
||||
- `--trace-deprecation`
|
||||
- `--trace-event-categories`
|
||||
|
@ -167,6 +167,9 @@ instead of printing to stderr.
|
||||
.It Fl -throw-deprecation
|
||||
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
|
||||
Specify an alternative default TLS cipher list.
|
||||
Requires Node.js to be built with crypto support. (Default)
|
||||
|
10
src/node.cc
10
src/node.cc
@ -275,6 +275,8 @@ std::string config_warning_file; // NOLINT(runtime/string)
|
||||
// that is used by lib/internal/bootstrap/node.js
|
||||
bool config_expose_internals = false;
|
||||
|
||||
std::string config_process_title; // NOLINT(runtime/string)
|
||||
|
||||
bool v8_initialized = false;
|
||||
|
||||
bool linux_at_secure = false;
|
||||
@ -2521,6 +2523,7 @@ static void PrintHelp() {
|
||||
" write warnings to file instead of\n"
|
||||
" stderr\n"
|
||||
" --throw-deprecation throw an exception on deprecations\n"
|
||||
" --title=title the process title to use on start up\n"
|
||||
#if HAVE_OPENSSL
|
||||
" --tls-cipher-list=val use an alternative default TLS cipher "
|
||||
"list\n"
|
||||
@ -2658,6 +2661,7 @@ static void CheckIfAllowedInEnv(const char* exe, bool is_env,
|
||||
"--redirect-warnings",
|
||||
"--require",
|
||||
"--throw-deprecation",
|
||||
"--title",
|
||||
"--tls-cipher-list",
|
||||
"--trace-deprecation",
|
||||
"--trace-event-categories",
|
||||
@ -2828,6 +2832,8 @@ static void ParseArgs(int* argc,
|
||||
} else if (strncmp(arg, "--security-revert=", 18) == 0) {
|
||||
const char* cve = arg + 18;
|
||||
Revert(cve);
|
||||
} else if (strncmp(arg, "--title=", 8) == 0) {
|
||||
config_process_title = arg + 8;
|
||||
} else if (strcmp(arg, "--preserve-symlinks") == 0) {
|
||||
config_preserve_symlinks = true;
|
||||
} else if (strcmp(arg, "--preserve-symlinks-main") == 0) {
|
||||
@ -3319,6 +3325,10 @@ void Init(int* argc,
|
||||
|
||||
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 the parameter isn't given, use the env variable.
|
||||
if (icu_data_dir.empty())
|
||||
|
13
test/parallel/test-process-title-cli.js
Normal file
13
test/parallel/test-process-title-cli.js
Normal 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');
|
Loading…
x
Reference in New Issue
Block a user