podman

Форк
0
/
runtime_linux.go 
67 строк · 2.4 Кб
1
//go:build !remote
2

3
package libpod
4

5
import (
6
	"errors"
7
	"fmt"
8
	"os"
9

10
	"golang.org/x/sys/unix"
11

12
	"github.com/containers/common/pkg/cgroups"
13
	"github.com/containers/podman/v5/pkg/rootless"
14
	"github.com/containers/podman/v5/pkg/systemd"
15
	"github.com/sirupsen/logrus"
16
)
17

18
func checkCgroups2UnifiedMode(runtime *Runtime) {
19
	unified, _ := cgroups.IsCgroup2UnifiedMode()
20
	// DELETE ON RHEL9
21
	if !unified {
22
		_, ok := os.LookupEnv("PODMAN_IGNORE_CGROUPSV1_WARNING")
23
		if !ok {
24
			logrus.Warn("Using cgroups-v1 which is deprecated in favor of cgroups-v2 with Podman v5 and will be removed in a future version. Set environment variable `PODMAN_IGNORE_CGROUPSV1_WARNING` to hide this warning.")
25
		}
26
	}
27
	// DELETE ON RHEL9
28

29
	if unified && rootless.IsRootless() && !systemd.IsSystemdSessionValid(rootless.GetRootlessUID()) {
30
		// If user is rootless and XDG_RUNTIME_DIR is found, podman will not proceed with /tmp directory
31
		// it will try to use existing XDG_RUNTIME_DIR
32
		// if current user has no write access to XDG_RUNTIME_DIR we will fail later
33
		if err := unix.Access(runtime.storageConfig.RunRoot, unix.W_OK); err != nil {
34
			msg := fmt.Sprintf("RunRoot is pointing to a path (%s) which is not writable. Most likely podman will fail.", runtime.storageConfig.RunRoot)
35
			if errors.Is(err, os.ErrNotExist) {
36
				// if dir does not exist, try to create it
37
				if err := os.MkdirAll(runtime.storageConfig.RunRoot, 0700); err != nil {
38
					logrus.Warn(msg)
39
				}
40
			} else {
41
				logrus.Warnf("%s: %v", msg, err)
42
			}
43
		}
44
	}
45
}
46

47
// Check the current boot ID against the ID cached in the runtime alive file.
48
func (r *Runtime) checkBootID(runtimeAliveFile string) error {
49
	systemBootID, err := os.ReadFile("/proc/sys/kernel/random/boot_id")
50
	if err == nil {
51
		podmanBootID, err := os.ReadFile(runtimeAliveFile)
52
		if err != nil {
53
			return fmt.Errorf("reading boot ID from runtime alive file: %w", err)
54
		}
55
		if len(podmanBootID) != 0 {
56
			if string(systemBootID) != string(podmanBootID) {
57
				return fmt.Errorf("current system boot ID differs from cached boot ID; an unhandled reboot has occurred. Please delete directories %q and %q and re-run Podman", r.storageConfig.RunRoot, r.config.Engine.TmpDir)
58
			}
59
		} else {
60
			// Write the current boot ID to the alive file.
61
			if err := os.WriteFile(runtimeAliveFile, systemBootID, 0644); err != nil {
62
				return fmt.Errorf("writing boot ID to runtime alive file: %w", err)
63
			}
64
		}
65
	}
66
	return nil
67
}
68

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.