Skip to content

Commit 9d71619

Browse files
committed
src: add --title command line argument
Simple utility command line argument for setting the process title on process startup. PR-URL: #21477 Reviewed-By: Bradley Farias <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 6705356 commit 9d71619

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

doc/api/cli.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,13 @@ added: v0.11.14
278278

279279
Throw errors for deprecations.
280280

281+
### `--title=title`
282+
<!-- YAML
283+
added: REPLACEME
284+
-->
285+
286+
Set `process.title` on startup.
287+
281288
### `--tls-cipher-list=list`
282289
<!-- YAML
283290
added: v4.0.0
@@ -539,6 +546,7 @@ Node options that are allowed are:
539546
- `--redirect-warnings`
540547
- `--require`, `-r`
541548
- `--throw-deprecation`
549+
- `--title`
542550
- `--tls-cipher-list`
543551
- `--trace-deprecation`
544552
- `--trace-event-categories`

doc/node.1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ instead of printing to stderr.
167167
.It Fl -throw-deprecation
168168
Throw errors for deprecations.
169169
.
170+
.It Fl -title Ns = Ns Ar title
171+
Specify process.title on startup.
172+
.
170173
.It Fl -tls-cipher-list Ns = Ns Ar list
171174
Specify an alternative default TLS cipher list.
172175
Requires Node.js to be built with crypto support. (Default)

src/node.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ std::string config_warning_file; // NOLINT(runtime/string)
275275
// that is used by lib/internal/bootstrap/node.js
276276
bool config_expose_internals = false;
277277

278+
std::string config_process_title; // NOLINT(runtime/string)
279+
278280
bool v8_initialized = false;
279281

280282
bool linux_at_secure = false;
@@ -2521,6 +2523,7 @@ static void PrintHelp() {
25212523
" write warnings to file instead of\n"
25222524
" stderr\n"
25232525
" --throw-deprecation throw an exception on deprecations\n"
2526+
" --title=title the process title to use on start up\n"
25242527
#if HAVE_OPENSSL
25252528
" --tls-cipher-list=val use an alternative default TLS cipher "
25262529
"list\n"
@@ -2658,6 +2661,7 @@ static void CheckIfAllowedInEnv(const char* exe, bool is_env,
26582661
"--redirect-warnings",
26592662
"--require",
26602663
"--throw-deprecation",
2664+
"--title",
26612665
"--tls-cipher-list",
26622666
"--trace-deprecation",
26632667
"--trace-event-categories",
@@ -2828,6 +2832,8 @@ static void ParseArgs(int* argc,
28282832
} else if (strncmp(arg, "--security-revert=", 18) == 0) {
28292833
const char* cve = arg + 18;
28302834
Revert(cve);
2835+
} else if (strncmp(arg, "--title=", 8) == 0) {
2836+
config_process_title = arg + 8;
28312837
} else if (strcmp(arg, "--preserve-symlinks") == 0) {
28322838
config_preserve_symlinks = true;
28332839
} else if (strcmp(arg, "--preserve-symlinks-main") == 0) {
@@ -3319,6 +3325,10 @@ void Init(int* argc,
33193325

33203326
ProcessArgv(argc, argv, exec_argc, exec_argv);
33213327

3328+
// Set the process.title immediately after processing argv if --title is set.
3329+
if (!config_process_title.empty())
3330+
uv_set_process_title(config_process_title.c_str());
3331+
33223332
#if defined(NODE_HAVE_I18N_SUPPORT)
33233333
// If the parameter isn't given, use the env variable.
33243334
if (icu_data_dir.empty())
Lines changed: 13 additions & 0 deletions
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)