summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-11-23 16:30:23 +0100
committerLennart Poettering <lennart@poettering.net>2018-11-26 14:08:46 +0100
commit49fe5c099639aa2111efb56c6ac609955a279279 (patch)
treebff451fbe68b0aa57fe8ad198695384eab264545
parentstrv: add new macro STARTSWITH_SET() (diff)
downloadsystemd-49fe5c099639aa2111efb56c6ac609955a279279.tar.xz
systemd-49fe5c099639aa2111efb56c6ac609955a279279.zip
tree-wide: port various places over to STARTSWITH_SET()
Diffstat (limited to '')
-rw-r--r--src/backlight/backlight.c4
-rw-r--r--src/basic/path-util.c3
-rw-r--r--src/core/load-fragment.c2
-rw-r--r--src/cryptsetup/cryptsetup-generator.c4
-rw-r--r--src/journal-remote/journal-remote-main.c7
-rw-r--r--src/journal-remote/journal-upload.c4
-rw-r--r--src/login/logind-core.c17
-rw-r--r--src/run/run.c13
-rw-r--r--src/shared/acl-util.c9
-rw-r--r--src/shared/web-util.c14
-rw-r--r--src/udev/udevd.c5
11 files changed, 31 insertions, 51 deletions
diff --git a/src/backlight/backlight.c b/src/backlight/backlight.c
index a866c68823..780ad56eb1 100644
--- a/src/backlight/backlight.c
+++ b/src/backlight/backlight.c
@@ -44,9 +44,7 @@ static int find_pci_or_platform_parent(sd_device *device, sd_device **ret) {
c += strspn(c, DIGITS);
if (*c == '-') {
/* A connector DRM device, let's ignore all but LVDS and eDP! */
-
- if (!startswith(c, "-LVDS-") &&
- !startswith(c, "-Embedded DisplayPort-"))
+ if (!STARTSWITH_SET(c, "-LVDS-", "-Embedded DisplayPort-"))
return -EOPNOTSUPP;
}
diff --git a/src/basic/path-util.c b/src/basic/path-util.c
index 2deb176240..eb64c886e6 100644
--- a/src/basic/path-util.c
+++ b/src/basic/path-util.c
@@ -919,8 +919,7 @@ bool valid_device_allow_pattern(const char *path) {
/* Like valid_device_node_path(), but also allows full-subsystem expressions, like DeviceAllow= and DeviceDeny=
* accept it */
- if (startswith(path, "block-") ||
- startswith(path, "char-"))
+ if (STARTSWITH_SET(path, "block-", "char-"))
return true;
return valid_device_node_path(path);
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index efefdaed99..ce222e4023 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -3242,7 +3242,7 @@ int config_parse_device_allow(
return 0;
}
- if (!startswith(resolved, "block-") && !startswith(resolved, "char-")) {
+ if (!STARTSWITH_SET(resolved, "block-", "char-")) {
r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue);
if (r < 0)
diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c
index 7da13dc207..b0b1065e2f 100644
--- a/src/cryptsetup/cryptsetup-generator.c
+++ b/src/cryptsetup/cryptsetup-generator.c
@@ -510,11 +510,9 @@ static int add_crypttab_devices(void) {
continue;
}
- uuid = startswith(device, "UUID=");
+ uuid = STARTSWITH_SET(device, "UUID=", "luks-");
if (!uuid)
uuid = path_startswith(device, "/dev/disk/by-uuid/");
- if (!uuid)
- uuid = startswith(name, "luks-");
if (uuid)
d = hashmap_get(arg_disks, uuid);
diff --git a/src/journal-remote/journal-remote-main.c b/src/journal-remote/journal-remote-main.c
index 44f3450d87..02078dcb4a 100644
--- a/src/journal-remote/journal-remote-main.c
+++ b/src/journal-remote/journal-remote-main.c
@@ -630,10 +630,9 @@ static int create_remoteserver(
if (fd < 0)
return fd;
- hostname =
- startswith(arg_url, "https://") ?:
- startswith(arg_url, "http://") ?:
- arg_url;
+ hostname = STARTSWITH_SET(arg_url, "https://", "http://");
+ if (!hostname)
+ hostname = arg_url;
hostname = strdupa(hostname);
if ((p = strchr(hostname, '/')))
diff --git a/src/journal-remote/journal-upload.c b/src/journal-remote/journal-upload.c
index f7b91fddde..70d0fcad4d 100644
--- a/src/journal-remote/journal-upload.c
+++ b/src/journal-remote/journal-upload.c
@@ -25,6 +25,7 @@
#include "sigbus.h"
#include "signal-util.h"
#include "string-util.h"
+#include "strv.h"
#include "util.h"
#define PRIV_KEY_FILE CERTIFICATE_ROOT "/private/journal-upload.pem"
@@ -408,7 +409,8 @@ static int setup_uploader(Uploader *u, const char *url, const char *state_file)
memzero(u, sizeof(Uploader));
u->input = -1;
- if (!(host = startswith(url, "http://")) && !(host = startswith(url, "https://"))) {
+ host = STARTSWITH_SET(url, "http://", "https://");
+ if (!host) {
host = url;
proto = "https://";
}
diff --git a/src/login/logind-core.c b/src/login/logind-core.c
index 2bab2fd2f5..60831bb1c3 100644
--- a/src/login/logind-core.c
+++ b/src/login/logind-core.c
@@ -606,9 +606,8 @@ static int manager_count_external_displays(Manager *m) {
return r;
FOREACH_DEVICE(e, d) {
+ const char *status, *enabled, *dash, *nn, *subsys;
sd_device *p;
- const char *status, *enabled, *dash, *nn, *i, *subsys;
- bool external = false;
if (sd_device_get_parent(d, &p) < 0)
continue;
@@ -631,16 +630,10 @@ static int manager_count_external_displays(Manager *m) {
continue;
dash++;
- FOREACH_STRING(i, "VGA-", "DVI-I-", "DVI-D-", "DVI-A-"
- "Composite-", "SVIDEO-", "Component-",
- "DIN-", "DP-", "HDMI-A-", "HDMI-B-", "TV-") {
-
- if (startswith(dash, i)) {
- external = true;
- break;
- }
- }
- if (!external)
+ if (!STARTSWITH_SET(dash,
+ "VGA-", "DVI-I-", "DVI-D-", "DVI-A-"
+ "Composite-", "SVIDEO-", "Component-",
+ "DIN-", "DP-", "HDMI-A-", "HDMI-B-", "TV-"))
continue;
/* Ignore ports that are not enabled */
diff --git a/src/run/run.c b/src/run/run.c
index 0475156a43..e9e31282b6 100644
--- a/src/run/run.c
+++ b/src/run/run.c
@@ -384,12 +384,13 @@ static int parse_argv(int argc, char *argv[]) {
return log_oom();
with_timer = with_timer ||
- !!startswith(optarg, "OnActiveSec=") ||
- !!startswith(optarg, "OnBootSec=") ||
- !!startswith(optarg, "OnStartupSec=") ||
- !!startswith(optarg, "OnUnitActiveSec=") ||
- !!startswith(optarg, "OnUnitInactiveSec=") ||
- !!startswith(optarg, "OnCalendar=");
+ STARTSWITH_SET(optarg,
+ "OnActiveSec=",
+ "OnBootSec=",
+ "OnStartupSec=",
+ "OnUnitActiveSec=",
+ "OnUnitInactiveSec=",
+ "OnCalendar=");
break;
case ARG_PATH_PROPERTY:
diff --git a/src/shared/acl-util.c b/src/shared/acl-util.c
index 1eaf653103..6f0657174c 100644
--- a/src/shared/acl-util.c
+++ b/src/shared/acl-util.c
@@ -219,14 +219,11 @@ int parse_acl(const char *text, acl_t *acl_access, acl_t *acl_default, bool want
STRV_FOREACH(entry, split) {
char *p;
- p = startswith(*entry, "default:");
+ p = STARTSWITH_SET(*entry, "default:", "d:");
if (!p)
- p = startswith(*entry, "d:");
+ p = *entry;
- if (p)
- r = strv_push(&d, p);
- else
- r = strv_push(&a, *entry);
+ r = strv_push(&d, p);
if (r < 0)
return r;
}
diff --git a/src/shared/web-util.c b/src/shared/web-util.c
index 82221af194..edf650d200 100644
--- a/src/shared/web-util.c
+++ b/src/shared/web-util.c
@@ -3,6 +3,7 @@
#include <stdbool.h>
#include "string-util.h"
+#include "strv.h"
#include "utf8.h"
#include "web-util.h"
@@ -13,7 +14,7 @@ bool http_etag_is_valid(const char *etag) {
if (!endswith(etag, "\""))
return false;
- if (!startswith(etag, "\"") && !startswith(etag, "W/\""))
+ if (!STARTSWITH_SET(etag, "\"", "W/\""))
return false;
return true;
@@ -25,9 +26,7 @@ bool http_url_is_valid(const char *url) {
if (isempty(url))
return false;
- p = startswith(url, "http://");
- if (!p)
- p = startswith(url, "https://");
+ p = STARTSWITH_SET(url, "http://", "https://");
if (!p)
return false;
@@ -46,12 +45,7 @@ bool documentation_url_is_valid(const char *url) {
if (http_url_is_valid(url))
return true;
- p = startswith(url, "file:/");
- if (!p)
- p = startswith(url, "info:");
- if (!p)
- p = startswith(url, "man:");
-
+ p = STARTSWITH_SET(url, "file:/", "info:", "man:");
if (isempty(p))
return false;
diff --git a/src/udev/udevd.c b/src/udev/udevd.c
index 6eacfe811f..9c8e7f977f 100644
--- a/src/udev/udevd.c
+++ b/src/udev/udevd.c
@@ -57,6 +57,7 @@
#include "signal-util.h"
#include "socket-util.h"
#include "string-util.h"
+#include "strv.h"
#include "strxcpyx.h"
#include "syslog-util.h"
#include "udev-builtin.h"
@@ -361,9 +362,7 @@ static int worker_lock_block_device(sd_device *dev, int *ret_fd) {
if (r < 0)
return log_device_debug_errno(dev, r, "Failed to get sysname: %m");
- if (startswith(val, "dm-") ||
- startswith(val, "md") ||
- startswith(val, "drbd"))
+ if (STARTSWITH_SET(val, "dm-", "md", "drbd"))
return 0;
r = sd_device_get_devtype(dev, &val);