@@ -309,12 +309,7 @@ func jail(ctx context.Context, m *Machine, cfg *Config) error {
309
309
stderr = os .Stderr
310
310
}
311
311
312
- stdin := cfg .JailerCfg .Stdin
313
- if stdin == nil {
314
- stdin = os .Stdin
315
- }
316
-
317
- m .cmd = NewJailerCommandBuilder ().
312
+ builder := NewJailerCommandBuilder ().
318
313
WithID (cfg .JailerCfg .ID ).
319
314
WithUID (* cfg .JailerCfg .UID ).
320
315
WithGID (* cfg .JailerCfg .GID ).
@@ -324,9 +319,13 @@ func jail(ctx context.Context, m *Machine, cfg *Config) error {
324
319
WithDaemonize (cfg .JailerCfg .Daemonize ).
325
320
WithSeccompLevel (cfg .JailerCfg .SeccompLevel ).
326
321
WithStdout (stdout ).
327
- WithStderr (stderr ).
328
- WithStdin (stdin ).
329
- Build (ctx )
322
+ WithStderr (stderr )
323
+
324
+ if stdin := cfg .JailerCfg .Stdin ; stdin != nil {
325
+ builder = builder .WithStdin (stdin )
326
+ }
327
+
328
+ m .cmd = builder .Build (ctx )
330
329
331
330
if err := cfg .JailerCfg .ChrootStrategy .AdaptHandlers (& m .Handlers ); err != nil {
332
331
return err
@@ -375,6 +374,29 @@ func LinkFilesHandler(rootfs, kernelImageFileName string) Handler {
375
374
}
376
375
377
376
m .cfg .KernelImagePath = kernelImageFileName
377
+
378
+ for _ , fifoPath := range []* string {& m .cfg .LogFifo , & m .cfg .MetricsFifo } {
379
+ if fifoPath == nil || * fifoPath == "" {
380
+ continue
381
+ }
382
+
383
+ fileName := filepath .Base (* fifoPath )
384
+ if err := linkFileToRootFS (
385
+ m .cfg .JailerCfg ,
386
+ filepath .Join (rootfs , fileName ),
387
+ * fifoPath ,
388
+ ); err != nil {
389
+ return err
390
+ }
391
+
392
+ if err := os .Chown (filepath .Join (rootfs , fileName ), * m .cfg .JailerCfg .UID , * m .cfg .JailerCfg .GID ); err != nil {
393
+ return err
394
+ }
395
+
396
+ // update fifoPath as jailer works relative to the chroot dir
397
+ * fifoPath = fileName
398
+ }
399
+
378
400
return nil
379
401
},
380
402
}
@@ -395,18 +417,18 @@ func NewNaiveChrootStrategy(rootfs, kernelImagePath string) NaiveChrootStrategy
395
417
}
396
418
}
397
419
398
- // ErrCreateMachineHandlerMissing occurs when the CreateMachineHandler is not
399
- // present in FcInit .
400
- var ErrCreateMachineHandlerMissing = fmt .Errorf ("%s is missing from FcInit's list" , CreateMachineHandlerName )
420
+ // ErrRequiredHandlerMissing occurs when a required handler is not present in
421
+ // the handler list .
422
+ var ErrRequiredHandlerMissing = fmt .Errorf ("required handler is missing from FcInit's list" )
401
423
402
424
// AdaptHandlers will inject the LinkFilesHandler into the handler list.
403
425
func (s NaiveChrootStrategy ) AdaptHandlers (handlers * Handlers ) error {
404
- if ! handlers .FcInit .Has (CreateMachineHandlerName ) {
405
- return ErrCreateMachineHandlerMissing
426
+ if ! handlers .FcInit .Has (CreateLogFilesHandlerName ) {
427
+ return ErrRequiredHandlerMissing
406
428
}
407
429
408
430
handlers .FcInit = handlers .FcInit .AppendAfter (
409
- CreateMachineHandlerName ,
431
+ CreateLogFilesHandlerName ,
410
432
LinkFilesHandler (filepath .Join (s .Rootfs , rootfsFolderName ), filepath .Base (s .KernelImagePath )),
411
433
)
412
434
0 commit comments