diff options
author | NRK <nrk@disroot.org> | 2022-06-22 05:28:07 +0200 |
---|---|---|
committer | NRK <nrk@disroot.org> | 2023-01-09 06:07:24 +0100 |
commit | 49d11f0d1fae43ae1e5f61204ed051e889062767 (patch) | |
tree | 39950a5f0de40b7048a171025c2ff3f8db43bee2 /options.c | |
parent | 76c2b81b6077702d3bbd9726b698cd8b6547fc5e (diff) | |
download | nsxiv-49d11f0d1fae43ae1e5f61204ed051e889062767.tar.zst |
spawn(): improve performance and simplify API
posix_spawn() is designed especially for this purpose, and thus it's
much more lightweight and efficient than manually fork/dup/exec-ing.
on my system, it improves the performance of spawn() by about 10x. given
that we make frequent calls to potentially multiple scripts, the
increased efficiency will add up overtime.
using posix_spawn() also simplifies the logic quite a bit, despite the
very verbose function names. however it does make cleanup a bit more
complicated.
this patch uses the linux kernel style cleanup strategy [0] (which I'm
personally not a huge fan of, but it fits this situation quite nicely)
with a "stack-like" unwinding via `goto`-s.
additionally simplify the spawn() API by taking in {read,write}fd
pointers and returning the pid instead of using some custom struct.
this coincidently also fixes #299
[0]: https://www.kernel.org/doc/html/v4.10/process/coding-style.html?highlight=goto#centralized-exiting-of-functions
Diffstat (limited to 'options.c')
0 files changed, 0 insertions, 0 deletions