@@ -11,6 +11,7 @@ import (
1111 "reflect"
1212 "strconv"
1313 "strings"
14+ "syscall"
1415 "testing"
1516
1617 "github.com/opencontainers/runc/libcontainer"
@@ -1660,6 +1661,59 @@ func TestPIDHost(t *testing.T) {
16601661 }
16611662}
16621663
1664+ func TestPIDHostInitProcessWait (t * testing.T ) {
1665+ if testing .Short () {
1666+ return
1667+ }
1668+
1669+ rootfs , err := newRootfs ()
1670+ ok (t , err )
1671+ defer remove (rootfs )
1672+
1673+ pidns := "/proc/1/ns/pid"
1674+
1675+ // Run a container with two long-running processes.
1676+ config := newTemplateConfig (rootfs )
1677+ config .Namespaces .Add (configs .NEWPID , pidns )
1678+ container , err := newContainerWithName ("test" , config )
1679+ ok (t , err )
1680+ defer func () {
1681+ _ = container .Destroy ()
1682+ }()
1683+
1684+ process1 := & libcontainer.Process {
1685+ Cwd : "/" ,
1686+ Args : []string {"sleep" , "100" },
1687+ Env : standardEnvironment ,
1688+ Init : true ,
1689+ }
1690+ err = container .Run (process1 )
1691+ ok (t , err )
1692+
1693+ process2 := & libcontainer.Process {
1694+ Cwd : "/" ,
1695+ Args : []string {"sleep" , "100" },
1696+ Env : standardEnvironment ,
1697+ Init : false ,
1698+ }
1699+ err = container .Run (process2 )
1700+ ok (t , err )
1701+
1702+ // Kill the init process and Wait for it.
1703+ err = process1 .Signal (syscall .SIGKILL )
1704+ ok (t , err )
1705+ _ , err = process1 .Wait ()
1706+ if err == nil {
1707+ t .Fatal ("expected Wait to indicate failure" )
1708+ }
1709+
1710+ // The non-init process must've been killed.
1711+ err = process2 .Signal (syscall .Signal (0 ))
1712+ if err == nil || err .Error () != "no such process" {
1713+ t .Fatalf ("expected process to have been killed: %v" , err )
1714+ }
1715+ }
1716+
16631717func TestInitJoinPID (t * testing.T ) {
16641718 if testing .Short () {
16651719 return
0 commit comments