chiark / gitweb /
set nice/oom_adjust only when asked for
[elogind.git] / execute.c
index ccf951a25a437974f681ca0d12763237dfe9839c..cbefadfca06456ab7508a0bc17adfa3ac4ef36fe 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) {