Skip to content

Commit

Permalink
Merge pull request #20062 from vrothberg/syslog-fix
Browse files Browse the repository at this point in the history
pass --syslog to the cleanup process
  • Loading branch information
openshift-merge-robot authored Sep 20, 2023
2 parents c5be3ae + 4652a26 commit 639eb52
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 9 deletions.
3 changes: 1 addition & 2 deletions cmd/podman/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ var (
dockerConfig = ""
debug bool

useSyslog bool
requireCleanup = true

// Defaults for capturing/redirecting the command output since (the) cobra is
Expand Down Expand Up @@ -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")
_ = 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)")
}
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/podman/syslog_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
7 changes: 5 additions & 2 deletions cmd/podman/syslog_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion libpod/oci_conmon_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/domain/entities/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions pkg/domain/infra/runtime_libpod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down
14 changes: 14 additions & 0 deletions test/system/030-run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1261,4 +1261,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

0 comments on commit 639eb52

Please sign in to comment.