1
1
use std:: collections:: HashMap ;
2
2
use std:: env;
3
3
use std:: path:: Path ;
4
- use std:: path:: PathBuf ;
5
4
use std:: process:: { Command , Stdio } ;
6
5
use std:: sync:: OnceLock ;
7
6
@@ -247,7 +246,7 @@ impl LoopbackDevice {
247
246
/// if the parent process dies unexpectedly
248
247
fn spawn_cleanup_helper ( device_path : & str ) -> Result < LoopbackCleanupHandle > {
249
248
// 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 ( )
251
250
. context ( "Failed to locate bootc binary for cleanup helper" ) ?;
252
251
253
252
// Create the helper process
@@ -270,44 +269,6 @@ impl LoopbackDevice {
270
269
Ok ( LoopbackCleanupHandle { child } )
271
270
}
272
271
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
-
311
272
// Shared backend for our `close` and `drop` implementations.
312
273
fn impl_close ( & mut self ) -> Result < ( ) > {
313
274
// SAFETY: This is the only place we take the option
0 commit comments