@@ -104,33 +104,35 @@ func createControlSocket(rootDir, id string) (string, int, error) {
104104 return "" , - 1 , fmt .Errorf ("unable to find location to write socket file" )
105105}
106106
107- // pid is an atomic type that implements JSON marshal/unmarshal interfaces.
108- type pid struct {
107+ // Pid is an atomic type that implements JSON marshal/unmarshal interfaces.
108+ type Pid struct {
109109 val atomicbitops.Int64
110110}
111111
112- func (p * pid ) store (pid int ) {
112+ // Store stores the PID in p.
113+ func (p * Pid ) Store (pid int ) {
113114 p .val .Store (int64 (pid ))
114115}
115116
116- func (p * pid ) load () int {
117+ // Load loads the PID from p.
118+ func (p * Pid ) Load () int {
117119 return int (p .val .Load ())
118120}
119121
120122// UnmarshalJSON implements json.Unmarshaler.UnmarshalJSON.
121- func (p * pid ) UnmarshalJSON (b []byte ) error {
123+ func (p * Pid ) UnmarshalJSON (b []byte ) error {
122124 var pid int
123125
124126 if err := json .Unmarshal (b , & pid ); err != nil {
125127 return err
126128 }
127- p .store (pid )
129+ p .Store (pid )
128130 return nil
129131}
130132
131133// MarshalJSON implements json.Marshaler.MarshalJSON
132- func (p * pid ) MarshalJSON () ([]byte , error ) {
133- return json .Marshal (p .load ())
134+ func (p * Pid ) MarshalJSON () ([]byte , error ) {
135+ return json .Marshal (p .Load ())
134136}
135137
136138// Sandbox wraps a sandbox process.
@@ -156,7 +158,7 @@ type Sandbox struct {
156158
157159 // Pid is the pid of the running sandbox. May be 0 if the sandbox
158160 // is not running.
159- Pid pid `json:"pid"`
161+ Pid Pid `json:"pid"`
160162
161163 // UID is the user ID in the parent namespace that the sandbox is running as.
162164 UID int `json:"uid"`
@@ -231,7 +233,7 @@ type Sandbox struct {
231233
232234// Getpid returns the process ID of the sandbox process.
233235func (s * Sandbox ) Getpid () int {
234- return s .Pid .load ()
236+ return s .Pid .Load ()
235237}
236238
237239// Args is used to configure a new sandbox.
@@ -388,7 +390,7 @@ func New(conf *config.Config, args *Args) (*Sandbox, error) {
388390
389391// CreateSubcontainer creates a container inside the sandbox.
390392func (s * Sandbox ) CreateSubcontainer (conf * config.Config , cid string , tty * os.File ) error {
391- log .Debugf ("Create sub-container %q in sandbox %q, PID: %d" , cid , s .ID , s .Pid .load ())
393+ log .Debugf ("Create sub-container %q in sandbox %q, PID: %d" , cid , s .ID , s .Pid .Load ())
392394
393395 var files []* os.File
394396 if tty != nil {
@@ -428,7 +430,7 @@ func (s *Sandbox) StartRoot(conf *config.Config, spec *specs.Spec) error {
428430 if err := hostsettings .Handle (conf ); err != nil {
429431 return fmt .Errorf ("host settings: %w (use --host-settings=ignore to bypass)" , err )
430432 }
431- pid := s .Pid .load ()
433+ pid := s .Pid .Load ()
432434 log .Debugf ("Start root sandbox %q, PID: %d" , s .ID , pid )
433435 conn , err := s .sandboxConnect ()
434436 if err != nil {
@@ -456,7 +458,7 @@ func (s *Sandbox) StartRoot(conf *config.Config, spec *specs.Spec) error {
456458
457459// StartSubcontainer starts running a sub-container inside the sandbox.
458460func (s * Sandbox ) StartSubcontainer (spec * specs.Spec , conf * config.Config , cid string , stdios , goferFiles , goferFilestores []* os.File , devIOFile * os.File , goferConfs []boot.GoferMountConf ) error {
459- log .Debugf ("Start sub-container %q in sandbox %q, PID: %d" , cid , s .ID , s .Pid .load ())
461+ log .Debugf ("Start sub-container %q in sandbox %q, PID: %d" , cid , s .ID , s .Pid .Load ())
460462
461463 if err := s .configureStdios (conf , stdios ); err != nil {
462464 return err
@@ -561,7 +563,7 @@ func (s *Sandbox) Restore(conf *config.Config, spec *specs.Spec, cid string, ima
561563 return err
562564 }
563565 // Configure the network.
564- if err := setupNetwork (conn , s .Pid .load (), conf , disableIPv6 ); err != nil {
566+ if err := setupNetwork (conn , s .Pid .Load (), conf , disableIPv6 ); err != nil {
565567 return fmt .Errorf ("setting up network: %v" , err )
566568 }
567569
@@ -575,7 +577,7 @@ func (s *Sandbox) Restore(conf *config.Config, spec *specs.Spec, cid string, ima
575577
576578// RestoreSubcontainer sends the restore call for a sub-container in the sandbox.
577579func (s * Sandbox ) RestoreSubcontainer (spec * specs.Spec , conf * config.Config , cid string , stdios , goferFiles , goferFilestoreFiles []* os.File , devIOFile * os.File , goferMountConf []boot.GoferMountConf ) error {
578- log .Debugf ("Restore sub-container %q in sandbox %q, PID: %d" , cid , s .ID , s .Pid .load ())
580+ log .Debugf ("Restore sub-container %q in sandbox %q, PID: %d" , cid , s .ID , s .Pid .Load ())
579581
580582 if err := s .configureStdios (conf , stdios ); err != nil {
581583 return err
@@ -680,7 +682,7 @@ func (s *Sandbox) ProcfsDump() ([]procfs.ProcessProcfsDump, error) {
680682
681683// NewCGroup returns the sandbox's Cgroup, or an error if it does not have one.
682684func (s * Sandbox ) NewCGroup () (cgroup.Cgroup , error ) {
683- return cgroup .NewFromPid (s .Pid .load (), false /* useSystemd */ )
685+ return cgroup .NewFromPid (s .Pid .Load (), false /* useSystemd */ )
684686}
685687
686688// Execute runs the specified command in the container. It returns the PID of
@@ -797,7 +799,7 @@ func (s *Sandbox) call(method string, arg, result any) error {
797799}
798800
799801func (s * Sandbox ) connError (err error ) error {
800- return fmt .Errorf ("connecting to control server at PID %d: %v" , s .Pid .load (), err )
802+ return fmt .Errorf ("connecting to control server at PID %d: %v" , s .Pid .Load (), err )
801803}
802804
803805// createSandboxProcess starts the sandbox as a subprocess by running the "boot"
@@ -1287,7 +1289,7 @@ func (s *Sandbox) createSandboxProcess(conf *config.Config, args *Args, startSyn
12871289 }
12881290
12891291 s .child = true
1290- s .Pid .store (cmd .Process .Pid )
1292+ s .Pid .Store (cmd .Process .Pid )
12911293 log .Infof ("Sandbox started, PID: %d" , cmd .Process .Pid )
12921294
12931295 return nil
@@ -1390,7 +1392,7 @@ func (s *Sandbox) destroy() error {
13901392 log .Warningf ("failed to delete control socket file %q: %v" , controlSocketPath , err )
13911393 }
13921394 }
1393- pid := s .Pid .load ()
1395+ pid := s .Pid .Load ()
13941396 if pid != 0 {
13951397 log .Debugf ("Killing sandbox %q" , s .ID )
13961398 if err := unix .Kill (pid , unix .SIGKILL ); err != nil && err != unix .ESRCH {
@@ -1610,7 +1612,7 @@ func (s *Sandbox) ExportMetrics(opts control.MetricsExportOpts) (*prometheus.Sna
16101612
16111613// IsRunning returns true if the sandbox or gofer process is running.
16121614func (s * Sandbox ) IsRunning () bool {
1613- pid := s .Pid .load ()
1615+ pid := s .Pid .Load ()
16141616 if pid == 0 {
16151617 return false
16161618 }
@@ -1721,7 +1723,7 @@ func (s *Sandbox) waitForStopped() error {
17211723 if s .child {
17221724 s .statusMu .Lock ()
17231725 defer s .statusMu .Unlock ()
1724- pid := s .Pid .load ()
1726+ pid := s .Pid .Load ()
17251727 if pid == 0 {
17261728 return nil
17271729 }
@@ -1730,7 +1732,7 @@ func (s *Sandbox) waitForStopped() error {
17301732 if _ , err := unix .Wait4 (int (pid ), & s .status , 0 , nil ); err != nil {
17311733 return fmt .Errorf ("error waiting the sandbox process: %v" , err )
17321734 }
1733- s .Pid .store (0 )
1735+ s .Pid .Store (0 )
17341736 return nil
17351737 }
17361738 ctx , cancel := context .WithTimeout (context .Background (), waitTimeout )
@@ -1878,7 +1880,7 @@ func (s *Sandbox) fixPidns(spec *specs.Spec) {
18781880 // pidns was not set, nothing to fix.
18791881 return
18801882 }
1881- if pidns .Path != fmt .Sprintf ("/proc/%d/ns/pid" , s .Pid .load ()) {
1883+ if pidns .Path != fmt .Sprintf ("/proc/%d/ns/pid" , s .Pid .Load ()) {
18821884 // Fix only if the PID namespace corresponds to the sandbox's.
18831885 return
18841886 }
0 commit comments