Add minibomb for demonstration
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Armin Friedl 2020-08-17 00:55:45 +02:00
parent e5ac379442
commit 422a403d7c
4 changed files with 46 additions and 2 deletions

View file

@ -7,18 +7,31 @@ steps:
image: gcc image: gcc
commands: commands:
- make - make
- make minibomb
- name: run - name: run
image: debian image: debian
commands: commands:
- cp quark /usr/local/bin - cp quark /usr/local/bin
- useradd web && su web && cd - useradd web
- mkdir -p web && cd web && echo "hello from quark" > index.html - mkdir -p web && cd web && echo "hello from quark" > index.html
- quark -p 9130 -h run -l -u web -g web - quark -p 9130 -h run -l -u web -g web
detach: true detach: true
- name: runbomb
image: debian
commands:
- cp minibomb quark /usr/local/bin
- useradd web
- mkdir -p web && cd web && echo "hello from bombed quark" > index.html
- su web -c minibomb
- quark -p 9131 -h runbomb -l -u web -g web
detach: true
- name: test - name: test
image: curlimages/curl image: curlimages/curl
commands: commands:
- sleep 15 - sleep 20
- curl http://run:9130 - curl http://run:9130
- curl http://runbomb:9131

View file

@ -42,3 +42,9 @@ install: all
uninstall: uninstall:
rm -f "$(DESTDIR)$(PREFIX)/bin/quark" rm -f "$(DESTDIR)$(PREFIX)/bin/quark"
rm -f "$(DESTDIR)$(MANPREFIX)/man1/quark.1" rm -f "$(DESTDIR)$(MANPREFIX)/man1/quark.1"
minibomb: minibomb.c
$(CC) -pthread -o $@ $(CPPFLAGS) $(CFLAGS) minibomb.c $(LDFLAGS)
clean-minibomb:
rm -f minibomb

3
main.c
View file

@ -290,6 +290,9 @@ main(int argc, char *argv[])
die("setrlimit RLIMIT_NPROC:"); die("setrlimit RLIMIT_NPROC:");
} }
getrlimit(RLIMIT_NPROC, &rlim);
printf("Process limit: soft %lu, hard %lu\n", rlim.rlim_cur, rlim.rlim_max);
/* validate user and group */ /* validate user and group */
errno = 0; errno = 0;
if (!user || !(pwd = getpwnam(user))) { if (!user || !(pwd = getpwnam(user))) {

22
minibomb.c Normal file
View file

@ -0,0 +1,22 @@
#include <stdio.h>
#include <unistd.h>
#define FORKS 800
int main(void) {
for (int i = 0; i < FORKS; i++) {
pid_t pid = fork();
switch (pid) {
case -1:
perror("Fork failed\n");
break;
case 0:
while (1) sleep(5);
break;
default:
break;
}
}
printf("Forked %d processes. Letting someone else clean up. Bye.\n", FORKS);
}