@@ -226,7 +226,14 @@ fn create_tpm_device_node() -> Result<()> {
226226 . trim ( )
227227 . split_once ( ':' )
228228 . context ( "invalid /sys/class/tpm/tpm0/dev" ) ?;
229- command ( "mknod" , & [ "/dev/tpm0" , "c" , major, minor] )
229+ if let Err ( error) = command ( "mknod" , & [ "/dev/tpm0" , "c" , major, minor] ) {
230+ // udev can create the node between the existence check above and
231+ // mknod. In that case the requested device is already available.
232+ if !Path :: new ( "/dev/tpm0" ) . exists ( ) {
233+ return Err ( error) ;
234+ }
235+ }
236+ Ok ( ( ) )
230237}
231238
232239fn provision_nv ( index : & str , contents : & Path ) -> Result < ( ) > {
@@ -314,7 +321,12 @@ pub fn run_nitro_vtpm(runtime_dir: &Path, config: &TeeSimulatorConfig) -> Result
314321 . trim ( )
315322 . split_once ( ':' )
316323 . context ( "invalid vTPM device number" ) ?;
317- command ( "mknod" , & [ "/dev/tpm0" , "c" , major, minor] ) ?;
324+ if let Err ( error) = command ( "mknod" , & [ "/dev/tpm0" , "c" , major, minor] ) {
325+ // udev races manual node creation after VTPM_PROXY_IOC_NEW_DEV.
326+ if !Path :: new ( "/dev/tpm0" ) . exists ( ) {
327+ return Err ( error) ;
328+ }
329+ }
318330 sd_notify:: notify ( true , & [ sd_notify:: NotifyState :: Ready ] ) ?;
319331 let result = proxy_thread
320332 . join ( )
0 commit comments