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. -- Frederic Crozat <fcro...@suse.com> SUSE
>From f17a7712ea2be4b540e3af8f474433ff1e989220 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..5e1106f 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(t, p, n) ((t*)memdup(p,sizeof(t)*(n))) #define char_array_0(x) x[sizeof(x)-1] = 0; -- 1.7.7 >From 81bdc076bba2f4dddb947bf56f4811fd2c031fef 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/main.c | 28 ++++++++++++++++++++++++++++ src/manager.c | 8 ++++++++ src/manager.h | 2 ++ src/service.c | 8 ++++++++ 4 files changed, 46 insertions(+), 0 deletions(-) diff --git a/src/main.c b/src/main.c index 7ae8841..ffb14bc 100644 --- a/src/main.c +++ b/src/main.c @@ -80,6 +80,7 @@ static char **arg_default_controllers = NULL; static char ***arg_join_controllers = NULL; static ExecOutput arg_default_std_output = EXEC_OUTPUT_JOURNAL; static ExecOutput arg_default_std_error = EXEC_OUTPUT_INHERIT; +static struct rlimit *default_rlimit[RLIMIT_NLIMITS] = {}; static FILE* serialization = NULL; @@ -660,6 +661,22 @@ static int parse_config_file(void) { { "Manager", "DefaultStandardOutput", config_parse_output, 0, &arg_default_std_output }, { "Manager", "DefaultStandardError", config_parse_output, 0, &arg_default_std_error }, { "Manager", "JoinControllers", config_parse_join_controllers, 0, &arg_join_controllers }, + { "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 } }; @@ -1404,6 +1421,14 @@ int main(int argc, char *argv[]) { m->swap_auto = arg_swap_auto; m->default_std_output = arg_default_std_output; m->default_std_error = arg_default_std_error; + 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; @@ -1543,6 +1568,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/manager.c b/src/manager.c index 74bd740..da78901 100644 --- a/src/manager.c +++ b/src/manager.c @@ -456,6 +456,7 @@ static void manager_clear_jobs_and_units(Manager *m) { void manager_free(Manager *m) { UnitType c; + int i; assert(m); @@ -501,6 +502,13 @@ void manager_free(Manager *m) { hashmap_free(m->cgroup_bondings); set_free_free(m->unit_path_cache); + 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/manager.h b/src/manager.h index a9d08f0..5dc7e29 100644 --- a/src/manager.h +++ b/src/manager.h @@ -225,6 +225,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/service.c b/src/service.c index 8b5c0b0..e020f23 100644 --- a/src/service.c +++ b/src/service.c @@ -109,6 +109,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); @@ -127,6 +128,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