Ruoyu Zhong 66737b5e82
os/linux/elf: fix file descriptor leak
On Linux, we occasionally see `EMFILE` ("too many open files") errors
especially when installing a large formula like `llvm`. Currently, this
can be reliably reproduced in a Homebrew/brew GitHub codespace (where
`ulimit -n` seems to be 1024 by default) with `brew install geeqie`,
with the following error message:

    Error: Too many open files @ rb_sysopen - /home/linuxbrew/.linuxbrew/Cellar/llvm/20.1.8/bin/tblgen-lsp-server

The reason is that each instance of `PatchELF::Patcher` keeps the ELF
file open. We prepend the `ELFShim` module to the `Pathname` class and
cache the patcher as an instance variable, which means that the ELF file
remains open so long as the `Pathname` instance is still alive even if
we don't need to access the ELF metadata anymore. When performing
certain checks (e.g., linkage), we also store these `Pathname`
instances, so the number of open file descriptors simply keeps
increasing.

We can fix that by not caching the patcher and only use it when
necessary. We create a patcher instance whenever we need to read or
write ELF metadata, and reading of metadata is consolidated into the
existing `ELFShim::Metadata` class so that we don't repeatedly create
patcher instances.

A fix for a file descriptor leak issue in patchelf.rb has been submitted
at https://github.com/david942j/patchelf.rb/pull/48. Together with that,
this fixes #19177, #19866, #20223, #20302.
2025-08-11 18:01:32 +08:00
..
2025-07-15 13:34:49 -04:00
2025-08-04 15:51:02 +01:00
2025-07-30 12:43:32 -07:00
2025-08-08 16:01:13 +08:00
2025-06-17 16:33:58 +01:00
2025-08-05 17:13:42 -04:00
2025-07-16 11:32:22 -04:00
2025-08-05 17:13:42 -04:00
2025-08-05 11:12:01 +01:00
2025-08-11 18:01:32 +08:00
2025-08-05 17:13:42 -04:00
2025-07-25 16:10:50 +00:00
2025-08-05 17:13:42 -04:00
2025-07-14 19:12:38 +01:00
2025-07-16 08:58:14 -07:00
2025-08-04 15:51:02 +01:00
2025-07-21 09:10:06 +01:00
2025-08-05 17:13:42 -04:00
2025-07-14 19:12:38 +01:00
2025-06-09 19:06:16 +01:00
2025-07-14 19:12:38 +01:00
2025-02-17 18:56:31 -08:00
2025-04-23 10:09:45 +02:00
2025-04-15 23:02:00 +01:00
2025-08-06 11:45:53 -07:00
2025-08-04 15:51:02 +01:00
2025-08-05 17:13:42 -04:00
2025-08-05 17:13:42 -04:00
2025-04-22 11:50:08 -07:00
2025-07-25 17:06:11 +01:00
2025-02-17 18:56:31 -08:00
2025-08-05 17:13:42 -04:00
2025-07-31 17:31:27 +01:00
2025-07-14 19:12:38 +01:00
2025-08-05 17:13:42 -04:00
2025-08-05 17:13:42 -04:00
2025-06-23 16:50:39 +01:00
2025-08-05 17:13:42 -04:00
2025-04-16 16:22:36 +01:00
2025-07-27 10:07:34 -07:00
2025-06-09 19:06:16 +01:00
2025-06-29 09:02:24 -07:00
2025-02-04 16:27:39 +00:00
2025-07-27 10:07:34 -07:00
2025-03-02 21:36:03 -08:00
2025-08-04 15:51:02 +01:00
2025-06-09 19:06:16 +01:00
2025-08-04 15:51:02 +01:00
2025-03-31 17:55:07 +01:00
2025-08-05 17:13:42 -04:00
2025-08-05 17:13:42 -04:00
2025-07-31 17:31:27 +01:00
2025-07-14 19:12:38 +01:00

Homebrew Ruby API

This is the API for Homebrew.

The main class you should look at is the {Formula} class (and classes linked from there). That's the class that's used to create Homebrew formulae (i.e. package descriptions). Assume anything else you stumble upon is private.

You may also find the Formula Cookbook and Ruby Style Guide helpful in creating formulae.

Good luck!