aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--init/init.c10
-rw-r--r--init/subsys.c10
2 files changed, 15 insertions, 5 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)
diff --git a/init/subsys.c b/init/subsys.c
index 07a3e16..32b7cd3 100644
--- a/init/subsys.c
+++ b/init/subsys.c
@@ -13,7 +13,6 @@
#include <log.h>
#include <util.h>
-#define STACK_SIZE 8192 * 512
#define MAX_SUBSYSTEMS 32
struct subsystem_info {
@@ -24,6 +23,7 @@ struct subsystem_info {
char mode;
};
+extern long stack_size;
extern int mainpid;
static struct subsystem_info *subsystems[MAX_SUBSYSTEMS + 1];
static int subsystem_count = 0;
@@ -81,7 +81,7 @@ int subsystem_handle_term(int pid)
print(LOG_DEBUG "subsys: subsystem terminated %s (%d)", subsystem->fn_name, pid);
- if(munmap(subsystem->stack, STACK_SIZE) < 0)
+ if(munmap(subsystem->stack, stack_size) < 0)
print(LOG_EMERG "subsys: failed to deallocate stack for subsystem %s (%d) (errno %d)", subsystem->fn_name, pid, errno);
subsystems[i] = 0;
free(subsystem);
@@ -105,7 +105,7 @@ int __impl_start_subsystem(char *fn_name, int (*fn)(void))
/* because CLONE_VM is being set, our stack is not duplicated and
therefore we need to map a stack */
- void *stack = mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_GROWSDOWN | MAP_STACK | MAP_PRIVATE, -1, 0);
+ void *stack = mmap(NULL, stack_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_GROWSDOWN | MAP_STACK | MAP_PRIVATE, -1, 0);
if((long)stack <= 0) {
print(LOG_CRIT "subsys: cannot start subsystem %s: failed to allocate stack (errno %d)", fn_name, errno);
return 1;
@@ -120,11 +120,11 @@ int __impl_start_subsystem(char *fn_name, int (*fn)(void))
info->stack = stack;
info->mode = 'o';
- int pid = clone((int (*)(void *))__subsystem_entry, (void *)((long)stack + STACK_SIZE), CLONE_FILES | CLONE_VM | SIGCHLD, info);
+ int pid = clone((int (*)(void *))__subsystem_entry, (void *)((long)stack + stack_size), CLONE_FILES | CLONE_VM | SIGCHLD, info);
info->pid = pid;
if(pid < 0) {
print(LOG_CRIT "subsys: cannot start subsystem %s: clone failed (errno %d)", fn_name, errno);
- munmap(stack, STACK_SIZE);
+ munmap(stack, stack_size);
free(info);
return 1;
}