summaryrefslogtreecommitdiffstats
path: root/nsxiv.h
diff options
context:
space:
mode:
authorNRK <nrk@disroot.org>2022-06-22 05:28:07 +0200
committerNRK <nrk@disroot.org>2023-01-09 06:07:24 +0100
commit49d11f0d1fae43ae1e5f61204ed051e889062767 (patch)
tree39950a5f0de40b7048a171025c2ff3f8db43bee2 /nsxiv.h
parent76c2b81b6077702d3bbd9726b698cd8b6547fc5e (diff)
downloadnsxiv-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 'nsxiv.h')
-rw-r--r--nsxiv.h13
1 files changed, 1 insertions, 12 deletions
diff --git a/nsxiv.h b/nsxiv.h
index 33a2bde..19e5399 100644
--- a/nsxiv.h
+++ b/nsxiv.h
@@ -326,17 +326,6 @@ typedef struct {
int stlen;
} r_dir_t;
-typedef struct {
- int readfd;
- int writefd;
- pid_t pid;
-} spawn_t;
-
-enum {
- X_READ = (1 << 0),
- X_WRITE = (1 << 1)
-};
-
extern const char *progname;
void* emalloc(size_t);
@@ -349,7 +338,7 @@ int r_closedir(r_dir_t*);
char* r_readdir(r_dir_t*, bool);
int r_mkdir(char*);
void construct_argv(char**, unsigned int, ...);
-spawn_t spawn(const char*, char *const [], unsigned int);
+pid_t spawn(int*, int*, char *const []);
/* window.c */