@@ -1803,26 +1803,36 @@ func (d *lxc) DeviceEventHandler(runConf *deviceConfig.RunConfig) error {
1803
1803
1804
1804
// Generate uevent inside container if requested.
1805
1805
if len (runConf .Uevents ) > 0 {
1806
- pidFdNr , pidFd := d .inheritInitPidFd ()
1807
- if pidFdNr >= 0 {
1806
+ pidFd := d .inheritInitPidFd ()
1807
+ pidFdNr := "-1"
1808
+ if pidFd != nil {
1808
1809
defer func () { _ = pidFd .Close () }()
1810
+ pidFdNr = "3"
1809
1811
}
1810
1812
1811
1813
for _ , eventParts := range runConf .Uevents {
1812
- ueventArray := make ([]string , 6 )
1813
- ueventArray [0 ] = "forkuevent"
1814
- ueventArray [1 ] = "inject"
1815
- ueventArray [2 ] = "--"
1816
- ueventArray [3 ] = fmt .Sprintf ("%d" , d .InitPID ())
1817
- ueventArray [4 ] = fmt .Sprintf ("%d" , pidFdNr )
1818
1814
length := 0
1819
1815
for _ , part := range eventParts {
1820
1816
length = length + len (part ) + 1
1821
1817
}
1822
1818
1823
- ueventArray [5 ] = fmt .Sprintf ("%d" , length )
1824
- ueventArray = append (ueventArray , eventParts ... )
1825
- _ , _ , err := subprocess .RunCommandSplit (context .TODO (), nil , []* os.File {pidFd }, d .state .OS .ExecPath , ueventArray ... )
1819
+ args := []string {
1820
+ "forkuevent" ,
1821
+ "inject" ,
1822
+ "--" ,
1823
+ fmt .Sprintf ("%d" , d .InitPID ()),
1824
+ pidFdNr ,
1825
+ fmt .Sprintf ("%d" , length ),
1826
+ }
1827
+
1828
+ args = append (args , eventParts ... )
1829
+
1830
+ _ , _ , err := subprocess .RunCommandSplit (
1831
+ context .TODO (),
1832
+ nil ,
1833
+ []* os.File {pidFd },
1834
+ d .state .OS .ExecPath ,
1835
+ args ... )
1826
1836
if err != nil {
1827
1837
return err
1828
1838
}
@@ -7221,17 +7231,17 @@ func (d *lxc) templateApplyNow(trigger instance.TemplateTrigger) error {
7221
7231
return nil
7222
7232
}
7223
7233
7224
- func (d * lxc ) inheritInitPidFd () ( int , * os.File ) {
7234
+ func (d * lxc ) inheritInitPidFd () * os.File {
7225
7235
if d .state .OS .PidFds {
7226
7236
pidFdFile , err := d .InitPidFd ()
7227
7237
if err != nil {
7228
- return - 1 , nil
7238
+ return nil
7229
7239
}
7230
7240
7231
- return 3 , pidFdFile
7241
+ return pidFdFile
7232
7242
}
7233
7243
7234
- return - 1 , nil
7244
+ return nil
7235
7245
}
7236
7246
7237
7247
// FileSFTPConn returns a connection to the forkfile handler.
@@ -7356,8 +7366,8 @@ func (d *lxc) FileSFTPConn() (net.Conn, error) {
7356
7366
extraFiles = append (extraFiles , rootfsFile )
7357
7367
7358
7368
// Get the pidfd.
7359
- pidFdNr , pidFd := d .inheritInitPidFd ()
7360
- if pidFdNr >= 0 {
7369
+ pidFd := d .inheritInitPidFd ()
7370
+ if pidFd != nil {
7361
7371
defer func () { _ = pidFd .Close () }()
7362
7372
args = append (args , "5" )
7363
7373
extraFiles = append (extraFiles , pidFd )
@@ -7900,9 +7910,11 @@ func (d *lxc) networkState(hostInterfaces []net.Interface) map[string]api.Instan
7900
7910
}
7901
7911
7902
7912
if ! couldUseNetnsGetifaddrs {
7903
- pidFdNr , pidFd := d .inheritInitPidFd ()
7904
- if pidFdNr >= 0 {
7913
+ pidFd := d .inheritInitPidFd ()
7914
+ pidFdNr := "-1"
7915
+ if pidFd != nil {
7905
7916
defer func () { _ = pidFd .Close () }()
7917
+ pidFdNr = "3"
7906
7918
}
7907
7919
7908
7920
// Get the network state from the container
@@ -7915,7 +7927,7 @@ func (d *lxc) networkState(hostInterfaces []net.Interface) map[string]api.Instan
7915
7927
"info" ,
7916
7928
"--" ,
7917
7929
fmt .Sprintf ("%d" , pid ),
7918
- fmt . Sprintf ( "%d" , pidFdNr ) )
7930
+ pidFdNr )
7919
7931
// Process forkgetnet response
7920
7932
if err != nil {
7921
7933
d .logger .Error ("Error calling 'forknet" , logger.Ctx {"err" : err , "pid" : pid })
@@ -8267,9 +8279,11 @@ func (d *lxc) removeMount(mount string) error {
8267
8279
}
8268
8280
} else {
8269
8281
// Remove the mount from the container
8270
- pidFdNr , pidFd := d .inheritInitPidFd ()
8271
- if pidFdNr >= 0 {
8282
+ pidFd := d .inheritInitPidFd ()
8283
+ pidFdNr := "-1"
8284
+ if pidFd != nil {
8272
8285
defer func () { _ = pidFd .Close () }()
8286
+ pidFdNr = "3"
8273
8287
}
8274
8288
8275
8289
_ , err := subprocess .RunCommandInheritFds (
@@ -8280,7 +8294,7 @@ func (d *lxc) removeMount(mount string) error {
8280
8294
"go-umount" ,
8281
8295
"--" ,
8282
8296
fmt .Sprintf ("%d" , pid ),
8283
- fmt . Sprintf ( "%d" , pidFdNr ) ,
8297
+ pidFdNr ,
8284
8298
mount )
8285
8299
if err != nil {
8286
8300
return err
0 commit comments