Skip to content

Commit

Permalink
src: add --title command line argument
Browse files Browse the repository at this point in the history
Simple utility command line argument for setting the process
title on process startup.

PR-URL: nodejs#21477
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
jasnell committed Jul 10, 2018
1 parent 6705356 commit 9d71619
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`
Expand Down
3 changes: 3 additions & 0 deletions doc/node.1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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())
Expand Down
13 changes: 13 additions & 0 deletions test/parallel/test-process-title-cli.js
Original file line number Diff line number Diff line change
@@ -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');

0 comments on commit 9d71619

Please sign in to comment.