From 4c9b80aee2b2ee3162b82e309718a23792d0e103 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Thu, 22 Oct 2020 20:17:24 +0200 Subject: [PATCH] cmd/initContainer: Don't rely on user D-Bus to track /etc/localtime This is one more step towards enabling toolbox(1) to be run as root. When invoked as 'sudo toolbox ...' there's no user or session D-Bus instance available for the root user, which prevents the use of D-Bus services like org.freedesktop.Flatpak.SessionHelper. https://github.com/containers/toolbox/issues/267 --- src/cmd/initContainer.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/cmd/initContainer.go b/src/cmd/initContainer.go index 12946a7..3c31d2a 100644 --- a/src/cmd/initContainer.go +++ b/src/cmd/initContainer.go @@ -168,6 +168,15 @@ func initContainer(cmd *cobra.Command, args []string) error { } } + if localtimeTarget, err := os.Readlink("/etc/localtime"); err != nil || + localtimeTarget != "/run/host/etc/localtime" { + if err := redirectPath("/etc/localtime", + "/run/host/etc/localtime", + false); err != nil { + return err + } + } + if _, err := os.Readlink("/etc/resolv.conf"); err != nil { if err := redirectPath("/etc/resolv.conf", "/run/host/etc/resolv.conf", @@ -192,14 +201,6 @@ func initContainer(cmd *cobra.Command, args []string) error { if utils.PathExists("/run/host/monitor") { logrus.Debug("Path /run/host/monitor exists") - if localtimeTarget, err := os.Readlink("/etc/localtime"); err != nil || - localtimeTarget != "/run/host/monitor/localtime" { - if err := redirectPath("/etc/localtime", - "/run/host/monitor/localtime", false); err != nil { - return err - } - } - if _, err := os.Readlink("/etc/timezone"); err != nil { if err := redirectPath("/etc/timezone", "/run/host/monitor/timezone",