all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH pve-xtermjs] Avoid allocating in `pre_exec` closure
@ 2025-12-05 12:47 Yuki Sireneva
  2025-12-09 16:25   ` [pve-devel] applied: [pbs-devel] " Thomas Lamprecht
  0 siblings, 1 reply; 3+ messages in thread
From: Yuki Sireneva @ 2025-12-05 12:47 UTC (permalink / raw)
  To: pbs-devel; +Cc: Yuki Sireneva

`Error::new` allocates memory (see [148971]). This is bad in
multi-threaded programs, which pve-xtermjs AFAIK is. If the fork occurs
while the allocator lock is held by another thread, deadlocks can occur,
since there's no one left in the new process to unlock the mutex.
I do not believe this is UB, and modern libc offer protections against
this issue, but this isn't POSIX-compliant and should preferably be
avoided.

`nix` provides a non-allocating `impl From<Errno> for std::io::Error`,
which can be used instead. This ensures that the correct error code is
forwarded to the parent process, instead of the default `-EINVAL`.

[rust#148971]: https://github.com/rust-lang/rust/pull/148971

Signed-off-by: Yuki Sireneva <yuki.utk8g@gmail.com>
---
 termproxy/src/main.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/termproxy/src/main.rs b/termproxy/src/main.rs
index 135468d..31f5a41 100644
--- a/termproxy/src/main.rs
+++ b/termproxy/src/main.rs
@@ -287,7 +287,7 @@ fn run_pty<'a>(mut full_cmd: impl Iterator<Item = &'a OsString>) -> Result<Pty>
 
     unsafe {
         command.pre_exec(move || {
-            make_controlling_terminal(&secondary_name).map_err(Error::other)?;
+            make_controlling_terminal(&secondary_name)?;
             Ok(())
         });
     }
-- 
2.51.2


_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-12-09 16:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-05 12:47 [pbs-devel] [PATCH pve-xtermjs] Avoid allocating in `pre_exec` closure Yuki Sireneva
2025-12-09 16:25 ` [pbs-devel] applied: " Thomas Lamprecht
2025-12-09 16:25   ` [pve-devel] applied: [pbs-devel] " Thomas Lamprecht

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal