mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
libct: clean cached rlimit nofile in go runtime
As reported in issue #4195, the new version(since 1.19) of go runtime
will cache rlimit-nofile. Before executing execve, the rlimit-nofile
of the process will be restored with the cache. In runc, this will
cause the rlimit-nofile set by the parent process for the container
to become invalid. It can be solved by clearing the cache.
Signed-off-by: ls-ggg <335814617@qq.com>
(cherry picked from commit f9f8abf310)
Signed-off-by: lifubang <lifubang@acmcoder.com>
This commit is contained in:
@@ -223,6 +223,12 @@ func containerInit(t initType, config *initConfig, pipe *syncSocket, consoleSock
|
||||
return err
|
||||
}
|
||||
|
||||
// Clean the RLIMIT_NOFILE cache in go runtime.
|
||||
// Issue: https://github.com/opencontainers/runc/issues/4195
|
||||
if containsRlimit(config.Rlimits, unix.RLIMIT_NOFILE) {
|
||||
system.ClearRlimitNofileCache()
|
||||
}
|
||||
|
||||
switch t {
|
||||
case initSetns:
|
||||
i := &linuxSetnsInit{
|
||||
@@ -649,6 +655,15 @@ func setupRoute(config *configs.Config) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func containsRlimit(limits []configs.Rlimit, resource int) bool {
|
||||
for _, rlimit := range limits {
|
||||
if rlimit.Type == resource {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func setupRlimits(limits []configs.Rlimit, pid int) error {
|
||||
for _, rlimit := range limits {
|
||||
if err := unix.Prlimit(pid, rlimit.Type, &unix.Rlimit{Max: rlimit.Hard, Cur: rlimit.Soft}, nil); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user