From 4652a2623f391d514edd49d10778bb55aacdffe0 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Wed, 20 Sep 2023 11:01:21 +0200 Subject: [PATCH] pass --syslog to the cleanup process The --syslog flag has not been passed to the cleanup process (i.e., conmon's exit args) complicating debugging quite a bit. Signed-off-by: Valentin Rothberg --- cmd/podman/root.go | 3 +-- cmd/podman/syslog_common.go | 3 ++- cmd/podman/syslog_unsupported.go | 7 +++++-- libpod/oci_conmon_common.go | 2 +- pkg/domain/entities/engine.go | 2 +- pkg/domain/infra/runtime_libpod.go | 3 +-- test/system/030-run.bats | 14 ++++++++++++++ 7 files changed, 25 insertions(+), 9 deletions(-) diff --git a/cmd/podman/root.go b/cmd/podman/root.go index 1cba35a54d..4a5802e3c2 100644 --- a/cmd/podman/root.go +++ b/cmd/podman/root.go @@ -77,7 +77,6 @@ var ( dockerConfig = "" debug bool - useSyslog bool requireCleanup = true // Defaults for capturing/redirecting the command output since (the) cobra is @@ -576,7 +575,7 @@ func rootFlags(cmd *cobra.Command, podmanConfig *entities.PodmanConfig) { pFlags.StringArrayVar(&podmanConfig.RuntimeFlags, runtimeflagFlagName, []string{}, "add global flags for the container runtime") _ = 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)") } } diff --git a/cmd/podman/syslog_common.go b/cmd/podman/syslog_common.go index b9909f8ec0..e33eb8aaec 100644 --- a/cmd/podman/syslog_common.go +++ b/cmd/podman/syslog_common.go @@ -6,12 +6,13 @@ package main import ( "log/syslog" + "github.com/containers/podman/v4/cmd/podman/registry" "github.com/sirupsen/logrus" logrusSyslog "github.com/sirupsen/logrus/hooks/syslog" ) func syslogHook() { - if !useSyslog { + if !registry.PodmanConfig().Syslog { return } diff --git a/cmd/podman/syslog_unsupported.go b/cmd/podman/syslog_unsupported.go index 365e5b2b41..24c4f3134d 100644 --- a/cmd/podman/syslog_unsupported.go +++ b/cmd/podman/syslog_unsupported.go @@ -6,13 +6,16 @@ package main import ( "fmt" "os" + "runtime" + + "github.com/containers/podman/v4/cmd/podman/registry" ) func syslogHook() { - if !useSyslog { + if !registry.PodmanConfig().Syslog { 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) } diff --git a/libpod/oci_conmon_common.go b/libpod/oci_conmon_common.go index 65465c574f..046a96e65c 100644 --- a/libpod/oci_conmon_common.go +++ b/libpod/oci_conmon_common.go @@ -1107,7 +1107,7 @@ func (r *ConmonOCIRuntime) createOCIContainer(ctr *Container, restoreOptions *Co 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 { return 0, err } diff --git a/pkg/domain/entities/engine.go b/pkg/domain/entities/engine.go index 7c6c0dab81..70f0906d98 100644 --- a/pkg/domain/entities/engine.go +++ b/pkg/domain/entities/engine.go @@ -47,7 +47,7 @@ type PodmanConfig struct { Remote bool // Connection to Podman API Service will use RESTful API RuntimePath string // --runtime flag will set Engine.RuntimePath 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 URI string // URI to RESTful API Service diff --git a/pkg/domain/infra/runtime_libpod.go b/pkg/domain/infra/runtime_libpod.go index 9171c4ed6a..33af1018a8 100644 --- a/pkg/domain/infra/runtime_libpod.go +++ b/pkg/domain/infra/runtime_libpod.go @@ -275,8 +275,7 @@ func getRuntime(ctx context.Context, fs *flag.FlagSet, opts *engineOpts) (*libpo options = append(options, libpod.WithDatabaseBackend(cfg.ContainersConf.Engine.DBBackend)) } - // no need to handle the error, it will return false anyway - if syslog, _ := fs.GetBool("syslog"); syslog { + if cfg.Syslog { options = append(options, libpod.WithSyslog()) } diff --git a/test/system/030-run.bats b/test/system/030-run.bats index 1b04b734d5..0bb5b0531a 100644 --- a/test/system/030-run.bats +++ b/test/system/030-run.bats @@ -1259,4 +1259,18 @@ search | $IMAGE | 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