Merge pull request #20062 from vrothberg/syslog-fix

pass --syslog to the cleanup process
This commit is contained in:
OpenShift Merge Robot
2023-09-20 11:57:33 -04:00
committed by GitHub
7 changed files with 25 additions and 9 deletions

View File

@ -76,7 +76,6 @@ var (
dockerConfig = "" dockerConfig = ""
debug bool debug bool
useSyslog bool
requireCleanup = true requireCleanup = true
// Defaults for capturing/redirecting the command output since (the) cobra is // Defaults for capturing/redirecting the command output since (the) cobra is
@ -611,7 +610,7 @@ func rootFlags(cmd *cobra.Command, podmanConfig *entities.PodmanConfig) {
pFlags.StringArrayVar(&podmanConfig.RuntimeFlags, runtimeflagFlagName, []string{}, "add global flags for the container runtime") pFlags.StringArrayVar(&podmanConfig.RuntimeFlags, runtimeflagFlagName, []string{}, "add global flags for the container runtime")
_ = rootCmd.RegisterFlagCompletionFunc(runtimeflagFlagName, completion.AutocompleteNone) _ = rootCmd.RegisterFlagCompletionFunc(runtimeflagFlagName, completion.AutocompleteNone)
pFlags.BoolVar(&useSyslog, "syslog", false, "Output logging information to syslog as well as the console (default false)") pFlags.BoolVar(&podmanConfig.Syslog, "syslog", false, "Output logging information to syslog as well as the console (default false)")
} }
} }

View File

@ -6,12 +6,13 @@ package main
import ( import (
"log/syslog" "log/syslog"
"github.com/containers/podman/v4/cmd/podman/registry"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
logrusSyslog "github.com/sirupsen/logrus/hooks/syslog" logrusSyslog "github.com/sirupsen/logrus/hooks/syslog"
) )
func syslogHook() { func syslogHook() {
if !useSyslog { if !registry.PodmanConfig().Syslog {
return return
} }

View File

@ -6,13 +6,16 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"runtime"
"github.com/containers/podman/v4/cmd/podman/registry"
) )
func syslogHook() { func syslogHook() {
if !useSyslog { if !registry.PodmanConfig().Syslog {
return return
} }
fmt.Fprintf(os.Stderr, "Logging to Syslog is not supported on Windows") fmt.Fprintf(os.Stderr, "Logging to Syslog is not supported on %s", runtime.GOOS)
os.Exit(1) os.Exit(1)
} }

View File

@ -1108,7 +1108,7 @@ func (r *ConmonOCIRuntime) createOCIContainer(ctr *Container, restoreOptions *Co
args = append(args, "--no-pivot") args = append(args, "--no-pivot")
} }
exitCommand, err := specgenutil.CreateExitCommandArgs(ctr.runtime.storageConfig, ctr.runtime.config, logrus.IsLevelEnabled(logrus.DebugLevel), ctr.AutoRemove(), false) exitCommand, err := specgenutil.CreateExitCommandArgs(ctr.runtime.storageConfig, ctr.runtime.config, ctr.runtime.syslog || logrus.IsLevelEnabled(logrus.DebugLevel), ctr.AutoRemove(), false)
if err != nil { if err != nil {
return 0, err return 0, err
} }

View File

@ -47,7 +47,7 @@ type PodmanConfig struct {
Remote bool // Connection to Podman API Service will use RESTful API Remote bool // Connection to Podman API Service will use RESTful API
RuntimePath string // --runtime flag will set Engine.RuntimePath RuntimePath string // --runtime flag will set Engine.RuntimePath
RuntimeFlags []string // global flags for the container runtime RuntimeFlags []string // global flags for the container runtime
Syslog bool // write to StdOut and Syslog, not supported when tunneling Syslog bool // write logging information to syslog as well as the console
Trace bool // Hidden: Trace execution Trace bool // Hidden: Trace execution
URI string // URI to RESTful API Service URI string // URI to RESTful API Service

View File

@ -275,8 +275,7 @@ func getRuntime(ctx context.Context, fs *flag.FlagSet, opts *engineOpts) (*libpo
options = append(options, libpod.WithDatabaseBackend(cfg.ContainersConf.Engine.DBBackend)) options = append(options, libpod.WithDatabaseBackend(cfg.ContainersConf.Engine.DBBackend))
} }
// no need to handle the error, it will return false anyway if cfg.Syslog {
if syslog, _ := fs.GetBool("syslog"); syslog {
options = append(options, libpod.WithSyslog()) options = append(options, libpod.WithSyslog())
} }

View File

@ -1261,4 +1261,18 @@ search | $IMAGE |
done < <(parse_table "$tests") done < <(parse_table "$tests")
} }
@test "podman --syslog passed to conmon" {
skip_if_remote "--syslog is not supported for remote clients"
skip_if_journald_unavailable
run_podman run -d -q --syslog $IMAGE sleep infinity
cid="$output"
run_podman container inspect $cid --format "{{ .State.ConmonPid }}"
conmon_pid="$output"
is "$(< /proc/$conmon_pid/cmdline)" ".*--exit-command-arg--syslog.*" "conmon's exit-command has --syslog set"
run_podman rm -f -t0 $cid
}
# vim: filetype=sh # vim: filetype=sh