@@ -344,9 +344,9 @@ func (wbs *InWorkspaceServiceServer) SetupPairVeths(ctx context.Context, req *ap
344
344
return nil , status .Errorf (codes .Internal , "cannot setup a peer veths" )
345
345
}
346
346
347
- err = nsinsider (wbs .Session .InstanceID , int (pid ), func (c * exec.Cmd ) {
347
+ err = nsinsider (wbs .Session .InstanceID , int (containerPID ), func (c * exec.Cmd ) {
348
348
c .Args = append (c .Args , "enable-ip-forward" )
349
- }, enterMountNS (true ))
349
+ }, enterNetNS (true ), enterMountNSPid ( 1 ))
350
350
if err != nil {
351
351
log .WithError (err ).WithFields (wbs .Session .OWI ()).Error ("SetupPairVeths: cannot enable IP forwarding" )
352
352
return nil , status .Errorf (codes .Internal , "cannot enable IP forwarding" )
@@ -736,9 +736,10 @@ func cleanupMaskedMount(owi map[string]interface{}, base string, paths []string)
736
736
}
737
737
738
738
type nsinsiderOpts struct {
739
- MountNS bool
740
- PidNS bool
741
- NetNS bool
739
+ MountNS bool
740
+ PidNS bool
741
+ NetNS bool
742
+ MountNSPid int
742
743
}
743
744
744
745
func enterMountNS (enter bool ) nsinsiderOpt {
@@ -759,6 +760,13 @@ func enterNetNS(enter bool) nsinsiderOpt {
759
760
}
760
761
}
761
762
763
+ func enterMountNSPid (pid int ) nsinsiderOpt {
764
+ return func (o * nsinsiderOpts ) {
765
+ o .MountNS = true
766
+ o .MountNSPid = pid
767
+ }
768
+ }
769
+
762
770
type nsinsiderOpt func (* nsinsiderOpts )
763
771
764
772
func nsinsider (instanceID string , targetPid int , mod func (* exec.Cmd ), opts ... nsinsiderOpt ) error {
@@ -781,10 +789,14 @@ func nsinsider(instanceID string, targetPid int, mod func(*exec.Cmd), opts ...ns
781
789
}
782
790
var nss []mnt
783
791
if cfg .MountNS {
792
+ tpid := targetPid
793
+ if cfg .MountNSPid != 0 {
794
+ tpid = cfg .MountNSPid
795
+ }
784
796
nss = append (nss ,
785
- mnt {"_LIBNSENTER_ROOTFD" , fmt .Sprintf ("/proc/%d/root" , targetPid ), unix .O_PATH },
786
- mnt {"_LIBNSENTER_CWDFD" , fmt .Sprintf ("/proc/%d/cwd" , targetPid ), unix .O_PATH },
787
- mnt {"_LIBNSENTER_MNTNSFD" , fmt .Sprintf ("/proc/%d/ns/mnt" , targetPid ), os .O_RDONLY },
797
+ mnt {"_LIBNSENTER_ROOTFD" , fmt .Sprintf ("/proc/%d/root" , tpid ), unix .O_PATH },
798
+ mnt {"_LIBNSENTER_CWDFD" , fmt .Sprintf ("/proc/%d/cwd" , tpid ), unix .O_PATH },
799
+ mnt {"_LIBNSENTER_MNTNSFD" , fmt .Sprintf ("/proc/%d/ns/mnt" , tpid ), os .O_RDONLY },
788
800
)
789
801
}
790
802
if cfg .PidNS {
0 commit comments