mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
892f2ded6f
The current support of systemd-notify has a race condition as the message send to the systemd notify socket might be dropped if the sender process is not running by the time systemd checks for the sender of the datagram. A proper fix of this in systemd would require changes to the kernel to maintain the cgroup of the sender process when it is dead (but it is not probably going to happen...) Generally, the solution to this issue is to specify the PID in the message itself so that systemd has not to guess the sender, but this wouldn't work when running in a PID namespace as the container will pass the PID known in its namespace (something like PID=1,2,3..) and systemd running on the host is not able to map it to the runc service. The proposed solution is to have a proxy in runc that forwards the messages to the host systemd. Example of this issue: https://github.com/projectatomic/atomic-system-containers/pull/24 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
81 lines
1.8 KiB
Go
81 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/Sirupsen/logrus"
|
|
"github.com/opencontainers/runtime-spec/specs-go"
|
|
"github.com/urfave/cli"
|
|
)
|
|
|
|
const (
|
|
exactArgs = iota
|
|
minArgs
|
|
)
|
|
|
|
func checkArgs(context *cli.Context, expected, checkType int) error {
|
|
var err error
|
|
cmdName := context.Command.Name
|
|
switch checkType {
|
|
case exactArgs:
|
|
if context.NArg() != expected {
|
|
err = fmt.Errorf("%s: %q requires exactly %d argument(s)", os.Args[0], cmdName, expected)
|
|
}
|
|
case minArgs:
|
|
if context.NArg() < expected {
|
|
err = fmt.Errorf("%s: %q requires a minimum of %d argument(s)", os.Args[0], cmdName, expected)
|
|
}
|
|
}
|
|
|
|
if err != nil {
|
|
fmt.Printf("Incorrect Usage.\n\n")
|
|
cli.ShowCommandHelp(context, cmdName)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// fatal prints the error's details if it is a libcontainer specific error type
|
|
// then exits the program with an exit status of 1.
|
|
func fatal(err error) {
|
|
// make sure the error is written to the logger
|
|
logrus.Error(err)
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
// setupSpec performs initial setup based on the cli.Context for the container
|
|
func setupSpec(context *cli.Context) (*specs.Spec, error) {
|
|
bundle := context.String("bundle")
|
|
if bundle != "" {
|
|
if err := os.Chdir(bundle); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
spec, err := loadSpec(specConfig)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if os.Geteuid() != 0 {
|
|
return nil, fmt.Errorf("runc should be run as root")
|
|
}
|
|
return spec, nil
|
|
}
|
|
|
|
func revisePidFile(context *cli.Context) error {
|
|
pidFile := context.String("pid-file")
|
|
if pidFile == "" {
|
|
return nil
|
|
}
|
|
|
|
// convert pid-file to an absolute path so we can write to the right
|
|
// file after chdir to bundle
|
|
pidFile, err := filepath.Abs(pidFile)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return context.Set("pid-file", pidFile)
|
|
}
|