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
This commit is contained in:
Debarshi Ray 2020-10-22 20:17:24 +02:00
parent 083aec96f2
commit 4c9b80aee2

View file

@ -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",