chiark / gitweb /
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)
committerSven Eden <yamakuzure@gmx.net>
Mon, 25 Sep 2017 12:31:04 +0000 (14:31 +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

index 37da0b192ccea600ca88addf70d0f3c65b6ef9d7..11597d08576f2d87b07106c78c15071039fdf693 100644 (file)
@@ -561,6 +561,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;
 
@@ -568,7 +569,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)) {
@@ -587,10 +589,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;