1
1
'use strict'
2
2
3
3
const runner = require ( 'child_process' )
4
- const debug = require ( 'debug' ) ( 'subchild' )
4
+ const debug = require ( 'debug' )
5
+ const log = debug ( 'ipfsd-ctl:sclite' )
5
6
6
7
const children = [ ]
7
8
@@ -13,30 +14,29 @@ function removeChild (child) {
13
14
}
14
15
15
16
function killAll ( ) {
16
- debug ( 'killing all children' )
17
+ log ( 'killing all children' )
17
18
let child
18
19
while ( ( child = children . shift ( ) ) !== undefined ) {
19
- debug ( child . pid , 'killing' )
20
+ log ( child . pid , 'killing' )
20
21
child . kill ( )
21
22
}
22
23
}
23
24
24
- process . once ( 'error' , killAll )
25
25
process . once ( 'exit' , killAll )
26
26
process . once ( 'SIGTERM' , killAll )
27
27
process . once ( 'SIGINT' , killAll )
28
28
29
29
function run ( cmd , args , opts ) {
30
30
const child = runner . execFile ( cmd , args , opts )
31
- debug ( child . pid , 'new' )
31
+ log ( child . pid , 'new' )
32
32
33
33
children . push ( child )
34
34
child . once ( 'error' , ( ) => {
35
- debug ( child . pid , 'error' )
35
+ log ( child . pid , 'error' )
36
36
removeChild ( child )
37
37
} )
38
38
child . once ( 'exit' , ( ) => {
39
- debug ( child . pid , 'exit' )
39
+ log ( child . pid , 'exit' )
40
40
removeChild ( child )
41
41
} )
42
42
return child
0 commit comments