@@ -81,3 +81,74 @@ func TestExecIn(t *testing.T) {
8181 t .Fatalf ("unexpected running process, output %q" , out )
8282 }
8383}
84+
85+ func TestExecInRlimit (t * testing.T ) {
86+ if testing .Short () {
87+ return
88+ }
89+
90+ rootfs , err := newRootFs ()
91+ if err != nil {
92+ t .Fatal (err )
93+ }
94+ defer remove (rootfs )
95+
96+ config := newTemplateConfig (rootfs )
97+ if err := writeConfig (config ); err != nil {
98+ t .Fatalf ("failed to write config %s" , err )
99+ }
100+
101+ // start the container
102+ containerErr := make (chan error , 1 )
103+ containerCmd := & exec.Cmd {}
104+ var statePath string
105+ createCmd := func (container * libcontainer.Config , console , dataPath , init string ,
106+ pipe * os.File , args []string ) * exec.Cmd {
107+ containerCmd = namespaces .DefaultCreateCommand (container , console , dataPath , init , pipe , args )
108+ statePath = dataPath
109+ return containerCmd
110+ }
111+ var containerStart sync.WaitGroup
112+ containerStart .Add (1 )
113+ go func () {
114+ buffers := newStdBuffers ()
115+ _ , err := namespaces .Exec (config ,
116+ buffers .Stdin , buffers .Stdout , buffers .Stderr ,
117+ "" , config .RootFs , []string {"sleep" , "10" },
118+ createCmd , containerStart .Done )
119+ containerErr <- err
120+ }()
121+ containerStart .Wait ()
122+
123+ defer func () {
124+ // kill the container
125+ if containerCmd .Process != nil {
126+ containerCmd .Process .Kill ()
127+ }
128+ if err := <- containerErr ; err != nil {
129+ t .Fatal (err )
130+ }
131+ }()
132+
133+ // start the exec process
134+ state , err := libcontainer .GetState (statePath )
135+ if err != nil {
136+ t .Fatalf ("failed to get state %s" , err )
137+ }
138+ buffers := newStdBuffers ()
139+ execErr := make (chan error , 1 )
140+ go func () {
141+ _ , err := namespaces .ExecIn (config , state , []string {"/bin/sh" , "-c" , "ulimit -n" },
142+ os .Args [0 ], "exec" , buffers .Stdin , buffers .Stdout , buffers .Stderr ,
143+ "" , nil )
144+ execErr <- err
145+ }()
146+ if err := <- execErr ; err != nil {
147+ t .Fatalf ("exec finished with error %s" , err )
148+ }
149+
150+ out := buffers .Stdout .String ()
151+ if limit := strings .TrimSpace (out ); limit != "1024" {
152+ t .Fatalf ("expected rlimit to be 1024, got %s" , limit )
153+ }
154+ }
0 commit comments