Don't become a fork bomb. Limit the number of processes by stopping to poll for new jobs once the limit is reached. I set the limit to 16 which is larger then the biggest concurrency I have seen during fetches.
OK? -- :wq Claudio Index: extern.h =================================================================== RCS file: /cvs/src/usr.sbin/rpki-client/extern.h,v retrieving revision 1.89 diff -u -p -r1.89 extern.h --- extern.h 3 Nov 2021 10:50:18 -0000 1.89 +++ extern.h 3 Nov 2021 14:25:53 -0000 @@ -618,4 +618,7 @@ int mkpath(const char *); /* Maximum depth of the RPKI tree. */ #define MAX_CERT_DEPTH 12 +/* Maximum number of concurrent rsync processes. */ +#define MAX_RSYNC_PROCESSES 16 + #endif /* ! EXTERN_H */ Index: rsync.c =================================================================== RCS file: /cvs/src/usr.sbin/rpki-client/rsync.c,v retrieving revision 1.29 diff -u -p -r1.29 rsync.c --- rsync.c 28 Oct 2021 13:50:29 -0000 1.29 +++ rsync.c 3 Nov 2021 14:25:00 -0000 @@ -119,7 +119,7 @@ proc_child(int signal) void proc_rsync(char *prog, char *bind_addr, int fd) { - size_t i, idsz = 0; + size_t i, idsz = 0, nprocs = 0; int rc = 0; struct pollfd pfd; struct msgbuf msgq; @@ -186,7 +186,9 @@ proc_rsync(char *prog, char *bind_addr, pid_t pid; int st; - pfd.events = POLLIN; + pfd.events = 0; + if (nprocs < MAX_RSYNC_PROCESSES) + pfd.events |= POLLIN; if (msgq.queued) pfd.events |= POLLOUT; @@ -228,6 +230,7 @@ proc_rsync(char *prog, char *bind_addr, ids[i].uri = NULL; ids[i].pid = 0; ids[i].id = 0; + nprocs--; } if (pid == -1 && errno != ECHILD) err(1, "waitpid"); @@ -314,6 +317,7 @@ proc_rsync(char *prog, char *bind_addr, ids[i].id = id; ids[i].pid = pid; ids[i].uri = uri; + nprocs++; /* Clean up temporary values. */