chiark / gitweb /
exec: also evaluate working_directory_missing_ok when not applying chroots
[elogind.git] / src / core / execute.c
index 19d3ec0da91e84ec474c0fd79a0752b5709f23a7..340b8000d4f224667a96863f5f9bfc2891955e0b 100644 (file)
@@ -40,8 +40,6 @@
 #include <sys/poll.h>
 #include <glob.h>
 #include <sys/personality.h>
-#include <libgen.h>
-#undef basename
 
 #ifdef HAVE_PAM
 #include <security/pam_appl.h>
@@ -1582,9 +1580,9 @@ static int exec_child(
 
                 if (context->private_tmp && runtime) {
                         if (runtime->tmp_dir)
-                                tmp = strappenda(runtime->tmp_dir, "/tmp");
+                                tmp = strjoina(runtime->tmp_dir, "/tmp");
                         if (runtime->var_tmp_dir)
-                                var = strappenda(runtime->var_tmp_dir, "/tmp");
+                                var = strjoina(runtime->var_tmp_dir, "/tmp");
                 }
 
                 r = setup_namespace(
@@ -1619,7 +1617,8 @@ static int exec_child(
                                 return -errno;
                         }
 
-                if (chdir(context->working_directory ? context->working_directory : "/") < 0) {
+                if (chdir(context->working_directory ?: "/") < 0 &&
+                    !context->working_directory_missing_ok) {
                         *exit_status = EXIT_CHDIR;
                         return -errno;
                 }
@@ -1627,13 +1626,14 @@ static int exec_child(
                 _cleanup_free_ char *d = NULL;
 
                 if (asprintf(&d, "%s/%s",
-                             context->root_directory ? context->root_directory : "",
-                             context->working_directory ? context->working_directory : "") < 0) {
+                             context->root_directory ?: "",
+                             context->working_directory ?: "") < 0) {
                         *exit_status = EXIT_MEMORY;
                         return -ENOMEM;
                 }
 
-                if (chdir(d) < 0) {
+                if (chdir(d) < 0 &&
+                    !context->working_directory_missing_ok) {
                         *exit_status = EXIT_CHDIR;
                         return -errno;
                 }
@@ -2588,7 +2588,7 @@ void exec_command_dump(ExecCommand *c, FILE *f, const char *prefix) {
         assert(f);
 
         prefix = strempty(prefix);
-        prefix2 = strappenda(prefix, "\t");
+        prefix2 = strjoina(prefix, "\t");
 
         cmd = exec_command_line(c->argv);
         fprintf(f,