chiark / gitweb /
tree-wide: drop 'This file is part of systemd' blurb
[elogind.git] / src / libelogind / sd-bus / bus-socket.c
index 0e58bc9536130325c8ab6d74cd1859d4baa803dc..e32fdb03179d530c58ed6fb67537547f3bb3dec5 100644 (file)
@@ -1,21 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 /***
-  This file is part of systemd.
-
   Copyright 2013 Lennart Poettering
-
-  systemd is free software; you can redistribute it and/or modify it
-  under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or
-  (at your option) any later version.
-
-  systemd is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
 #include <endian.h>
 #include "bus-socket.h"
 #include "fd-util.h"
 #include "format-util.h"
-//#include "fs-util.h"
+#include "fs-util.h"
 #include "hexdecoct.h"
-//#include "io-util.h"
+#include "io-util.h"
 #include "macro.h"
 #include "missing.h"
-//#include "path-util.h"
-//#include "process-util.h"
+#include "path-util.h"
+#include "process-util.h"
 #include "selinux-util.h"
 #include "signal-util.h"
 #include "stdio-util.h"
@@ -261,16 +246,13 @@ static bool line_equals(const char *s, size_t m, const char *line) {
 }
 
 static bool line_begins(const char *s, size_t m, const char *word) {
-        size_t l;
-
-        l = strlen(word);
-        if (m < l)
-                return false;
+        const char *p;
 
-        if (memcmp(s, word, l) != 0)
+        p = memory_startswith(s, m, word);
+        if (!p)
                 return false;
 
-        return m == l || (m > l && s[l] == ' ');
+        return IN_SET(*p, 0, ' ');
 }
 
 static int verify_anonymous_token(sd_bus *b, const char *p, size_t l) {
@@ -790,7 +772,7 @@ static int bus_socket_inotify_setup(sd_bus *b) {
                         if (IN_SET(errno, ENOENT, ELOOP))
                                 break; /* This component doesn't exist yet, or the path contains a cyclic symlink right now */
 
-                        r = log_debug_errno(errno, "Failed to add inotify watch on %s: %m", isempty(prefix) ? "/" : prefix);
+                        r = log_debug_errno(errno, "Failed to add inotify watch on %s: %m", empty_to_root(prefix));
                         goto fail;
                 } else
                         new_watches[n++] = wd;
@@ -960,14 +942,9 @@ int bus_socket_exec(sd_bus *b) {
         if (r == 0) {
                 /* Child */
 
-                safe_close(s[0]);
-
                 if (rearrange_stdio(s[1], s[1], STDERR_FILENO) < 0)
                         _exit(EXIT_FAILURE);
 
-                (void) fd_nonblock(STDIN_FILENO, false);
-                (void) fd_nonblock(STDOUT_FILENO, false);
-
                 if (b->exec_argv)
                         execvp(b->exec_path, b->exec_argv);
                 else {
@@ -1220,7 +1197,7 @@ int bus_socket_read_message(sd_bus *bus) {
                                         return -EIO;
                                 }
 
-                                f = realloc(bus->fds, sizeof(int) * (bus->n_fds + n));
+                                f = reallocarray(bus->fds, bus->n_fds + n, sizeof(int));
                                 if (!f) {
                                         close_many((int*) CMSG_DATA(cmsg), n);
                                         return -ENOMEM;