aboutsummaryrefslogtreecommitdiff
path: root/src/relocation.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2020-02-10 15:28:57 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2020-02-10 15:28:57 -0500
commit1ade521a4261b6e02d0a02622dacbdb2d0ff731a (patch)
tree9f41a7bfd0b426cc1a0e8b57e0fdc491c0866a0d /src/relocation.c
parent0c13cc71617550940638a143b626c426769c803f (diff)
downloadspmc-1ade521a4261b6e02d0a02622dacbdb2d0ff731a.tar.gz
Add relocate_auto()
* Move relocation code out of install()
Diffstat (limited to 'src/relocation.c')
-rw-r--r--src/relocation.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/relocation.c b/src/relocation.c
index 4dc784f..ce6a896 100644
--- a/src/relocation.c
+++ b/src/relocation.c
@@ -324,3 +324,52 @@ int relocate(const char *_filename, const char *_oldstr, const char *_newstr) {
return returncode;
}
+/**
+ * Parse package metadata and set `baseroot` binaries/text to point to `destroot`.
+ * `baseroot` should be a temporary directory because its contents are modified
+ *
+ * @param destroot
+ * @param baseroot
+ */
+void relocate_root(const char *destroot, const char *baseroot) {
+ RelocationEntry **b_record = NULL;
+ RelocationEntry **t_record = NULL;
+ char cwd[PATH_MAX];
+
+ getcwd(cwd, sizeof(cwd));
+ chdir(baseroot);
+ {
+ // Rewrite binary prefixes
+ b_record = prefixes_read(SPM_META_PREFIX_BIN);
+ if (b_record) {
+ for (int i = 0; b_record[i] != NULL; i++) {
+ if (file_is_binexec(b_record[i]->path)) {
+ if (SPM_GLOBAL.verbose) {
+ printf("Relocate RPATH: %s\n", b_record[i]->path);
+ }
+ rpath_autoset(b_record[i]->path);
+ }
+ if (SPM_GLOBAL.verbose) {
+ printf("Relocate DATA : %s\n", b_record[i]->path);
+ }
+ relocate(b_record[i]->path, b_record[i]->prefix, destroot);
+ }
+ }
+
+ // Rewrite text prefixes
+ t_record = prefixes_read(SPM_META_PREFIX_TEXT);
+ if (t_record) {
+ for (int i = 0; t_record[i] != NULL; i++) {
+ if (SPM_GLOBAL.verbose) {
+ printf("Relocate TEXT : %s (%s -> %s)\n", t_record[i]->path, t_record[i]->prefix, destroot);
+ }
+ file_replace_text(t_record[i]->path, t_record[i]->prefix, destroot);
+ }
+ }
+
+ prefixes_free(b_record);
+ prefixes_free(t_record);
+ }
+ chdir(cwd);
+}
+