From baf3cccdd52fe60d4816b11106141fff490db607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Tue, 1 Dec 2026 21:25:53 -0300 Subject: [PATCH] refactor(packaging): keep live-root detection in the server helper --- .gitignore | 2 -- builddebs.pl | 32 +------------------ perl-xCAT/debian/postrm | 3 +- perl-xCAT/debian/rules | 6 ---- perl-xCAT/debian/xcat-live-root-functions | 5 --- xCAT-server/debian/rules | 8 +---- xCAT-server/debian/xcat-live-root-functions | 1 - .../xcat/scripts/xcatd-init-compat-functions | 6 ++++ xCATsn/debian/postinst | 3 +- xCATsn/debian/rules | 6 ---- xCATsn/debian/xcat-live-root-functions | 1 - 11 files changed, 12 insertions(+), 61 deletions(-) delete mode 100644 perl-xCAT/debian/xcat-live-root-functions delete mode 120000 xCAT-server/debian/xcat-live-root-functions delete mode 120000 xCATsn/debian/xcat-live-root-functions diff --git a/.gitignore b/.gitignore index ca5bcb5297..d2331fbb60 100644 --- a/.gitignore +++ b/.gitignore @@ -12,8 +12,6 @@ Gitinfo # Build residue: buildrpms.pl and builddebs.pl write these into the source # tree, so a "git add -A" after a build sweeps them into a commit. dist/ -/.xCAT-server-live-root.build-link -/.xCATsn-live-root.build-link perl-xCAT/pods perl-xCAT/share/doc perl-xCAT/share/man diff --git a/builddebs.pl b/builddebs.pl index b42308de32..00bedf6c9c 100755 --- a/builddebs.pl +++ b/builddebs.pl @@ -171,17 +171,6 @@ my $DEB_DATE = strftime('%a, %d %b %Y %H:%M:%S +0000', gmtime($EPOCH)); sub with_prepared_tree { my ($pkg, $arch, $body) = @_; my $dir = "$ROOT/$pkg"; - my $live_root = "$dir/debian/xcat-live-root-functions"; - my $live_root_backup = "$ROOT/.$pkg-live-root.build-link"; - # Recover the source link before a later build can consume an interrupted copy. - if (-l $live_root_backup) { - rename($live_root_backup, $live_root) - or die "Cannot recover link $live_root: $!\n"; - } - if ($pkg ne 'perl-xCAT' && -f $live_root && !-l $live_root && - read_text($live_root) ne read_text("$ROOT/perl-xCAT/debian/xcat-live-root-functions")) { - die "Cannot build $pkg with a stale live-root helper; restore $live_root from source\n"; - } my @restore; my @remove; @@ -246,31 +235,12 @@ sub with_prepared_tree { write_text($control, pin_control_version(read_text($per_arch), $PKGVER)); } - my $rc = eval { - # Source packages cannot depend on another package's source directory. - if (-l $live_root) { - my $text = read_text($live_root); - die "Cannot overwrite $live_root_backup\n" - if -e $live_root_backup || -l $live_root_backup; - rename($live_root, $live_root_backup) - or die "Cannot save link $live_root: $!\n"; - write_text($live_root, $text); - } - $body->($dir); - 1; - } ? 0 : 1; + my $rc = eval { $body->($dir); 1 } ? 0 : 1; my $err = $@; - my $restore_error; - if (-l $live_root_backup) { - rename($live_root_backup, $live_root) - or $restore_error = "Cannot restore link $live_root: $!\n"; - } unlink @added, @remove; restore_file($_) for reverse @restore; - warn $restore_error if $restore_error && $rc; die $err if $rc; - die $restore_error if $restore_error; return; } diff --git a/perl-xCAT/debian/postrm b/perl-xCAT/debian/postrm index f8902ddfba..b5617e6d6a 100644 --- a/perl-xCAT/debian/postrm +++ b/perl-xCAT/debian/postrm @@ -21,7 +21,8 @@ set -e case "$1" in upgrade) - if [ -x /opt/xcat/sbin/restartxcatd ] && xcat_is_live_root; then + if [ -x /opt/xcat/sbin/restartxcatd ] && [ -f /proc/cmdline ] && + [ "$(stat -c '%d:%i' /)" = "$(stat -c '%d:%i' /proc/1/root/. 2>/dev/null)" ]; then . /etc/profile.d/xcat.sh XCATROOT=/opt/xcat /opt/xcat/sbin/restartxcatd -r fi diff --git a/perl-xCAT/debian/rules b/perl-xCAT/debian/rules index 46fb19ddbf..7a0450ef48 100755 --- a/perl-xCAT/debian/rules +++ b/perl-xCAT/debian/rules @@ -63,12 +63,6 @@ binary-arch: build install dh_perl dh_makeshlibs dh_installdeb - set -e; scriptfile=debian/perl-xcat/DEBIAN/postrm; \ - { head -n 1 "$$scriptfile"; \ - cat debian/xcat-live-root-functions; \ - tail -n +2 "$$scriptfile"; } > "$$scriptfile.tmp"; \ - chmod 755 "$$scriptfile.tmp"; \ - mv "$$scriptfile.tmp" "$$scriptfile" dh_shlibdeps dh_gencontrol dh_md5sums diff --git a/perl-xCAT/debian/xcat-live-root-functions b/perl-xCAT/debian/xcat-live-root-functions deleted file mode 100644 index 2081f9f49a..0000000000 --- a/perl-xCAT/debian/xcat-live-root-functions +++ /dev/null @@ -1,5 +0,0 @@ -xcat_is_live_root() -{ - [ -f /proc/cmdline ] && - [ "$(stat -c '%d:%i' /)" = "$(stat -c '%d:%i' /proc/1/root/. 2>/dev/null)" ] -} diff --git a/xCAT-server/debian/rules b/xCAT-server/debian/rules index bf24333f9a..3998a6f6b7 100755 --- a/xCAT-server/debian/rules +++ b/xCAT-server/debian/rules @@ -93,7 +93,7 @@ binary-arch: dh_makeshlibs dh_installdeb # These scripts can run before unpacking or after the helpers are removed. - set -e; for script in preinst postrm; do \ + set -e; for script in preinst prerm postrm; do \ scriptfile=$(buildroot)/DEBIAN/$$script; \ { head -n 1 "$$scriptfile"; \ cat share/xcat/scripts/xcatd-init-compat-functions; \ @@ -101,12 +101,6 @@ binary-arch: chmod 755 "$$scriptfile.tmp"; \ mv "$$scriptfile.tmp" "$$scriptfile"; \ done - set -e; scriptfile=$(buildroot)/DEBIAN/prerm; \ - { head -n 1 "$$scriptfile"; \ - cat debian/xcat-live-root-functions; \ - tail -n +2 "$$scriptfile"; } > "$$scriptfile.tmp"; \ - chmod 755 "$$scriptfile.tmp"; \ - mv "$$scriptfile.tmp" "$$scriptfile" dh_shlibdeps dh_gencontrol -- -Vperl:Depends=perl dh_md5sums diff --git a/xCAT-server/debian/xcat-live-root-functions b/xCAT-server/debian/xcat-live-root-functions deleted file mode 120000 index c56cc08f0f..0000000000 --- a/xCAT-server/debian/xcat-live-root-functions +++ /dev/null @@ -1 +0,0 @@ -../../perl-xCAT/debian/xcat-live-root-functions \ No newline at end of file diff --git a/xCAT-server/share/xcat/scripts/xcatd-init-compat-functions b/xCAT-server/share/xcat/scripts/xcatd-init-compat-functions index 05173dbbf8..d71e48b47c 100644 --- a/xCAT-server/share/xcat/scripts/xcatd-init-compat-functions +++ b/xCAT-server/share/xcat/scripts/xcatd-init-compat-functions @@ -88,6 +88,12 @@ xcat_target_uses_systemd() return 1 } +xcat_is_live_root() +{ + [ -f /proc/cmdline ] && + [ "$(stat -c '%d:%i' /)" = "$(stat -c '%d:%i' /proc/1/root/. 2>/dev/null)" ] +} + clear_xcatd_pending_state() { rm -f "$xcatd_state_dir/pending-xcatd" \ diff --git a/xCATsn/debian/postinst b/xCATsn/debian/postinst index df41ce6e7e..7621b07495 100644 --- a/xCATsn/debian/postinst +++ b/xCATsn/debian/postinst @@ -64,7 +64,8 @@ case "$1" in a2enmod -q headers >/dev/null 2>&1 || : fi - if xcat_is_live_root; then + if [ -f /proc/cmdline ] && + [ "$(stat -c '%d:%i' /)" = "$(stat -c '%d:%i' /proc/1/root/. 2>/dev/null)" ]; then if [ -d /run/systemd/system ] && command -v systemctl >/dev/null 2>&1; then systemctl start xcatd.service elif [ -x /etc/init.d/xcatd ]; then diff --git a/xCATsn/debian/rules b/xCATsn/debian/rules index 032cb47cb1..38689173dc 100755 --- a/xCATsn/debian/rules +++ b/xCATsn/debian/rules @@ -56,12 +56,6 @@ binary-arch: dh_perl dh_makeshlibs dh_installdeb - set -e; scriptfile=debian/xcatsn/DEBIAN/postinst; \ - { head -n 1 "$$scriptfile"; \ - cat debian/xcat-live-root-functions; \ - tail -n +2 "$$scriptfile"; } > "$$scriptfile.tmp"; \ - chmod 755 "$$scriptfile.tmp"; \ - mv "$$scriptfile.tmp" "$$scriptfile" dh_shlibdeps dh_gencontrol dh_md5sums diff --git a/xCATsn/debian/xcat-live-root-functions b/xCATsn/debian/xcat-live-root-functions deleted file mode 120000 index c56cc08f0f..0000000000 --- a/xCATsn/debian/xcat-live-root-functions +++ /dev/null @@ -1 +0,0 @@ -../../perl-xCAT/debian/xcat-live-root-functions \ No newline at end of file