make self-update work on Linux

This commit is contained in:
Connor Peet
2022-10-17 13:34:06 -07:00
parent 7c3740a7e7
commit 4e9bdbd44f
4 changed files with 71 additions and 17 deletions

View File

@@ -3,8 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
use std::process::Stdio;
use async_trait::async_trait;
use tokio::sync::oneshot;
@@ -215,6 +213,10 @@ async fn serve_with_csa(
csa: CodeServerArgs,
shutdown_rx: Option<oneshot::Receiver<()>>,
) -> Result<i32, AnyError> {
// Intentionally read before starting the server. If the server updated and
// respawn is requested, the old binary will get renamed, and then
// current_exe will point to the wrong path.
let current_exe = std::env::current_exe().unwrap();
let platform = spanf!(log, log.span("prereq"), PreReqChecker::new().verify())?;
let auth = Auth::new(&paths, log.clone());
@@ -244,11 +246,8 @@ async fn serve_with_csa(
// reuse current args, but specify no-forward since tunnels will
// already be running in this process, and we cannot do a login
let args = std::env::args().skip(1).collect::<Vec<String>>();
let exit = std::process::Command::new(std::env::current_exe().unwrap())
let exit = std::process::Command::new(current_exe)
.args(args)
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.stdin(Stdio::inherit())
.spawn()
.map_err(|e| wrap(e, "error respawning after update"))?
.wait()