mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-01 02:25:40 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
45c0db941f |
No files matched your search
@@ -133,6 +133,7 @@ object NativeGuest {
|
||||
* Rescanned when dpkg's state or a library directory changes.
|
||||
*/
|
||||
fun syncLibraryDirs(root: File) {
|
||||
includeRunpathConf(root)
|
||||
val conf = File(root, RUNPATH_CONF)
|
||||
val signature = (listOf("var/lib/dpkg/status", "usr/lib", "usr/local/lib", "usr/lib/aarch64-linux-gnu")
|
||||
.joinToString(",") { File(root, it).lastModified().toString() }) + "," + conf.parentFile.list()?.size
|
||||
@@ -150,6 +151,23 @@ object NativeGuest {
|
||||
stamp.writeText(signature)
|
||||
}
|
||||
|
||||
private fun includeRunpathConf(root: File) {
|
||||
val ldConf = File(root, "etc/ld.so.conf")
|
||||
val text = if (ldConf.isFile) ldConf.readText() else ""
|
||||
if (ldConfIncludes(text, "/$RUNPATH_CONF")) return
|
||||
ldConf.parentFile?.mkdirs()
|
||||
ldConf.writeText(text + (if (text.isEmpty() || text.endsWith("\n")) "" else "\n") + "include /$RUNPATH_CONF\n")
|
||||
}
|
||||
|
||||
internal fun ldConfIncludes(text: String, file: String): Boolean {
|
||||
val target = java.nio.file.Paths.get(file)
|
||||
return text.lineSequence().map { it.substringBefore('#').trim() }
|
||||
.filter { it.length > 8 && it.startsWith("include") && it[7].isWhitespace() }
|
||||
.flatMap { it.substring(8).trim().split(Regex("\\s+")).asSequence() }
|
||||
.map { if (it.startsWith("/")) it else "/etc/$it" }
|
||||
.any { pattern -> runCatching { java.nio.file.FileSystems.getDefault().getPathMatcher("glob:$pattern").matches(target) }.getOrDefault(false) }
|
||||
}
|
||||
|
||||
/** What a rootfs needs before anything runs in it natively; cheap once done. */
|
||||
@Synchronized
|
||||
fun prepare(context: Context, root: File) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.droiddeck.launcher.runtime
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
@@ -135,4 +136,38 @@ class NativeGuestTest {
|
||||
assertEquals("/mnt/droiddeck-sd/steamapps/compatdata/2",
|
||||
NativeGuest.guestLinkTarget("/data/user/0/app/files/steam-libraries/x/steamapps/compatdata/2", linkRoot, binds))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aRuntimeWhoseLdSoConfListsOnlyItsDirectoriesIncludesTheRunpathDirectories() {
|
||||
val root = rootWithLoader()
|
||||
File(root, "etc").mkdirs()
|
||||
File(root, "etc/ld.so.conf").writeText("/usr/local/lib\n/usr/lib\n/usr/lib32")
|
||||
NativeGuest.syncLibraryDirs(root)
|
||||
assertEquals("/usr/local/lib\n/usr/lib\n/usr/lib32\ninclude /etc/ld.so.conf.d/zz-droiddeck-native.conf\n",
|
||||
File(root, "etc/ld.so.conf").readText())
|
||||
NativeGuest.syncLibraryDirs(root)
|
||||
assertEquals(1, File(root, "etc/ld.so.conf").readLines().count { it.startsWith("include") })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aRuntimeThatAlreadyIncludesLdSoConfDKeepsItsLdSoConf() {
|
||||
val root = rootWithLoader()
|
||||
File(root, "etc").mkdirs()
|
||||
val ubuntu = "include /etc/ld.so.conf.d/*.conf\n\n"
|
||||
File(root, "etc/ld.so.conf").writeText(ubuntu)
|
||||
NativeGuest.syncLibraryDirs(root)
|
||||
assertEquals(ubuntu, File(root, "etc/ld.so.conf").readText())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anIncludeReachesTheRunpathConfThroughAbsoluteAndRelativePatterns() {
|
||||
val conf = "/etc/ld.so.conf.d/zz-droiddeck-native.conf"
|
||||
assertTrue(NativeGuest.ldConfIncludes("include /etc/ld.so.conf.d/*.conf", conf))
|
||||
assertTrue(NativeGuest.ldConfIncludes("include ld.so.conf.d/*.conf", conf))
|
||||
assertTrue(NativeGuest.ldConfIncludes("/usr/lib\ninclude\t/etc/other.conf /etc/ld.so.conf.d/zz-*.conf", conf))
|
||||
assertFalse(NativeGuest.ldConfIncludes("/usr/local/lib\n/usr/lib\n", conf))
|
||||
assertFalse(NativeGuest.ldConfIncludes("# include /etc/ld.so.conf.d/*.conf", conf))
|
||||
assertFalse(NativeGuest.ldConfIncludes("include /etc/ld.so.conf.d/*.cfg", conf))
|
||||
assertFalse(NativeGuest.ldConfIncludes("include /usr/lib/ld.so.conf.d/*.conf", conf))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user