fix systemd unit symlink equality logic

This commit is contained in:
Max Erenberg 2023-11-12 21:23:56 -05:00
parent db59c99f44
commit 8e21099f1b
4 changed files with 65 additions and 19 deletions

View File

@ -14,10 +14,10 @@ all:
LIBRARY_PATH=$(LIBRARY_PATH) CGO_LDFLAGS="$(CGO_LDFLAGS)" go build
run:
LD_LIBRARY_PATH=$(LIBRARY_PATH) LIBGUESTFS_PATH=$(LIBGUESTFS_PATH) LIBGUESTFS_HV=$(LIBGUESTFS_HV) LIBGUESTFS_BACKEND_SETTINGS=force_tcg ./cloudbuild
LD_LIBRARY_PATH=$(LIBRARY_PATH) LIBGUESTFS_PATH=$(LIBGUESTFS_PATH) LIBGUESTFS_HV=$(LIBGUESTFS_HV) ./cloudbuild
guestfish:
LD_LIBRARY_PATH=$(LIBRARY_PATH) LIBGUESTFS_PATH=$(LIBGUESTFS_PATH) LIBGUESTFS_HV=$(LIBGUESTFS_HV) LIBGUESTFS_BACKEND_SETTINGS=force_tcg scripts/guestfish.sh
LD_LIBRARY_PATH=$(LIBRARY_PATH) LIBGUESTFS_PATH=$(LIBGUESTFS_PATH) LIBGUESTFS_HV=$(LIBGUESTFS_HV) scripts/guestfish.sh
deps:
scripts/download-deps.sh

View File

@ -132,6 +132,16 @@ func (mgr *TemplateManager) ModifyTemplate(filename string) (err error) {
return
}
defer mgr.unmountAndCloseGuestfsHandle(handle)
hasSELinuxEnabled, err := hasSELinuxEnabled(handle)
if err != nil {
return
}
if hasSELinuxEnabled {
availErr := handle.Available([]string{"selinuxrelabel"})
if availErr != nil {
return fmt.Errorf("This appliance does not support selinuxrelabel: %w", availErr)
}
}
if err = mgr.createAugeasHandle(handle); err != nil {
return
}
@ -142,10 +152,6 @@ func (mgr *TemplateManager) ModifyTemplate(filename string) (err error) {
if err = mgr.impl.PerformDistroSpecificModifications(handle); err != nil {
return
}
hasSELinuxEnabled, err := hasSELinuxEnabled(handle)
if err != nil {
return
}
if hasSELinuxEnabled {
if err = mgr.selinuxRelabelDirectories(handle); err != nil {
return
@ -247,6 +253,21 @@ func (mgr *TemplateManager) maskSystemdUnit(handle *guestfs.Guestfs, unit string
return handle.Ln_sf("/dev/null", "/etc/systemd/system/"+unit)
}
func isSameFile(handle *guestfs.Guestfs, path1, path2 string) (bool, error) {
if path1 == path2 {
return true, nil
}
stat1, err := handle.Stat(path1)
if err != nil {
return false, fmt.Errorf("Could not stat %s: %w", path1, err)
}
stat2, err := handle.Stat(path2)
if err != nil {
return false, fmt.Errorf("Could not stat %s: %w", path2, err)
}
return stat1.Ino == stat2.Ino, nil
}
func systemdServiceIsEnabled(handle *guestfs.Guestfs, unit string) (bool, error) {
dirPrefixes := []string{"/etc", "/lib"}
unitPath := ""
@ -298,7 +319,9 @@ func systemdServiceIsEnabled(handle *guestfs.Guestfs, unit string) (bool, error)
if err != nil {
return false, fmt.Errorf("could not read link at %s: %w", linkName, err)
}
return target == unitPath, nil
// The target might be in /usr/lib, which will likely be a symlink
// to /lib. So we can't compare the paths directly.
return isSameFile(handle, target, unitPath)
}
// setChronyOptions sets custom NTP server URLs in a chrony config file.
@ -456,6 +479,15 @@ func usesEtcNetworkInterfaces(handle *guestfs.Guestfs) (bool, error) {
return systemdServiceIsEnabled(handle, "networking.service")
}
func usesSysconfigNetwork(handle *guestfs.Guestfs) (bool, error) {
configPath := "/etc/sysconfig/network/config"
configExists, err := handle.Is_file(configPath, nil)
if err != nil {
err = fmt.Errorf("Could not determine if "+configPath+" is a file: %w", err)
}
return configExists, err
}
func (mgr *TemplateManager) addSystemdNetworkdCloudInitSnippet(handle *guestfs.Guestfs) error {
// Use 98 so that each distro can use 99 for extra customization
path := "/etc/cloud/cloud.cfg.d/98_csclub_network.cfg"
@ -485,10 +517,15 @@ func (mgr *TemplateManager) setupCommonNetworkConfigs(handle *guestfs.Guestfs) e
if usesEtcNetworkInterfaces {
return mgr.setDhclientOptions(handle)
}
// The only other network backend used by one of our supported distros is
// Sysconfig, which is currently only used by OpenSUSE Tumbleweed.
// That case is handled separately in opensuse_tumbleweed.go.
return nil
usesSysconfigNetwork, err := usesSysconfigNetwork(handle)
if err != nil {
return err
}
if usesSysconfigNetwork {
// Handled separately in opensuse_tumbleweed.go
return nil
}
return fmt.Errorf("Could not determine network backend")
}
func (mgr *TemplateManager) setupIpv6Scripts(handle *guestfs.Guestfs) (err error) {

View File

@ -23,3 +23,4 @@ $SUPERMIN --build --verbose --if-newer \
mkdir -p guestfs
rm -rf guestfs/appliance
mv /var/tmp/.guestfs-`id -u`/appliance.d guestfs/appliance
touch guestfs/appliance/README.fixed

View File

@ -8,8 +8,6 @@ core_dependencies=(
libguestfs-dev
)
# This worked on Debian bullseye on the CSC machines - will need to
# be updated for other versions or other distros
# TODO: automatically generate this list from the dependencies for
# golang-guestfs-dev
libvirt_dependencies=(
@ -22,7 +20,6 @@ libvirt_dependencies=(
libpmem1
libslirp0
libspice-server1
liburing1
libusbredirparser1
libvdeplug2
libvirglrenderer1
@ -33,8 +30,6 @@ libvirt_dependencies=(
libxenevtchn1
libxenforeignmemory1
libxengnttab1
libxenmisc4.14
libxenstore3.0
libxentoolcore1
libxentoollog1
libyajl2
@ -43,6 +38,16 @@ libvirt_dependencies=(
seabios
)
. /etc/os-release
if [ "$VERSION_CODENAME" = bullseye ]; then
dependencies+=(liburing1 libxenmisc4.14 libxenstore3.0)
elif [ "$VERSION_CODENAME" = bookworm ]; then
dependencies+=(liburing2 libxenmisc4.17 libxenstore4)
else
echo "This script does not support $VERSION_CODENAME yet" >&2
exit 1
fi
dependencies=("${core_dependencies[@]}" "${libvirt_dependencies[@]}")
is_installed() {
@ -54,9 +59,12 @@ DEPS_DIR=guestfs/deps
mkdir -p $DEPS_DIR
cd guestfs
for dep in "${dependencies[@]}"; do
if is_installed $dep; then
continue
fi
# Even if a package is already installed, another package which we
# download might have a relative symlink to one of its files; download
# everything just to be safe
#if is_installed $dep; then
# continue
#fi
set -x
apt download $dep
dpkg -x ${dep}_*.deb deps