]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/udev/udev-event.c
util-lib: split our string related calls from util.[ch] into its own file string...
[thirdparty/systemd.git] / src / udev / udev-event.c
index f2b165076de61401de1b10ac06400eddb7264e82..49a45811a6375d09c4fc854a8da8d1bb650223b2 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <stddef.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
 #include <ctype.h>
-#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
 #include <net/if.h>
-#include <sys/prctl.h>
 #include <poll.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <sys/epoll.h>
-#include <sys/wait.h>
+#include <sys/prctl.h>
 #include <sys/signalfd.h>
+#include <sys/wait.h>
+#include <unistd.h>
 
-#include "netlink-util.h"
 #include "event-util.h"
 #include "formats-util.h"
+#include "netlink-util.h"
 #include "process-util.h"
 #include "signal-util.h"
+#include "string-util.h"
 #include "udev.h"
 
 typedef struct Spawn {
@@ -731,15 +732,13 @@ int udev_event_spawn(struct udev_event *event,
         /* pipes from child to parent */
         if (result != NULL || log_get_max_level() >= LOG_INFO) {
                 if (pipe2(outpipe, O_NONBLOCK) != 0) {
-                        err = -errno;
-                        log_error_errno(errno, "pipe failed: %m");
+                        err = log_error_errno(errno, "pipe failed: %m");
                         goto out;
                 }
         }
         if (log_get_max_level() >= LOG_INFO) {
                 if (pipe2(errpipe, O_NONBLOCK) != 0) {
-                        err = -errno;
-                        log_error_errno(errno, "pipe failed: %m");
+                        err = log_error_errno(errno, "pipe failed: %m");
                         goto out;
                 }
         }
@@ -753,12 +752,8 @@ int udev_event_spawn(struct udev_event *event,
                 char program[UTIL_PATH_SIZE];
 
                 /* child closes parent's ends of pipes */
-                if (outpipe[READ_END] >= 0) {
-                        outpipe[READ_END] = safe_close(outpipe[READ_END]);
-                }
-                if (errpipe[READ_END] >= 0) {
-                        errpipe[READ_END] = safe_close(errpipe[READ_END]);
-                }
+                outpipe[READ_END] = safe_close(outpipe[READ_END]);
+                errpipe[READ_END] = safe_close(errpipe[READ_END]);
 
                 strscpy(arg, sizeof(arg), cmd);
                 udev_build_argv(event->udev, arg, NULL, argv);
@@ -782,12 +777,8 @@ int udev_event_spawn(struct udev_event *event,
                 goto out;
         default:
                 /* parent closed child's ends of pipes */
-                if (outpipe[WRITE_END] >= 0) {
-                        outpipe[WRITE_END] = safe_close(outpipe[WRITE_END]);
-                }
-                if (errpipe[WRITE_END] >= 0) {
-                        errpipe[WRITE_END] = safe_close(errpipe[WRITE_END]);
-                }
+                outpipe[WRITE_END] = safe_close(outpipe[WRITE_END]);
+                errpipe[WRITE_END] = safe_close(errpipe[WRITE_END]);
 
                 spawn_read(event,
                            timeout_usec,