1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-21 22:04:01 +03:00

tree-wide: port various places over to STARTSWITH_SET()

This commit is contained in:
Lennart Poettering 2018-11-23 16:30:23 +01:00
parent 52f1552073
commit 49fe5c0996
11 changed files with 31 additions and 51 deletions

View File

@ -44,9 +44,7 @@ static int find_pci_or_platform_parent(sd_device *device, sd_device **ret) {
c += strspn(c, DIGITS); c += strspn(c, DIGITS);
if (*c == '-') { if (*c == '-') {
/* A connector DRM device, let's ignore all but LVDS and eDP! */ /* A connector DRM device, let's ignore all but LVDS and eDP! */
if (!STARTSWITH_SET(c, "-LVDS-", "-Embedded DisplayPort-"))
if (!startswith(c, "-LVDS-") &&
!startswith(c, "-Embedded DisplayPort-"))
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }

View File

@ -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= /* Like valid_device_node_path(), but also allows full-subsystem expressions, like DeviceAllow= and DeviceDeny=
* accept it */ * accept it */
if (startswith(path, "block-") || if (STARTSWITH_SET(path, "block-", "char-"))
startswith(path, "char-"))
return true; return true;
return valid_device_node_path(path); return valid_device_node_path(path);

View File

@ -3242,7 +3242,7 @@ int config_parse_device_allow(
return 0; 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); r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue);
if (r < 0) if (r < 0)

View File

@ -510,11 +510,9 @@ static int add_crypttab_devices(void) {
continue; continue;
} }
uuid = startswith(device, "UUID="); uuid = STARTSWITH_SET(device, "UUID=", "luks-");
if (!uuid) if (!uuid)
uuid = path_startswith(device, "/dev/disk/by-uuid/"); uuid = path_startswith(device, "/dev/disk/by-uuid/");
if (!uuid)
uuid = startswith(name, "luks-");
if (uuid) if (uuid)
d = hashmap_get(arg_disks, uuid); d = hashmap_get(arg_disks, uuid);

View File

@ -630,10 +630,9 @@ static int create_remoteserver(
if (fd < 0) if (fd < 0)
return fd; return fd;
hostname = hostname = STARTSWITH_SET(arg_url, "https://", "http://");
startswith(arg_url, "https://") ?: if (!hostname)
startswith(arg_url, "http://") ?: hostname = arg_url;
arg_url;
hostname = strdupa(hostname); hostname = strdupa(hostname);
if ((p = strchr(hostname, '/'))) if ((p = strchr(hostname, '/')))

View File

@ -25,6 +25,7 @@
#include "sigbus.h" #include "sigbus.h"
#include "signal-util.h" #include "signal-util.h"
#include "string-util.h" #include "string-util.h"
#include "strv.h"
#include "util.h" #include "util.h"
#define PRIV_KEY_FILE CERTIFICATE_ROOT "/private/journal-upload.pem" #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)); memzero(u, sizeof(Uploader));
u->input = -1; u->input = -1;
if (!(host = startswith(url, "http://")) && !(host = startswith(url, "https://"))) { host = STARTSWITH_SET(url, "http://", "https://");
if (!host) {
host = url; host = url;
proto = "https://"; proto = "https://";
} }

View File

@ -606,9 +606,8 @@ static int manager_count_external_displays(Manager *m) {
return r; return r;
FOREACH_DEVICE(e, d) { FOREACH_DEVICE(e, d) {
const char *status, *enabled, *dash, *nn, *subsys;
sd_device *p; sd_device *p;
const char *status, *enabled, *dash, *nn, *i, *subsys;
bool external = false;
if (sd_device_get_parent(d, &p) < 0) if (sd_device_get_parent(d, &p) < 0)
continue; continue;
@ -631,16 +630,10 @@ static int manager_count_external_displays(Manager *m) {
continue; continue;
dash++; dash++;
FOREACH_STRING(i, "VGA-", "DVI-I-", "DVI-D-", "DVI-A-" if (!STARTSWITH_SET(dash,
"Composite-", "SVIDEO-", "Component-", "VGA-", "DVI-I-", "DVI-D-", "DVI-A-"
"DIN-", "DP-", "HDMI-A-", "HDMI-B-", "TV-") { "Composite-", "SVIDEO-", "Component-",
"DIN-", "DP-", "HDMI-A-", "HDMI-B-", "TV-"))
if (startswith(dash, i)) {
external = true;
break;
}
}
if (!external)
continue; continue;
/* Ignore ports that are not enabled */ /* Ignore ports that are not enabled */

View File

@ -384,12 +384,13 @@ static int parse_argv(int argc, char *argv[]) {
return log_oom(); return log_oom();
with_timer = with_timer || with_timer = with_timer ||
!!startswith(optarg, "OnActiveSec=") || STARTSWITH_SET(optarg,
!!startswith(optarg, "OnBootSec=") || "OnActiveSec=",
!!startswith(optarg, "OnStartupSec=") || "OnBootSec=",
!!startswith(optarg, "OnUnitActiveSec=") || "OnStartupSec=",
!!startswith(optarg, "OnUnitInactiveSec=") || "OnUnitActiveSec=",
!!startswith(optarg, "OnCalendar="); "OnUnitInactiveSec=",
"OnCalendar=");
break; break;
case ARG_PATH_PROPERTY: case ARG_PATH_PROPERTY:

View File

@ -219,14 +219,11 @@ int parse_acl(const char *text, acl_t *acl_access, acl_t *acl_default, bool want
STRV_FOREACH(entry, split) { STRV_FOREACH(entry, split) {
char *p; char *p;
p = startswith(*entry, "default:"); p = STARTSWITH_SET(*entry, "default:", "d:");
if (!p) if (!p)
p = startswith(*entry, "d:"); p = *entry;
if (p) r = strv_push(&d, p);
r = strv_push(&d, p);
else
r = strv_push(&a, *entry);
if (r < 0) if (r < 0)
return r; return r;
} }

View File

@ -3,6 +3,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "string-util.h" #include "string-util.h"
#include "strv.h"
#include "utf8.h" #include "utf8.h"
#include "web-util.h" #include "web-util.h"
@ -13,7 +14,7 @@ bool http_etag_is_valid(const char *etag) {
if (!endswith(etag, "\"")) if (!endswith(etag, "\""))
return false; return false;
if (!startswith(etag, "\"") && !startswith(etag, "W/\"")) if (!STARTSWITH_SET(etag, "\"", "W/\""))
return false; return false;
return true; return true;
@ -25,9 +26,7 @@ bool http_url_is_valid(const char *url) {
if (isempty(url)) if (isempty(url))
return false; return false;
p = startswith(url, "http://"); p = STARTSWITH_SET(url, "http://", "https://");
if (!p)
p = startswith(url, "https://");
if (!p) if (!p)
return false; return false;
@ -46,12 +45,7 @@ bool documentation_url_is_valid(const char *url) {
if (http_url_is_valid(url)) if (http_url_is_valid(url))
return true; return true;
p = startswith(url, "file:/"); p = STARTSWITH_SET(url, "file:/", "info:", "man:");
if (!p)
p = startswith(url, "info:");
if (!p)
p = startswith(url, "man:");
if (isempty(p)) if (isempty(p))
return false; return false;

View File

@ -57,6 +57,7 @@
#include "signal-util.h" #include "signal-util.h"
#include "socket-util.h" #include "socket-util.h"
#include "string-util.h" #include "string-util.h"
#include "strv.h"
#include "strxcpyx.h" #include "strxcpyx.h"
#include "syslog-util.h" #include "syslog-util.h"
#include "udev-builtin.h" #include "udev-builtin.h"
@ -361,9 +362,7 @@ static int worker_lock_block_device(sd_device *dev, int *ret_fd) {
if (r < 0) if (r < 0)
return log_device_debug_errno(dev, r, "Failed to get sysname: %m"); return log_device_debug_errno(dev, r, "Failed to get sysname: %m");
if (startswith(val, "dm-") || if (STARTSWITH_SET(val, "dm-", "md", "drbd"))
startswith(val, "md") ||
startswith(val, "drbd"))
return 0; return 0;
r = sd_device_get_devtype(dev, &val); r = sd_device_get_devtype(dev, &val);