debugcurrentexe: command to show the path to the main executable

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
This commit is contained in:
Jun Wu 2023-10-09 15:23:47 -07:00 committed by Facebook GitHub Bot
parent 98732c7b0d
commit 4272035001
4 changed files with 36 additions and 0 deletions

View File

@ -14,6 +14,7 @@ pub use super::IO;
commands! {
mod args;
mod currentexe;
mod dumpinternalconfig;
mod dumpindexedlog;
mod dumptrace;

View File

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

View File

@ -110,6 +110,7 @@ Show debug commands if there are no other candidates
debugconfig
debugcopytrace
debugcreatestreamclonebundle
debugcurrentexe
debugdag
debugdata
debugdatapack
@ -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

View File

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