Skip to content

Commit d063056

Browse files
jasnelltargos
authored andcommitted
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 c4d7413 commit d063056

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
@@ -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

+3
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

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

280+
std::string config_process_title; // NOLINT(runtime/string)
281+
280282
bool v8_initialized = false;
281283

282284
bool linux_at_secure = false;
@@ -3066,6 +3068,7 @@ static void PrintHelp() {
30663068
" write warnings to file instead of\n"
30673069
" stderr\n"
30683070
" --throw-deprecation throw an exception on deprecations\n"
3071+
" --title=title the process title to use on start up\n"
30693072
#if HAVE_OPENSSL
30703073
" --tls-cipher-list=val use an alternative default TLS cipher "
30713074
"list\n"
@@ -3204,6 +3207,7 @@ static void CheckIfAllowedInEnv(const char* exe, bool is_env,
32043207
"--redirect-warnings",
32053208
"--require",
32063209
"--throw-deprecation",
3210+
"--title",
32073211
"--tls-cipher-list",
32083212
"--trace-deprecation",
32093213
"--trace-event-categories",
@@ -3374,6 +3378,8 @@ static void ParseArgs(int* argc,
33743378
} else if (strncmp(arg, "--security-revert=", 18) == 0) {
33753379
const char* cve = arg + 18;
33763380
Revert(cve);
3381+
} else if (strncmp(arg, "--title=", 8) == 0) {
3382+
config_process_title = arg + 8;
33773383
} else if (strcmp(arg, "--preserve-symlinks") == 0) {
33783384
config_preserve_symlinks = true;
33793385
} else if (strcmp(arg, "--preserve-symlinks-main") == 0) {
@@ -3868,6 +3874,10 @@ void Init(int* argc,
38683874

38693875
ProcessArgv(argc, argv, exec_argc, exec_argv);
38703876

3877+
// Set the process.title immediately after processing argv if --title is set.
3878+
if (!config_process_title.empty())
3879+
uv_set_process_title(config_process_title.c_str());
3880+
38713881
#if defined(NODE_HAVE_I18N_SUPPORT)
38723882
// If the parameter isn't given, use the env variable.
38733883
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)