Skip to content

Commit

Permalink
debugcurrentexe: command to show the path to the main executable
Browse files Browse the repository at this point in the history
Summary:
This command prints the path to the main executable. It's similar to
`sys.executable` in `debugshell`, but without using Python.

The main motivation is to better support the node IPC channel on Windows.
The problem is that by default, libc (CRT, C runtime) fds (not confused with
Windows OS handles) are *not* inherited. To inherit them you'll need to set
the `lpReserved2` in `STARTUPINFOA` struct when creating a process. The field
is [documented](https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/ns-processthreadsapi-startupinfoa) as:

  cbReserved2
  Reserved for use by the C Run-time; must be zero.

  lpReserved2
  Reserved for use by the C Run-time; must be NULL.

Rust stdlib does not provide a way to set them in the C runtime compatible way
to pass C fds. nodejs/libuv sets them directly, ignoring the "must be NULL"
suggestions.

On Windows, there are multiple layers of wrappers today.

For the telemetry wrapper we might teach it to translate the fd to Windows HANDLE
and teach the main binary to also accept a HANDLE.

Reviewed By: sggutier

Differential Revision: D50020026

fbshipit-source-id: 1798a30848b2b76add63f5637594784e6e7e096c
  • Loading branch information
quark-zju authored and facebook-github-bot committed Oct 9, 2023
1 parent 98732c7 commit 4272035
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions eden/scm/lib/hgcommands/src/commands/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub use super::IO;

commands! {
mod args;
mod currentexe;
mod dumpinternalconfig;
mod dumpindexedlog;
mod dumptrace;
Expand Down
31 changes: 31 additions & 0 deletions eden/scm/lib/hgcommands/src/commands/debug/currentexe.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/

use clidispatch::ReqCtx;

use super::ConfigSet;
use super::NoOpts;
use super::Result;

pub fn run(ctx: ReqCtx<NoOpts>, _config: &mut ConfigSet) -> Result<u8> {
let path = std::env::current_exe()?;
let out = format!("{}\n", path.display());
ctx.io().write(out)?;
Ok(0)
}

pub fn aliases() -> &'static str {
"debugcurrentexe"
}

pub fn doc() -> &'static str {
"show the path to the main executable"
}

pub fn synopsis() -> Option<&'static str> {
None
}
2 changes: 2 additions & 0 deletions eden/scm/tests/test-completion.t
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ Show debug commands if there are no other candidates
debugconfig
debugcopytrace
debugcreatestreamclonebundle
debugcurrentexe
debugdag
debugdata
debugdatapack
Expand Down Expand Up @@ -437,6 +438,7 @@ Show all commands + options
debugcomplete: options
debugcopytrace: source, dest
debugcreatestreamclonebundle:
debugcurrentexe:
debugdag: bookmarks, branches, dots, spaces
debugdata: changelog, manifest, dir
debugdatapack: long, node, node-delta
Expand Down
2 changes: 2 additions & 0 deletions eden/scm/tests/test-help.t
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,8 @@ Test list of internal help commands
trace the copy of the given files from source to dest commit
debugcreatestreamclonebundle
create a stream clone bundle file
debugcurrentexe
show the path to the main executable
debugdag format the changelog or an index DAG as a concise textual
description
debugdata dump the contents of a data file revision
Expand Down

0 comments on commit 4272035

Please sign in to comment.