aboutsummaryrefslogtreecommitdiffstats
path: root/init/init.c
diff options
context:
space:
mode:
authorturret <turret@duck.com>2023-12-18 15:49:45 -0600
committerturret <turret@duck.com>2023-12-18 15:49:45 -0600
commit24ce2da758627620754d854b81f80f67ae328f51 (patch)
tree664c1a4fafdfa1a663f0e3a327bbce961204d1df /init/init.c
parent3d920fd2be05203c12452c2f3ccec2d6112a568c (diff)
downloaddiscord-bot-skeleton-24ce2da758627620754d854b81f80f67ae328f51.tar.gz
discord-bot-skeleton-24ce2da758627620754d854b81f80f67ae328f51.tar.bz2
discord-bot-skeleton-24ce2da758627620754d854b81f80f67ae328f51.zip
subsys: use rlimits to determine stack size
Diffstat (limited to 'init/init.c')
-rw-r--r--init/init.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/init/init.c b/init/init.c
index 59908d1..29c2128 100644
--- a/init/init.c
+++ b/init/init.c
@@ -1,6 +1,7 @@
#include <signal.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/resource.h>
#include <sys/wait.h>
#include <config.h>
@@ -10,6 +11,7 @@
extern int subsystem_handle_term(int pid);
int mainpid = 0;
+long stack_size = 8192 * 512;
char *token;
/* For some reason, I get SIGSEGV'd when running because a random-ass
@@ -61,6 +63,14 @@ int main(void)
/* set mainpid for the subsystem service so it is fully accessible during l1 */
mainpid = getpid();
+ /* set stack_size for subsystem service */
+ struct rlimit *stack_rlimit = malloc(sizeof(struct rlimit));
+ getrlimit(RLIMIT_STACK, stack_rlimit);
+ if(stack_rlimit->rlim_cur != RLIM_INFINITY) {
+ stack_size = stack_rlimit->rlim_cur;
+ }
+ free(stack_rlimit);
+
/* fetch token */
char *token_base = getenv("TOKEN");
if(!token_base)