From: Lennart Poettering Date: Wed, 5 Mar 2014 01:29:58 +0000 (+0100) Subject: missing: if RLIMIT_RTTIME is not defined by the libc, then we need a new define for... X-Git-Tag: v211~126 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=517d56b1d0f67dcf76710bc1e17b05518b8cabe6 missing: if RLIMIT_RTTIME is not defined by the libc, then we need a new define for the max number of rlimits, too --- diff --git a/src/core/execute.c b/src/core/execute.c index fec4b3b13..ca807dc8c 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -1676,7 +1676,7 @@ int exec_spawn(ExecCommand *command, if (apply_permissions) { - for (i = 0; i < RLIMIT_NLIMITS; i++) { + for (i = 0; i < _RLIMIT_MAX; i++) { if (!context->rlimit[i]) continue; diff --git a/src/core/execute.h b/src/core/execute.h index 2c5d8bbf7..a33365732 100644 --- a/src/core/execute.h +++ b/src/core/execute.h @@ -38,6 +38,7 @@ typedef struct ExecRuntime ExecRuntime; #include "util.h" #include "set.h" #include "fdset.h" +#include "missing.h" typedef enum ExecInput { EXEC_INPUT_NULL, @@ -93,7 +94,7 @@ struct ExecContext { char **environment; char **environment_files; - struct rlimit *rlimit[RLIMIT_NLIMITS]; + struct rlimit *rlimit[_RLIMIT_MAX]; char *working_directory, *root_directory; mode_t umask; diff --git a/src/core/main.c b/src/core/main.c index 4ca847c78..25ddafee4 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -105,7 +105,7 @@ static unsigned arg_default_start_limit_burst = DEFAULT_START_LIMIT_BURST; static usec_t arg_runtime_watchdog = 0; static usec_t arg_shutdown_watchdog = 10 * USEC_PER_MINUTE; static char **arg_default_environment = NULL; -static struct rlimit *arg_default_rlimit[RLIMIT_NLIMITS] = {}; +static struct rlimit *arg_default_rlimit[_RLIMIT_MAX] = {}; static uint64_t arg_capability_bounding_set_drop = 0; static nsec_t arg_timer_slack_nsec = (nsec_t) -1; static Set* arg_syscall_archs = NULL; diff --git a/src/core/manager.c b/src/core/manager.c index 822c7ccfe..e4d03681a 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -810,7 +810,7 @@ void manager_free(Manager *m) { free(m->switch_root); free(m->switch_root_init); - for (i = 0; i < RLIMIT_NLIMITS; i++) + for (i = 0; i < _RLIMIT_MAX; i++) free(m->rlimit[i]); assert(hashmap_isempty(m->units_requiring_mounts_for)); @@ -2728,7 +2728,7 @@ int manager_set_default_rlimits(Manager *m, struct rlimit **default_rlimit) { assert(m); - for (i = 0; i < RLIMIT_NLIMITS; i++) { + for (i = 0; i < _RLIMIT_MAX; i++) { if (!default_rlimit[i]) continue; diff --git a/src/core/manager.h b/src/core/manager.h index 92985caef..e014abd04 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -228,7 +228,7 @@ struct Manager { bool default_memory_accounting; bool default_blockio_accounting; - struct rlimit *rlimit[RLIMIT_NLIMITS]; + struct rlimit *rlimit[_RLIMIT_MAX]; /* non-zero if we are reloading or reexecuting, */ int n_reloading; diff --git a/src/core/unit.c b/src/core/unit.c index d0e915909..2437ee3f6 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -2803,7 +2803,7 @@ int unit_exec_context_patch_defaults(Unit *u, ExecContext *c) { * _after_ the rest of the settings have been initialized */ /* This only copies in the ones that need memory */ - for (i = 0; i < RLIMIT_NLIMITS; i++) + for (i = 0; i < _RLIMIT_MAX; i++) if (u->manager->rlimit[i] && !c->rlimit[i]) { c->rlimit[i] = newdup(struct rlimit, u->manager->rlimit[i], 1); if (!c->rlimit[i]) diff --git a/src/shared/missing.h b/src/shared/missing.h index 06c69dac8..4e63fb9ac 100644 --- a/src/shared/missing.h +++ b/src/shared/missing.h @@ -47,6 +47,9 @@ #define RLIMIT_RTTIME 15 #endif +/* If RLIMIT_RTTIME is not defined, then we cannot use RLIMIT_NLIMITS as is */ +#define _RLIMIT_MAX (RLIMIT_RTTIME+1 > RLIMIT_NLIMITS ? RLIMIT_RTTIME+1 : RLIMIT_NLIMITS) + #ifndef F_LINUX_SPECIFIC_BASE #define F_LINUX_SPECIFIC_BASE 1024 #endif diff --git a/src/shared/util.c b/src/shared/util.c index 10daff303..8c7cfbd6d 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -83,6 +83,7 @@ #include "gunicode.h" #include "virt.h" #include "def.h" +#include "missing.h" int saved_argc = 0; char **saved_argv = NULL; @@ -4713,7 +4714,7 @@ static const char* const sched_policy_table[] = { DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(sched_policy, int, INT_MAX); -static const char* const rlimit_table[] = { +static const char* const rlimit_table[_RLIMIT_MAX] = { [RLIMIT_CPU] = "LimitCPU", [RLIMIT_FSIZE] = "LimitFSIZE", [RLIMIT_DATA] = "LimitDATA",