@@ -62,6 +62,8 @@ type procInfo struct {
62
62
waitErr error
63
63
}
64
64
65
+ var mu sync.Mutex
66
+
65
67
// process informations named with proc.
66
68
var procs []* procInfo
67
69
@@ -128,6 +130,9 @@ func readProcfile(cfg *config) error {
128
130
if err != nil {
129
131
return err
130
132
}
133
+ mu .Lock ()
134
+ defer mu .Unlock ()
135
+
131
136
procs = []* procInfo {}
132
137
index := 0
133
138
for _ , line := range strings .Split (string (content ), "\n " ) {
@@ -195,6 +200,10 @@ func check(cfg *config) error {
195
200
if err != nil {
196
201
return err
197
202
}
203
+
204
+ mu .Lock ()
205
+ defer mu .Unlock ()
206
+
198
207
keys := make ([]string , len (procs ))
199
208
i := 0
200
209
for _ , proc := range procs {
@@ -207,6 +216,9 @@ func check(cfg *config) error {
207
216
}
208
217
209
218
func findProc (name string ) * procInfo {
219
+ mu .Lock ()
220
+ defer mu .Unlock ()
221
+
210
222
for _ , proc := range procs {
211
223
if proc .name == name {
212
224
return proc
@@ -221,6 +233,7 @@ func start(ctx context.Context, sig <-chan os.Signal, cfg *config) error {
221
233
if err != nil {
222
234
return err
223
235
}
236
+
224
237
ctx , cancel := context .WithCancel (ctx )
225
238
// Cancel the RPC server when procs have returned/errored, cancel the
226
239
// context anyway in case of early return.
@@ -238,7 +251,9 @@ func start(ctx context.Context, sig <-chan os.Signal, cfg *config) error {
238
251
maxProcNameLength = len (v )
239
252
}
240
253
}
254
+ mu .Lock ()
241
255
procs = tmp
256
+ mu .Unlock ()
242
257
}
243
258
godotenv .Load ()
244
259
rpcChan := make (chan * rpcMessage , 10 )
0 commit comments