1
0
mirror of https://github.com/lxc/incus.git synced 2026-02-05 18:45:46 +01:00
Files
incus/internal/server/util/sys.go
Stéphane Graber 6bab178249 incusd: Update for ArchitectureID
Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
2025-04-02 21:59:53 -04:00

66 lines
1.4 KiB
Go

//go:build linux && cgo && !agent
package util
import (
"os"
"strings"
"golang.org/x/sys/unix"
"github.com/lxc/incus/v6/shared/osarch"
)
// GetArchitectures returns the list of supported architectures.
func GetArchitectures() ([]int, error) {
architectures := []int{}
architectureName, err := osarch.ArchitectureGetLocal()
if err != nil {
return nil, err
}
architecture, err := osarch.ArchitectureID(architectureName)
if err != nil {
return nil, err
}
architectures = append(architectures, architecture)
personalities, err := osarch.ArchitecturePersonalities(architecture)
if err != nil {
return nil, err
}
architectures = append(architectures, personalities...)
return architectures, nil
}
// GetExecPath returns the path to the current binary.
func GetExecPath() string {
execPath := os.Getenv("INCUS_EXEC_PATH")
if execPath != "" {
return execPath
}
execPath, err := os.Readlink("/proc/self/exe")
if err != nil {
execPath = "bad-exec-path"
}
// The execPath from /proc/self/exe can end with " (deleted)" if the binary has been removed/changed
// since it was first started, strip this so that we only return a valid path.
return strings.TrimSuffix(execPath, " (deleted)")
}
// ReplaceDaemon replaces the daemon by re-execing the binary.
func ReplaceDaemon() error {
err := unix.Exec(GetExecPath(), os.Args, os.Environ())
if err != nil {
return err
}
return nil
}