summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2023-09-16 12:34:48 +0200
committerJulian Andres Klode <julian.klode@canonical.com>2023-09-16 12:37:31 +0200
commit99c888b5eabbb7008bf4451bc62c277f28bb925f (patch)
tree2375ab845a8c66a368bae090b799d819287ee589 /apt-pkg
parent52dd18670bf7d22ecf234141d3c7b7b9f67c6fa3 (diff)
Only accept installs of usrmerge on unmerged-usr systems
As of bookworm, merged-usr is mandatory, and people got caught in the crosshairs of the dpkg fsys-unmessusr debacle and inadvertently reverted back to an unmerged configuration and continue to remain on an unsupported system unknowingly. Help them by erroring out when they are installing packages on /, they are not in a chroot, and a usrmerge package is available.
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/aptconfiguration.cc29
-rw-r--r--apt-pkg/aptconfiguration.h6
2 files changed, 33 insertions, 2 deletions
diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc
index 00a97a0e7..cfe38ec83 100644
--- a/apt-pkg/aptconfiguration.cc
+++ b/apt-pkg/aptconfiguration.cc
@@ -28,8 +28,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/stat.h>
#include <unistd.h>
-
/*}}}*/
namespace APT {
// setDefaultConfigurationForCompressors /*{{{*/
@@ -538,4 +538,31 @@ bool Configuration::isChroot()
return once.res;
}
/*}}}*/
+// isUsrMerged - whether usr is merged t /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool Configuration::checkUsrMerged()
+{
+ std::string rootDir = _config->FindDir("Dir");
+ for (auto dir : {"bin", "sbin", "lib"})
+ {
+ struct stat root;
+ struct stat usr;
+ std::string dirInRoot = rootDir + dir;
+ std::string dirInUsr = rootDir + "usr/" + dir;
+
+ // Missing directories are a boot strap scenario that needs to work
+ if (stat(dirInRoot.c_str(), &root))
+ continue;
+ if (stat(dirInUsr.c_str(), &usr))
+ continue;
+ if (root.st_dev != usr.st_dev)
+ return _error->Error("%s is on different device than %s", dirInRoot.c_str(), dirInUsr.c_str());
+ if (root.st_ino != usr.st_ino)
+ return _error->Error("%s resolved to a different inode than %s", dirInRoot.c_str(), dirInUsr.c_str());
+ }
+
+ return true;
+}
+ /*}}}*/
}
diff --git a/apt-pkg/aptconfiguration.h b/apt-pkg/aptconfiguration.h
index bbeb156b9..3e2636edc 100644
--- a/apt-pkg/aptconfiguration.h
+++ b/apt-pkg/aptconfiguration.h
@@ -125,8 +125,12 @@ namespace Configuration { /*{{{*/
std::string const getMachineID();
+#ifdef APT_COMPILING_APT
/** \return Whether we are running in a chroot */
- bool isChroot();
+ APT_PUBLIC bool isChroot();
+ /** \return Check usr is merged or produce error. */
+ APT_PUBLIC bool checkUsrMerged();
+#endif
/*}}}*/
}
/*}}}*/