11use std:: collections:: HashMap ;
22use std:: env;
33use std:: path:: Path ;
4- use std:: path:: PathBuf ;
54use std:: process:: { Command , Stdio } ;
65use std:: sync:: OnceLock ;
76
@@ -247,7 +246,7 @@ impl LoopbackDevice {
247246 /// if the parent process dies unexpectedly
248247 fn spawn_cleanup_helper ( device_path : & str ) -> Result < LoopbackCleanupHandle > {
249248 // Try multiple strategies to find the bootc binary
250- let bootc_path = Self :: find_bootc_binary ( )
249+ let bootc_path = bootc_utils :: reexec :: executable_path ( )
251250 . context ( "Failed to locate bootc binary for cleanup helper" ) ?;
252251
253252 // Create the helper process
@@ -270,44 +269,6 @@ impl LoopbackDevice {
270269 Ok ( LoopbackCleanupHandle { child } )
271270 }
272271
273- /// Find the bootc binary using multiple strategies
274- fn find_bootc_binary ( ) -> Result < PathBuf > {
275- // Strategy 1: Try /proc/self/exe (works in most cases)
276- if let Ok ( exe_path) = std:: fs:: read_link ( "/proc/self/exe" ) {
277- if exe_path. exists ( ) {
278- return Ok ( exe_path) ;
279- } else {
280- tracing:: warn!( "/proc/self/exe points to non-existent path: {:?}" , exe_path) ;
281- }
282- } else {
283- tracing:: warn!( "Failed to read /proc/self/exe" ) ;
284- }
285-
286- // Strategy 2: Try argv[0] from std::env
287- if let Some ( argv0) = std:: env:: args ( ) . next ( ) {
288- let argv0_path = PathBuf :: from ( argv0) ;
289- if argv0_path. is_absolute ( ) && argv0_path. exists ( ) {
290- return Ok ( argv0_path) ;
291- }
292- // If it's relative, try to resolve it
293- if let Ok ( canonical) = argv0_path. canonicalize ( ) {
294- return Ok ( canonical) ;
295- }
296- }
297-
298- // Strategy 3: Try common installation paths
299- let common_paths = [ "/usr/bin/bootc" , "/usr/local/bin/bootc" ] ;
300-
301- for path in & common_paths {
302- let path_buf = PathBuf :: from ( path) ;
303- if path_buf. exists ( ) {
304- return Ok ( path_buf) ;
305- }
306- }
307-
308- anyhow:: bail!( "Could not locate bootc binary using any available strategy" )
309- }
310-
311272 // Shared backend for our `close` and `drop` implementations.
312273 fn impl_close ( & mut self ) -> Result < ( ) > {
313274 // SAFETY: This is the only place we take the option
0 commit comments