File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -333,6 +333,7 @@ int main(int argc, char *argv[]) {
333333                .sa_handler  =  signal_handler ,
334334        };
335335        bool  has_procfs  =  false;
336+         bool  has_sysroot  =  false;
336337
337338        parse_conf ();
338339
@@ -433,6 +434,25 @@ int main(int argc, char *argv[]) {
433434                        if  (r  <  0 )
434435                                return  EXIT_FAILURE ;
435436                }
437+                 if  (!has_sysroot ) {
438+                         // sysroot is where systemd will switch root when 
439+                         // switching from initramfs to the root fs. We chroot 
440+                         // there so we can write later the svg file. 
441+                         // 
442+                         // TODO instead of detecting this way, use signal by initramfs signal. 
443+                         has_sysroot  =  access ("/sysroot" , F_OK ) ==  0 ;
444+                         if  (has_sysroot ) {
445+                                 // chroot does not change the cwd of the process, so we do that first 
446+                                 if  (chdir ("/sysroot" ) !=  0 ) {
447+                                         log_info_errno (errno , "cannot chdir to /sysroot: %m\n" );
448+                                         return  EXIT_FAILURE ;
449+                                 }
450+                                 if  (chroot ("." ) !=  0 )  {
451+                                         log_info_errno (errno , "cannot chroot: %m\n" );
452+                                         return  EXIT_FAILURE ;
453+                                 }
454+                         }
455+                 }
436456
437457                sample_stop  =  gettime_ns ();
438458
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments