@@ -24,7 +24,6 @@ const EXCLFS_BIN = '/bin/exclfs'
24
24
const HOME = '/tmp'
25
25
26
26
27
- var cmdline
28
27
var ROOT_HOME = ''
29
28
var single
30
29
@@ -405,8 +404,8 @@ function pathToUserfs(error, result)
405
404
{
406
405
if ( error ) console . warn ( error )
407
406
408
- cmdline . root = result [ 'path to userfs' ]
409
- return mountUsersFS ( cmdline )
407
+ this . root = result [ 'path to userfs' ]
408
+ return mountUsersFS ( this )
410
409
}
411
410
412
411
/**
@@ -419,7 +418,7 @@ function askLocation(error)
419
418
console . warn ( 'Could not find userfs:' , error )
420
419
421
420
prompt . start ( )
422
- prompt . get ( 'path to userfs' , pathToUserfs )
421
+ prompt . get ( 'path to userfs' , pathToUserfs . bind ( this ) )
423
422
}
424
423
425
424
/**
@@ -491,6 +490,7 @@ function prepareSessions()
491
490
*/
492
491
function mountUsersFS ( cmdline )
493
492
{
493
+ // Allow to override or disable `usersDev`
494
494
var usersDev = process . env . root
495
495
if ( usersDev === undefined ) usersDev = cmdline . root
496
496
@@ -502,7 +502,7 @@ function mountUsersFS(cmdline)
502
502
else if ( usersDev )
503
503
waitUntilExists ( usersDev , 5 , function ( error )
504
504
{
505
- if ( error ) return askLocation ( error )
505
+ if ( error ) return askLocation . call ( cmdline , error )
506
506
507
507
// Mount users filesystem
508
508
var type = process . env . rootfstype || cmdline . rootfstype || 'auto'
@@ -547,23 +547,37 @@ rimraf('/sbin')
547
547
// Symlinks for config data optained from `procfs`
548
548
mkdirp ( '/etc' , '0100' , function ( error )
549
549
{
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
552
551
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'
557
556
}
558
557
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
564
574
565
- single = cmdline . single
575
+ var cmdline = linuxCmdline ( data )
566
576
567
- // Mount root filesystem
568
- mountUsersFS ( cmdline )
577
+ single = cmdline . single
578
+
579
+ // Mount root filesystem
580
+ mountUsersFS ( cmdline )
581
+ } )
582
+ } )
569
583
} )
0 commit comments