Skip to content

Commit

Permalink
Use external tool to adjust soft limits
Browse files Browse the repository at this point in the history
  • Loading branch information
hurufu committed May 19, 2024
1 parent d5e1d17 commit ff74d2d
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 13 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ coverage: test | $(CFILES) $(UT_C)
gcov -o . $|
clang-analyze: $(ALL_PLIST)
tcp-server: frob | d5.txt
s6-tcpserver -vd -b2 0.0.0.0 5002 s6-tcpserver-access -t200 -v3 -rp -B "Welcome!\r\n" $(realpath $<) 1000 $|
s6-tcpserver -vd -b2 0.0.0.0 5002 s6-tcpserver-access -t200 -v3 -rp -B "Welcome!\r\n" s6-softlimit -o 1024 $(realpath $<) 1000 $|
tcp-client: frob | d5.txt
s6-tcpclient -rv localhost 5002 $(realpath $<) 1000 $|
tls-server: frob server.cer server.key | d5.txt
Expand Down
12 changes: 0 additions & 12 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,9 @@
#include <sys/resource.h>
#include <pthread.h>

static void adjust_rlimit(void) {
// This will force syscalls that allocate file descriptors to fail if it
// doesn't fit into fd_set, so we don't have to check for that in the code.
struct rlimit rl;
if (getrlimit(RLIMIT_NOFILE, &rl) != 0)
ABORTF("getrlimit");
if (rl.rlim_cur > FD_SETSIZE)
if (setrlimit(RLIMIT_NOFILE, &(struct rlimit){ .rlim_cur = FD_SETSIZE, .rlim_max = rl.rlim_max }) != 0)
ABORTF("setrlimit");
}

int main(const int ac, const char* av[static const ac]) {
if (ac != 3)
return 1;
adjust_rlimit();
int fd_fo_main = STDOUT_FILENO, fd_fi_main = STDIN_FILENO;
ucsp_info_and_adjust_fds(&fd_fo_main, &fd_fi_main);
int frontend_pipe[2];
Expand Down

0 comments on commit ff74d2d

Please sign in to comment.