Le mardi 03 avril 2012 à 15:44 +0200, Frederic Crozat a écrit : > Le lundi 02 avril 2012 à 22:59 +0200, Lennart Poettering a écrit : > > On Fri, 30.03.12 17:20, Frederic Crozat (fcro...@suse.com) wrote: > > > > > >From 5008080dda662208278c159213adbd5211496043 Mon Sep 17 00:00:00 2001 > > > From: Frederic Crozat <fcro...@suse.com> > > > Date: Thu, 29 Mar 2012 17:53:41 +0200 > > > Subject: [PATCH 1/2] macro: add newdup macro, equivalent of new + memdup > > > but > > > type-safe > > > > > > --- > > > src/macro.h | 1 + > > > 1 files changed, 1 insertions(+), 0 deletions(-) > > > > > > diff --git a/src/macro.h b/src/macro.h > > > index 19f259e..a85e72d 100644 > > > --- a/src/macro.h > > > +++ b/src/macro.h > > > @@ -137,6 +137,7 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) { > > > > > > #define memzero(x,l) (memset((x), 0, (l))) > > > #define zero(x) (memzero(&(x), sizeof(x))) > > > +#define newdup(x,l) ( (x= new(typeof(*l),1)) ? > > > memcpy((x),(l),sizeof(*l)) : NULL) > > > > Hmm, I was more thinking of a definition much closer to new() and > > new0(), without typeof, but with allowing allocation of an array > > > > #define newdup(t, p, n) ((t*)memdup(p,sizeof(t)*(n))) > > New version attached, based on your comments.
Rebased version, including a fix to newdup macro which went to git some weeks ago. -- Frederic Crozat <fcro...@suse.com> SUSE
>From 5944312f891658446edea08e6907dff05daebdec Mon Sep 17 00:00:00 2001 From: Frederic Crozat <fcro...@suse.com> Date: Mon, 21 May 2012 16:53:18 +0200 Subject: [PATCH 1/2] util: fix typo in newdup --- src/shared/util.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/shared/util.h b/src/shared/util.h index 3dce047..33a7e7c 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -103,7 +103,7 @@ bool streq_ptr(const char *a, const char *b); #define newa(t, n) ((t*) alloca(sizeof(t)*(n))) -#define newdup(t, p, n) ((t*) memdup(p, sizeof(t)*(n)) +#define newdup(t, p, n) ((t*) memdup(p, sizeof(t)*(n))) #define malloc0(n) (calloc((n), 1)) -- 1.7.7 >From f175a58a4a183a0d34cb13b77290425eb3f3c9b0 Mon Sep 17 00:00:00 2001 From: Frederic Crozat <fcro...@suse.com> Date: Wed, 21 Mar 2012 18:03:40 +0100 Subject: [PATCH 2/2] allow system wide limits for services --- src/core/main.c | 28 ++++++++++++++++++++++++++++ src/core/manager.c | 7 +++++++ src/core/manager.h | 2 ++ src/core/service.c | 8 ++++++++ 4 files changed, 45 insertions(+), 0 deletions(-) diff --git a/src/core/main.c b/src/core/main.c index 8c25819..5e37b47 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -85,6 +85,7 @@ static ExecOutput arg_default_std_output = EXEC_OUTPUT_JOURNAL; static ExecOutput arg_default_std_error = EXEC_OUTPUT_INHERIT; static usec_t arg_runtime_watchdog = 0; static usec_t arg_shutdown_watchdog = 10 * USEC_PER_MINUTE; +static struct rlimit *default_rlimit[RLIMIT_NLIMITS] = {}; static FILE* serialization = NULL; @@ -665,6 +666,22 @@ static int parse_config_file(void) { { "Manager", "JoinControllers", config_parse_join_controllers, 0, &arg_join_controllers }, { "Manager", "RuntimeWatchdogSec", config_parse_usec, 0, &arg_runtime_watchdog }, { "Manager", "ShutdownWatchdogSec", config_parse_usec, 0, &arg_shutdown_watchdog }, + { "Manager", "LimitCPU", config_parse_limit, 0, &default_rlimit[RLIMIT_CPU]}, + { "Manager", "LimitFSIZE", config_parse_limit, 0, &default_rlimit[RLIMIT_FSIZE]}, + { "Manager", "LimitDATA", config_parse_limit, 0, &default_rlimit[RLIMIT_DATA]}, + { "Manager", "LimitSTACK", config_parse_limit, 0, &default_rlimit[RLIMIT_STACK]}, + { "Manager", "LimitCORE", config_parse_limit, 0, &default_rlimit[RLIMIT_CORE]}, + { "Manager", "LimitRSS", config_parse_limit, 0, &default_rlimit[RLIMIT_RSS]}, + { "Manager", "LimitNOFILE", config_parse_limit, 0, &default_rlimit[RLIMIT_NOFILE]}, + { "Manager", "LimitAS", config_parse_limit, 0, &default_rlimit[RLIMIT_AS]}, + { "Manager", "LimitNPROC", config_parse_limit, 0, &default_rlimit[RLIMIT_NPROC]}, + { "Manager", "LimitMEMLOCK", config_parse_limit, 0, &default_rlimit[RLIMIT_MEMLOCK]}, + { "Manager", "LimitLOCKS", config_parse_limit, 0, &default_rlimit[RLIMIT_LOCKS]}, + { "Manager", "LimitSIGPENDING", config_parse_limit, 0, &default_rlimit[RLIMIT_SIGPENDING]}, + { "Manager", "LimitMSGQUEUE", config_parse_limit, 0, &default_rlimit[RLIMIT_MSGQUEUE]}, + { "Manager", "LimitNICE", config_parse_limit, 0, &default_rlimit[RLIMIT_NICE]}, + { "Manager", "LimitRTPRIO", config_parse_limit, 0, &default_rlimit[RLIMIT_RTPRIO]}, + { "Manager", "LimitRTTIME", config_parse_limit, 0, &default_rlimit[RLIMIT_RTTIME]}, { NULL, NULL, NULL, 0, NULL } }; @@ -1471,6 +1488,14 @@ int main(int argc, char *argv[]) { m->default_std_error = arg_default_std_error; m->runtime_watchdog = arg_runtime_watchdog; m->shutdown_watchdog = arg_shutdown_watchdog; + for (j = 0; j < RLIMIT_NLIMITS; j++) { + if (default_rlimit[j]) { + m->rlimit[j] = newdup(struct rlimit, default_rlimit[j], 1); + + if (!m->rlimit[j]) + goto finish; + } + } if (dual_timestamp_is_set(&initrd_timestamp)) m->initrd_timestamp = initrd_timestamp; @@ -1631,6 +1656,9 @@ finish: if (m) manager_free(m); + for (j = 0; j < RLIMIT_NLIMITS; j++) + free (default_rlimit[j]); + free(arg_default_unit); strv_free(arg_default_controllers); free_join_controllers(); diff --git a/src/core/manager.c b/src/core/manager.c index f8fb8a2..65b34f3 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -476,6 +476,7 @@ static void manager_clear_jobs_and_units(Manager *m) { void manager_free(Manager *m) { UnitType c; + int i; assert(m); @@ -524,6 +525,12 @@ void manager_free(Manager *m) { free(m->switch_root); free(m->switch_root_init); + for (i = 0; i < RLIMIT_NLIMITS; i++) { + if (m->rlimit[i]) { + free (m->rlimit[i]); + m->rlimit[i] = NULL; + } + } free(m); } diff --git a/src/core/manager.h b/src/core/manager.h index 046540d..6aefc8b 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -226,6 +226,8 @@ struct Manager { ExecOutput default_std_output, default_std_error; + struct rlimit *rlimit[RLIMIT_NLIMITS]; + /* non-zero if we are reloading or reexecuting, */ int n_reloading; diff --git a/src/core/service.c b/src/core/service.c index 28049a3..fa3a54b 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -110,6 +110,7 @@ static const UnitActiveState state_translation_table[_SERVICE_STATE_MAX] = { static void service_init(Unit *u) { Service *s = SERVICE(u); + int i; assert(u); assert(u->load_state == UNIT_STUB); @@ -129,6 +130,13 @@ static void service_init(Unit *u) { s->guess_main_pid = true; exec_context_init(&s->exec_context); + for (i = 0; i < RLIMIT_NLIMITS; i++) { + if (UNIT(s)->manager->rlimit[i]) { + s->exec_context.rlimit[i] = newdup(struct rlimit, UNIT(s)->manager->rlimit[i], 1); + if (!s->exec_context.rlimit[i]) + return; + } + } RATELIMIT_INIT(s->start_limit, 10*USEC_PER_SEC, 5); -- 1.7.7
_______________________________________________ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel