Skip to content

Commit 550335e

Browse files
committed
src: add --title command line argument
Simple utility command line argument for setting the process title on process startup.
1 parent 62efea9 commit 550335e

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

doc/api/cli.md

+8
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,13 @@ added: v0.11.14
271271

272272
Throw errors for deprecations.
273273

274+
### `--title=title`
275+
<!-- YAML
276+
added: REPLACEME
277+
-->
278+
279+
Set `process.title` on startup.
280+
274281
### `--tls-cipher-list=list`
275282
<!-- YAML
276283
added: v4.0.0
@@ -532,6 +539,7 @@ Node options that are allowed are:
532539
- `--redirect-warnings`
533540
- `--require`, `-r`
534541
- `--throw-deprecation`
542+
- `--title`
535543
- `--tls-cipher-list`
536544
- `--trace-deprecation`
537545
- `--trace-event-categories`

doc/node.1

+3
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ instead of printing to stderr.
164164
.It Fl -throw-deprecation
165165
Throw errors for deprecations.
166166
.
167+
.It Fl -title Ns = Ns Ar title
168+
Specify process.title on startup.
169+
.
167170
.It Fl -tls-cipher-list Ns = Ns Ar list
168171
Specify an alternative default TLS cipher list.
169172
Requires Node.js to be built with crypto support. (Default)

src/node.cc

+10
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ std::string config_warning_file; // NOLINT(runtime/string)
273273
// that is used by lib/internal/bootstrap/node.js
274274
bool config_expose_internals = false;
275275

276+
std::string config_process_title; // NOLINT(runtime/string)
277+
276278
bool v8_initialized = false;
277279

278280
bool linux_at_secure = false;
@@ -2508,6 +2510,7 @@ static void PrintHelp() {
25082510
" write warnings to file instead of\n"
25092511
" stderr\n"
25102512
" --throw-deprecation throw an exception on deprecations\n"
2513+
" --title=title the process title to use on start up\n"
25112514
#if HAVE_OPENSSL
25122515
" --tls-cipher-list=val use an alternative default TLS cipher "
25132516
"list\n"
@@ -2645,6 +2648,7 @@ static void CheckIfAllowedInEnv(const char* exe, bool is_env,
26452648
"--redirect-warnings",
26462649
"--require",
26472650
"--throw-deprecation",
2651+
"--title",
26482652
"--tls-cipher-list",
26492653
"--trace-deprecation",
26502654
"--trace-event-categories",
@@ -2815,6 +2819,8 @@ static void ParseArgs(int* argc,
28152819
} else if (strncmp(arg, "--security-revert=", 18) == 0) {
28162820
const char* cve = arg + 18;
28172821
Revert(cve);
2822+
} else if (strncmp(arg, "--title=", 8) == 0) {
2823+
config_process_title = arg + 8;
28182824
} else if (strcmp(arg, "--preserve-symlinks") == 0) {
28192825
config_preserve_symlinks = true;
28202826
} else if (strcmp(arg, "--preserve-symlinks-main") == 0) {
@@ -3306,6 +3312,10 @@ void Init(int* argc,
33063312

33073313
ProcessArgv(argc, argv, exec_argc, exec_argv);
33083314

3315+
// Set the process.title immediately after processing argv if --title is set.
3316+
if (!config_process_title.empty())
3317+
uv_set_process_title(config_process_title.c_str());
3318+
33093319
#if defined(NODE_HAVE_I18N_SUPPORT)
33103320
// If the parameter isn't given, use the env variable.
33113321
if (icu_data_dir.empty())
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Flags: --title=foo
2+
'use strict';
3+
4+
const common = require('../common');
5+
6+
if (common.isSunOS)
7+
common.skip(`Unsupported platform [${process.platform}]`);
8+
9+
const assert = require('assert');
10+
11+
// Verifies that the --title=foo command line flag set the process
12+
// title on startup.
13+
assert.strictEqual(process.title, 'foo');

0 commit comments

Comments
 (0)