]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: use path_startswith() rather than startswith() where ever that's appropriate
authorLennart Poettering <lennart@poettering.net>
Wed, 9 Aug 2017 17:03:39 +0000 (19:03 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 9 Aug 2017 17:03:39 +0000 (19:03 +0200)
When checking path prefixes we really should use the right APIs, just in
case people add multiple slashes to their paths...

src/basic/terminal-util.c
src/core/cgroup.c
src/core/dbus-cgroup.c
src/login/logind-utmp.c
src/sysctl/sysctl.c
src/udev/udevadm-test-builtin.c
src/udev/udevadm-util.c

index c570c2e3568db509b59e731dbebd02335905febf..d665a181bc938a4bd967ae144beac334c8b11ff8 100644 (file)
@@ -55,6 +55,7 @@
 #include "terminal-util.h"
 #include "time-util.h"
 #include "util.h"
+#include "path-util.h"
 
 static volatile unsigned cached_columns = 0;
 static volatile unsigned cached_lines = 0;
@@ -556,6 +557,7 @@ int terminal_vhangup(const char *name) {
 
 int vt_disallocate(const char *name) {
         _cleanup_close_ int fd = -1;
+        const char *e, *n;
         unsigned u;
         int r;
 
@@ -563,7 +565,8 @@ int vt_disallocate(const char *name) {
          * (i.e. because it is the active one), at least clear it
          * entirely (including the scrollback buffer) */
 
-        if (!startswith(name, "/dev/"))
+        e = path_startswith(name, "/dev/");
+        if (!e)
                 return -EINVAL;
 
         if (!tty_is_vc(name)) {
@@ -582,10 +585,11 @@ int vt_disallocate(const char *name) {
                 return 0;
         }
 
-        if (!startswith(name, "/dev/tty"))
+        n = startswith(e, "tty");
+        if (!n)
                 return -EINVAL;
 
-        r = safe_atou(name+8, &u);
+        r = safe_atou(n, &u);
         if (r < 0)
                 return r;
 
index 82d86a0ad40082cd17d2e35ac4ec878d59122e31..94a4f9ae29c4dbbe0846e528c98f9bacc6000c3e 100644 (file)
@@ -949,7 +949,7 @@ static void cgroup_context_apply(Unit *u, CGroupMask mask, ManagerState state) {
 
                         acc[k++] = 0;
 
-                        if (startswith(a->path, "/dev/"))
+                        if (path_startswith(a->path, "/dev/"))
                                 whitelist_device(path, a->path, acc);
                         else if ((val = startswith(a->path, "block-")))
                                 whitelist_major(path, val, 'b', acc);
index 4e6d1effaa804dda5da3da7e3dc25303d49ad0eb..c1026e3f5b483937219d304bb245164a04b433c9 100644 (file)
@@ -1018,8 +1018,8 @@ int bus_cgroup_set_property(
 
                 while ((r = sd_bus_message_read(message, "(ss)", &path, &rwm)) > 0) {
 
-                        if ((!startswith(path, "/dev/") &&
-                             !startswith(path, "/run/systemd/inaccessible/") &&
+                        if ((!path_startswith(path, "/dev/") &&
+                             !path_startswith(path, "/run/systemd/inaccessible/") &&
                              !startswith(path, "block-") &&
                              !startswith(path, "char-")) ||
                             strpbrk(path, WHITESPACE))
index 311751c2db2035d1d8691dff71661c1d2f492e5d..00c4cbcf4f1fe7dbe467f9bc80b6e9c61ba5bf86 100644 (file)
@@ -31,6 +31,7 @@
 #include "bus-util.h"
 #include "format-util.h"
 #include "logind.h"
+#include "path-util.h"
 #include "special.h"
 #include "strv.h"
 #include "unit-name.h"
@@ -60,15 +61,19 @@ _const_ static usec_t when_wall(usec_t n, usec_t elapse) {
 }
 
 bool logind_wall_tty_filter(const char *tty, void *userdata) {
-
         Manager *m = userdata;
+        const char *p;
 
         assert(m);
 
-        if (!startswith(tty, "/dev/") || !m->scheduled_shutdown_tty)
+        if (!m->scheduled_shutdown_tty)
+                return true;
+
+        p = path_startswith(tty, "/dev/");
+        if (!p)
                 return true;
 
-        return !streq(tty + 5, m->scheduled_shutdown_tty);
+        return !streq(p, m->scheduled_shutdown_tty);
 }
 
 static int warn_wall(Manager *m, usec_t n) {
index b3587e249dc60ffe1d1cc878935b476a774ffb2a..41a6dcbd1b0264905f01dd25b3de6214069b11b9 100644 (file)
@@ -223,7 +223,7 @@ static int parse_argv(int argc, char *argv[]) {
                          * sysctl name available. */
                         sysctl_normalize(optarg);
 
-                        if (startswith(optarg, "/proc/sys"))
+                        if (path_startswith(optarg, "/proc/sys"))
                                 p = strdup(optarg);
                         else
                                 p = strappend("/proc/sys/", optarg);
index 0b180d03eb399abc772c1ab4413f2707d8915104..b5662be5c2980b688f76019060da413d071012bb 100644 (file)
@@ -21,6 +21,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "path-util.h"
 #include "string-util.h"
 #include "udev.h"
 
@@ -80,7 +81,7 @@ static int adm_builtin(struct udev *udev, int argc, char *argv[]) {
         }
 
         /* add /sys if needed */
-        if (!startswith(syspath, "/sys"))
+        if (!path_startswith(syspath, "/sys"))
                 strscpyl(filename, sizeof(filename), "/sys", syspath, NULL);
         else
                 strscpy(filename, sizeof(filename), syspath);
index 3539c1d6ab15a48088cca120518e9a0ba28657a2..beda7c36bb8cb556d3b1935f16f8ed2529629699 100644 (file)
@@ -15,6 +15,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "path-util.h"
 #include "string-util.h"
 #include "udevadm-util.h"
 
@@ -28,7 +29,7 @@ struct udev_device *find_device(struct udev *udev,
         if (prefix && !startswith(id, prefix))
                 id = strjoina(prefix, id);
 
-        if (startswith(id, "/dev/")) {
+        if (path_startswith(id, "/dev/")) {
                 struct stat statbuf;
                 char type;
 
@@ -43,7 +44,7 @@ struct udev_device *find_device(struct udev *udev,
                         return NULL;
 
                 return udev_device_new_from_devnum(udev, type, statbuf.st_rdev);
-        } else if (startswith(id, "/sys/"))
+        } else if (path_startswith(id, "/sys/"))
                 return udev_device_new_from_syspath(udev, id);
         else
                 return NULL;