chiark / gitweb /
core: don't wait for reply if writing to pipe fails
[elogind.git] / src / core / execute.c
index 874cdc7efee2730e12c09063920cc54b10c3ec3c..02df51b5bb29f6b0b0b05f83c22c6a5c6813a8f0 100644 (file)
@@ -19,8 +19,6 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <assert.h>
-#include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <sys/prctl.h>
-#include <linux/sched.h>
-#include <sys/types.h>
 #include <sys/stat.h>
 #include <grp.h>
-#include <pwd.h>
-#include <sys/mount.h>
-#include <linux/fs.h>
-#include <linux/oom.h>
-#include <sys/poll.h>
+#include <poll.h>
 #include <glob.h>
 #include <sys/personality.h>
-#include <libgen.h>
-#undef basename
 
 #ifdef HAVE_PAM
 #include <security/pam_appl.h>
 #include "errno-list.h"
 #include "af-list.h"
 #include "mkdir.h"
-#include "apparmor-util.h"
 #include "smack-util.h"
 #include "bus-endpoint.h"
-#include "label.h"
 #include "cap-list.h"
 
+#ifdef HAVE_APPARMOR
+#include "apparmor-util.h"
+#endif
+
 #ifdef HAVE_SECCOMP
 #include "seccomp-util.h"
 #endif
@@ -1167,10 +1159,10 @@ static void do_idle_pipe_dance(int idle_pipe[4]) {
 
                 if (idle_pipe[3] >= 0 && r == 0 /* timeout */) {
                         /* Signal systemd that we are bored and want to continue. */
-                        write(idle_pipe[3], "x", 1);
-
-                        /* Wait for systemd to react to the signal above. */
-                        fd_wait_for_event(idle_pipe[0], POLLHUP, IDLE_TIMEOUT2_USEC);
+                        r = write(idle_pipe[3], "x", 1);
+                        if (r > 0)
+                                /* Wait for systemd to react to the signal above. */
+                                fd_wait_for_event(idle_pipe[0], POLLHUP, IDLE_TIMEOUT2_USEC);
                 }
 
                 safe_close(idle_pipe[0]);
@@ -1526,7 +1518,7 @@ static int exec_child(
                                 return -ENOMEM;
                         }
 
-                        r = mkdir_safe(p, context->runtime_directory_mode, uid, gid);
+                        r = mkdir_safe_label(p, context->runtime_directory_mode, uid, gid);
                         if (r < 0) {
                                 *exit_status = EXIT_RUNTIME_DIRECTORY;
                                 return r;
@@ -1619,7 +1611,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 +1620,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;
                 }