Skip to content

Commit 0724741

Browse files
authored
Merge pull request #300 from desultory/dev
Add musl_libc toggle, regenerate ld.so.cache within the initrd
2 parents b10eef2 + 761b2ed commit 0724741

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
lines changed

docs/configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Modules write to a shared config dict that is accessible by other modules.
4343
* `build_logging` (false) Enables additional logging during the build process.
4444
* `make_nodes` (false) Create real device nodes in the build dir.
4545
* `find_libgcc` (true) Automatically locates libgcc using ldconfig -p and adds it to the initramfs.
46+
* `musl_libc` (false) Disable ldconfig -p usage for libgcc detection, skip ld.so.cache regeneration.
4647
* `out_dir` (initramfs_out) If relative, it will be placed under `tmpdir`, defines the output directory.
4748
* `out_file` Sets the name of the output file, under `out_dir`.
4849
* `clean` (true) forces the build dir to be cleaned on each run.

src/ugrd/base/base.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ modules = [ "ugrd.base.core",
88

99
binaries = [ "awk", "bc", "dd", "grep", "ls", "cp", "cat", "stty", "switch_root", "rm" ]
1010

11-
paths = [ "root", "tmp" ]
11+
paths = [ "etc", "root", "tmp" ]
1212

1313
loglevel = 5
1414
shebang_args = "-l"

src/ugrd/base/core.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = "desultory"
2-
__version__ = "4.5.1"
2+
__version__ = "4.6.0"
33

44
from os import environ, makedev, mknod, uname
55
from pathlib import Path
@@ -303,6 +303,7 @@ def deploy_nodes(self) -> None:
303303
raise e
304304

305305

306+
@unset("musl_libc", "Skipping libgcc_s dependency resolution, musl_libc is enabled.", log_level=20)
306307
@contains("find_libgcc", "Skipping libgcc_s dependency resolution", log_level=20)
307308
def autodetect_libgcc(self) -> None:
308309
"""Finds libgcc.so, adds a 'dependencies' item for it.
@@ -318,7 +319,9 @@ def autodetect_libgcc(self) -> None:
318319
musl_warning = True
319320

320321
if musl_warning:
321-
self.logger.warning("This check can be disabled by setting `find_libgcc = false` in the configuration.")
322+
self.logger.warning(
323+
"This check can be disabled by setting `musl_libc = true` or `find_libgcc = false` in the configuration."
324+
)
322325
return self.logger.warning("Unable to run ldconfig -p, if glibc is being used, this is fatal!")
323326

324327
if cmd.returncode != 0:
@@ -343,6 +346,18 @@ def autodetect_musl(self) -> None:
343346
if musl_path.exists():
344347
self.logger.info("Detected musl search path: %s" % c_(musl_path, "cyan"))
345348
self["dependencies"] = musl_path
349+
elif self["musl_libc"]:
350+
raise AutodetectError("Musl libc is enabled, but the musl search path was not found: %s" % musl_path)
351+
352+
353+
@unset("musl_libc", "Skipping ld.so.cache regeneration, musl_libc is enabled.", log_level=30)
354+
def regen_ld_so_cache(self) -> None:
355+
"""Regenerates the ld.so.cache file in the build dir. Uses defined library paths to generate the config"""
356+
self.logger.info("Regenerating ld.so.cache")
357+
self._write("etc/ld.so.conf", self["library_paths"])
358+
build_path = self._get_build_path("/")
359+
self._run(["ldconfig", "-r", str(build_path)])
360+
self["check_included_or_mounted"] = "etc/ld.so.cache"
346361

347362

348363
def _process_out_file(self, out_file: str) -> None:

src/ugrd/base/core.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ timeout = 15
5050
"deploy_symlinks",
5151
"deploy_nodes"]
5252

53+
[imports.build_final]
54+
"ugrd.base.core" = [ "regen_ld_so_cache" ]
55+
5356
[custom_parameters]
5457
hostonly = "bool" # If true, the initramfs will be built specifically for the host building it
5558
validate = "bool" # If true, the configuration of the initramfs will be validated against the host
@@ -70,6 +73,7 @@ zstd_dependencies = "NoDupFlatList" # ZStandard compressed dependencies propert
7073
gz_dependencies = "NoDupFlatList" # GZipped dependencies property, used to define the gzipped dependencies (will be extracted)
7174
library_paths = "NoDupFlatList" # library_paths property, used to define the library paths to add to LD_LIBRARY_PATH
7275
find_libgcc = "bool" # If true, the initramfs will search for libgcc_s.so.1 and add it to the initramfs
76+
musl_libc = "bool" # If true, disables find_libgcc and regen_ld_so_cache
7377
libraries = "NoDupFlatList" # Additional libraries, by name, added to the initramfs
7478
binaries = "NoDupFlatList" # Binaries which should be included in the intiramfs, dependencies resolved with lddtree
7579
binary_search_paths = "NoDupFlatList" # Binary paths, used to define the paths to search for binaries

src/ugrd/fs/test_image.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ cryptsetup = "dict" # Same as above
2020
_cryptsetup_root = "str" # Define the root device for cryptsetup
2121
test_image_size = "int" # Define the size of the test image in MiB
2222
test_flag = "str" # Define the success flag used to determine if the test was successful
23-
23+
check_included_or_mounted = "NoDupFlatList" # Only defined to suppress errors about unknown config

0 commit comments

Comments
 (0)