forked from containerd/containerd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request containerd#9210 from thaJeztah/1.6_backport_fix_de…
…adlock
- Loading branch information
Showing
15 changed files
with
353 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
//go:build linux | ||
|
||
/* | ||
Copyright The containerd Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"strconv" | ||
"strings" | ||
"syscall" | ||
"time" | ||
) | ||
|
||
// issue9103KillInitAfterCreate kills the runc.Init process after creating | ||
// command returns successfully. | ||
// | ||
// REF: https://github.com/containerd/containerd/issues/9103 | ||
func issue9103KillInitAfterCreate(ctx context.Context, method invoker) error { | ||
isCreated := strings.Contains(strings.Join(os.Args, ","), ",create,") | ||
|
||
if err := method(ctx); err != nil { | ||
return err | ||
} | ||
|
||
if !isCreated { | ||
return nil | ||
} | ||
|
||
initPidPath := "init.pid" | ||
data, err := os.ReadFile(initPidPath) | ||
if err != nil { | ||
return fmt.Errorf("failed to read %s: %w", initPidPath, err) | ||
} | ||
|
||
pid, err := strconv.Atoi(string(data)) | ||
if err != nil { | ||
return fmt.Errorf("failed to get init pid from string %s: %w", string(data), err) | ||
} | ||
|
||
if pid <= 0 { | ||
return fmt.Errorf("unexpected init pid %v", pid) | ||
} | ||
|
||
if err := syscall.Kill(pid, syscall.SIGKILL); err != nil { | ||
return fmt.Errorf("failed to kill the init pid %v: %w", pid, err) | ||
} | ||
|
||
// Ensure that the containerd-shim has received the SIGCHLD and start | ||
// to cleanup | ||
time.Sleep(3 * time.Second) | ||
return nil | ||
} |
Oops, something went wrong.