chiark / gitweb /
set nice/oom_adjust only when asked for
authorLennart Poettering <lennart@poettering.net>
Thu, 28 Jan 2010 01:53:56 +0000 (02:53 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 28 Jan 2010 01:53:56 +0000 (02:53 +0100)
execute.c
execute.h
load-fragment.c

index ccf951a..cbefadf 100644 (file)
--- a/execute.c
+++ b/execute.c
@@ -263,7 +263,6 @@ int exec_spawn(const ExecCommand *command, const ExecContext *context, int *fds,
         if (pid == 0) {
                 char **e, **f = NULL;
                 int i, r;
         if (pid == 0) {
                 char **e, **f = NULL;
                 int i, r;
-                char t[16];
                 sigset_t ss;
 
                 /* child */
                 sigset_t ss;
 
                 /* child */
@@ -286,19 +285,24 @@ int exec_spawn(const ExecCommand *command, const ExecContext *context, int *fds,
                         goto fail;
                 }
 
                         goto fail;
                 }
 
-                snprintf(t, sizeof(t), "%i", context->oom_adjust);
-                char_array_0(t);
+                if (context->oom_adjust_set) {
+                        char t[16];
 
 
-                if (write_one_line_file("/proc/self/oom_adj", t) < 0) {
-                        r = EXIT_OOM_ADJUST;
-                        goto fail;
-                }
+                        snprintf(t, sizeof(t), "%i", context->oom_adjust);
+                        char_array_0(t);
 
 
-                if (setpriority(PRIO_PROCESS, 0, context->nice) < 0) {
-                        r = EXIT_NICE;
-                        goto fail;
+                        if (write_one_line_file("/proc/self/oom_adj", t) < 0) {
+                                r = EXIT_OOM_ADJUST;
+                                goto fail;
+                        }
                 }
 
                 }
 
+                if (context->nice_set)
+                        if (setpriority(PRIO_PROCESS, 0, context->nice) < 0) {
+                                r = EXIT_NICE;
+                                goto fail;
+                        }
+
                 if (close_fds(fds, n_fds) < 0 ||
                     shift_fds(fds, n_fds) < 0 ||
                     flags_fds(fds, n_fds) < 0) {
                 if (close_fds(fds, n_fds) < 0 ||
                     shift_fds(fds, n_fds) < 0 ||
                     flags_fds(fds, n_fds) < 0) {
@@ -428,13 +432,19 @@ void exec_context_dump(ExecContext *c, FILE* f, const char *prefix) {
 
         fprintf(f,
                 "%sUmask: %04o\n"
 
         fprintf(f,
                 "%sUmask: %04o\n"
-                "%sDirectory: %s\n"
-                "%sNice: %i\n"
-                "%sOOMAdjust: %i\n",
+                "%sDirectory: %s\n",
                 prefix, c->umask,
                 prefix, c->umask,
-                prefix, c->directory ? c->directory : "/",
-                prefix, c->nice,
-                prefix, c->oom_adjust);
+                prefix, c->directory ? c->directory : "/");
+
+        if (c->nice_set)
+                fprintf(f,
+                        "%sNice: %i\n",
+                        prefix, c->nice);
+
+        if (c->oom_adjust_set)
+                fprintf(f,
+                        "%sOOMAdjust: %i\n",
+                        prefix, c->oom_adjust);
 }
 
 void exec_status_fill(ExecStatus *s, pid_t pid, int code, int status) {
 }
 
 void exec_status_fill(ExecStatus *s, pid_t pid, int code, int status) {
index 3283e1f..04b9f6e 100644 (file)
--- a/execute.h
+++ b/execute.h
@@ -44,9 +44,12 @@ struct ExecContext {
         char **environment;
         mode_t umask;
         struct rlimit *rlimit[RLIMIT_NLIMITS];  /* FIXME: load-fragment parser missing */
         char **environment;
         mode_t umask;
         struct rlimit *rlimit[RLIMIT_NLIMITS];  /* FIXME: load-fragment parser missing */
+        char *directory;
         int oom_adjust;
         int nice;
         int oom_adjust;
         int nice;
-        char *directory;
+
+        bool oom_adjust_set:1;
+        bool nice_set:1;
 
         ExecOutput output;
         int syslog_priority;
 
         ExecOutput output;
         int syslog_priority;
index 9273fc8..0db74b3 100644 (file)
@@ -208,7 +208,8 @@ static int config_parse_nice(
                 void *data,
                 void *userdata) {
 
                 void *data,
                 void *userdata) {
 
-        int *i = data, priority, r;
+        ExecContext *c = data;
+        int priority, r;
 
         assert(filename);
         assert(lvalue);
 
         assert(filename);
         assert(lvalue);
@@ -225,7 +226,9 @@ static int config_parse_nice(
                 return -ERANGE;
         }
 
                 return -ERANGE;
         }
 
-        *i = priority;
+        c->nice = priority;
+        c->nice_set = false;
+
         return 0;
 }
 
         return 0;
 }
 
@@ -238,7 +241,8 @@ static int config_parse_oom_adjust(
                 void *data,
                 void *userdata) {
 
                 void *data,
                 void *userdata) {
 
-        int *i = data, oa, r;
+        ExecContext *c = data;
+        int oa, r;
 
         assert(filename);
         assert(lvalue);
 
         assert(filename);
         assert(lvalue);
@@ -255,7 +259,9 @@ static int config_parse_oom_adjust(
                 return -ERANGE;
         }
 
                 return -ERANGE;
         }
 
-        *i = oa;
+        c->oom_adjust = oa;
+        c->oom_adjust_set = true;
+
         return 0;
 }
 
         return 0;
 }
 
@@ -709,8 +715,8 @@ static int load_from_path(Unit *u, const char *path) {
                 { "User",                   config_parse_string,          &(context).user,                                 section   }, \
                 { "Group",                  config_parse_string,          &(context).group,                                section   }, \
                 { "SupplementaryGroups",    config_parse_strv,            &(context).supplementary_groups,                 section   }, \
                 { "User",                   config_parse_string,          &(context).user,                                 section   }, \
                 { "Group",                  config_parse_string,          &(context).group,                                section   }, \
                 { "SupplementaryGroups",    config_parse_strv,            &(context).supplementary_groups,                 section   }, \
-                { "Nice",                   config_parse_nice,            &(context).nice,                                 section   }, \
-                { "OOMAdjust",              config_parse_oom_adjust,      &(context).oom_adjust,                           section   }, \
+                { "Nice",                   config_parse_nice,            &(context),                                      section   }, \
+                { "OOMAdjust",              config_parse_oom_adjust,      &(context),                                      section   }, \
                 { "UMask",                  config_parse_umask,           &(context).umask,                                section   }, \
                 { "Environment",            config_parse_strv,            &(context).environment,                          section   }, \
                 { "Output",                 config_parse_output,          &(context).output,                               section   }, \
                 { "UMask",                  config_parse_umask,           &(context).umask,                                section   }, \
                 { "Environment",            config_parse_strv,            &(context).environment,                          section   }, \
                 { "Output",                 config_parse_output,          &(context).output,                               section   }, \