File tree Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
- const run = require ( 'subcomandante' )
3
+ const run = require ( './ subcomandante-lite ' )
4
4
const once = require ( 'once' )
5
5
const debug = require ( 'debug' ) ( 'ipfsd-ctl:run' )
6
6
const path = require ( 'path' )
Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ const runner = require ( 'child_process' )
4
+ const debug = require ( 'debug' ) ( 'subchild' )
5
+
6
+ const children = [ ]
7
+
8
+ function removeChild ( child ) {
9
+ const i = children . indexOf ( child )
10
+ if ( i !== - 1 ) {
11
+ children . slice ( i , 1 )
12
+ }
13
+ }
14
+
15
+ function killAll ( ) {
16
+ debug ( 'killing all children' )
17
+ let child
18
+ while ( ( child = children . shift ( ) ) !== undefined ) {
19
+ debug ( child . pid , 'killing' )
20
+ child . kill ( ) ;
21
+ }
22
+ }
23
+
24
+ process . once ( 'error' , killAll )
25
+ process . once ( 'exit' , killAll )
26
+ process . once ( 'SIGTERM' , killAll )
27
+ process . once ( 'SIGINT' , killAll )
28
+
29
+ function run ( cmd , args , opts ) {
30
+ const child = runner . execFile ( cmd , args , opts )
31
+ debug ( child . pid , 'new' )
32
+
33
+ children . push ( child ) ;
34
+ child . once ( 'error' , ( ) => {
35
+ debug ( child . pid , 'error' )
36
+ removeChild ( child )
37
+ } )
38
+ child . once ( 'exit' , ( ) => {
39
+ debug ( child . pid , 'exit' )
40
+ removeChild ( child ) ;
41
+ } )
42
+ return child
43
+ }
44
+
45
+ module . exports = run
You can’t perform that action at this time.
0 commit comments