@@ -24,7 +24,6 @@ const EXCLFS_BIN = '/bin/exclfs'
2424const HOME = '/tmp'
2525
2626
27- var cmdline
2827var ROOT_HOME = ''
2928var single
3029
@@ -405,8 +404,8 @@ function pathToUserfs(error, result)
405404{
406405 if ( error ) console . warn ( error )
407406
408- cmdline . root = result [ 'path to userfs' ]
409- return mountUsersFS ( cmdline )
407+ this . root = result [ 'path to userfs' ]
408+ return mountUsersFS ( this )
410409}
411410
412411/**
@@ -419,7 +418,7 @@ function askLocation(error)
419418 console . warn ( 'Could not find userfs:' , error )
420419
421420 prompt . start ( )
422- prompt . get ( 'path to userfs' , pathToUserfs )
421+ prompt . get ( 'path to userfs' , pathToUserfs . bind ( this ) )
423422}
424423
425424/**
@@ -491,6 +490,7 @@ function prepareSessions()
491490 */
492491function mountUsersFS ( cmdline )
493492{
493+ // Allow to override or disable `usersDev`
494494 var usersDev = process . env . root
495495 if ( usersDev === undefined ) usersDev = cmdline . root
496496
@@ -502,7 +502,7 @@ function mountUsersFS(cmdline)
502502 else if ( usersDev )
503503 waitUntilExists ( usersDev , 5 , function ( error )
504504 {
505- if ( error ) return askLocation ( error )
505+ if ( error ) return askLocation . call ( cmdline , error )
506506
507507 // Mount users filesystem
508508 var type = process . env . rootfstype || cmdline . rootfstype || 'auto'
@@ -547,23 +547,37 @@ rimraf('/sbin')
547547// Symlinks for config data optained from `procfs`
548548mkdirp ( '/etc' , '0100' , function ( error )
549549{
550- if ( error && error . code != 'EEXIST' ) return callback ( error )
551- cmdline = linuxCmdline ( fs . readFileSync ( '/proc/cmdline' , 'utf8' ) )
550+ if ( error && error . code != 'EEXIST' ) throw error
552551
553- try {
554- fs . symlinkSync ( '/proc/mounts' , '/etc/mtab' )
555- } catch ( e ) {
556- if ( e && e . code !== 'EEXIST' ) return callback ( e )
552+ const symlinks =
553+ {
554+ '/proc/mounts' : '/etc/mtab' ,
555+ '/proc/net/pnp' : '/etc/resolv.conf'
557556 }
558557
559- try {
560- fs . symlinkSync ( '/proc/net/pnp' , '/etc/resolv.conf' )
561- } catch ( e ) {
562- if ( e && e . code !== 'EEXIST' ) return callback ( e )
563- }
558+ each ( symlinks , function ( dest , src , callback )
559+ {
560+ fs . symlink ( src , dest , function ( error )
561+ {
562+ if ( error && error . code !== 'EEXIST' ) return callback ( error )
563+
564+ callback ( )
565+ } )
566+ } ,
567+ function ( error )
568+ {
569+ if ( error ) throw error
570+
571+ fs . readFile ( '/proc/cmdline' , 'utf8' , function ( error , data )
572+ {
573+ if ( error ) throw error
564574
565- single = cmdline . single
575+ var cmdline = linuxCmdline ( data )
566576
567- // Mount root filesystem
568- mountUsersFS ( cmdline )
577+ single = cmdline . single
578+
579+ // Mount root filesystem
580+ mountUsersFS ( cmdline )
581+ } )
582+ } )
569583} )
0 commit comments