tree-wide: port various parsers over to read_stripped_line()

This commit is contained in:
Lennart Poettering 2023-10-16 18:01:00 +02:00
parent c56cb33f09
commit 0ff6ff2b29
26 changed files with 127 additions and 194 deletions

View file

@ -473,16 +473,14 @@ static int get_process_id(pid_t pid, const char *field, uid_t *ret) {
_cleanup_free_ char *line = NULL;
char *l;
r = read_line(f, LONG_LINE_MAX, &line);
r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return r;
if (r == 0)
break;
l = strstrip(line);
if (startswith(l, field)) {
l += strlen(field);
l = startswith(line, field);
if (l) {
l += strspn(l, WHITESPACE);
l[strcspn(l, WHITESPACE)] = 0;

View file

@ -85,22 +85,20 @@ static int apply_file(const char *filename, bool ignore_enoent) {
log_debug("Applying %s%s", pp, special_glyph(SPECIAL_GLYPH_ELLIPSIS));
for (unsigned line = 1;; line++) {
_cleanup_free_ char *text = NULL;
char *p;
int k;
k = read_line(f, LONG_LINE_MAX, &text);
k = read_stripped_line(f, LONG_LINE_MAX, &text);
if (k < 0)
return log_error_errno(k, "Failed to read file '%s': %m", pp);
if (k == 0)
break;
p = strstrip(text);
if (isempty(p))
if (isempty(text))
continue;
if (strchr(COMMENTS, p[0]))
if (strchr(COMMENTS, text[0]))
continue;
RET_GATHER(r, apply_rule(filename, line, p));
RET_GATHER(r, apply_rule(filename, line, text));
}
return r;

View file

@ -298,15 +298,14 @@ static int process(
uint64_t k, *q;
char *l;
r = read_line(f, LONG_LINE_MAX, &line);
r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return r;
if (r == 0)
break;
/* Trim and skip the device */
l = strstrip(line);
l += strcspn(l, WHITESPACE);
/* Skip the device */
l = line + strcspn(line, WHITESPACE);
l += strspn(l, WHITESPACE);
if (all_unified) {

View file

@ -221,21 +221,19 @@ static int manager_deserialize_one_unit(Manager *m, const char *name, FILE *f, F
}
static int manager_deserialize_units(Manager *m, FILE *f, FDSet *fds) {
const char *unit_name;
int r;
for (;;) {
_cleanup_free_ char *line = NULL;
/* Start marker */
r = read_line(f, LONG_LINE_MAX, &line);
r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return log_error_errno(r, "Failed to read serialization line: %m");
if (r == 0)
break;
unit_name = strstrip(line);
r = manager_deserialize_one_unit(m, unit_name, f, fds);
r = manager_deserialize_one_unit(m, line, f, fds);
if (r == -ENOMEM)
return r;
if (r < 0) {

View file

@ -554,24 +554,22 @@ int unit_deserialize_state(Unit *u, FILE *f, FDSet *fds) {
int unit_deserialize_state_skip(FILE *f) {
int r;
assert(f);
/* Skip serialized data for this unit. We don't know what it is. */
for (;;) {
_cleanup_free_ char *line = NULL;
char *l;
r = read_line(f, LONG_LINE_MAX, &line);
r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return log_error_errno(r, "Failed to read serialization line: %m");
if (r == 0)
return 0;
l = strstrip(line);
/* End marker */
if (isempty(l))
if (isempty(line))
return 1;
}
}

View file

@ -809,10 +809,10 @@ static int add_crypttab_devices(void) {
_cleanup_free_ char *line = NULL, *name = NULL, *device = NULL, *keyspec = NULL, *options = NULL,
*keyfile = NULL, *keydev = NULL, *headerdev = NULL, *filtered_header = NULL;
crypto_device *d = NULL;
char *l, *uuid;
char *uuid;
int k;
r = read_line(f, LONG_LINE_MAX, &line);
r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return log_error_errno(r, "Failed to read %s: %m", arg_crypttab);
if (r == 0)
@ -820,11 +820,10 @@ static int add_crypttab_devices(void) {
crypttab_line++;
l = strstrip(line);
if (IN_SET(l[0], 0, '#'))
if (IN_SET(line[0], 0, '#'))
continue;
k = sscanf(l, "%ms %ms %ms %ms", &name, &device, &keyspec, &options);
k = sscanf(line, "%ms %ms %ms %ms", &name, &device, &keyspec, &options);
if (k < 2 || k > 4) {
log_error("Failed to parse %s:%u, ignoring.", arg_crypttab, crypttab_line);
continue;

View file

@ -168,9 +168,8 @@ static int add_credential_gettys(void) {
for (;;) {
_cleanup_free_ char *tty = NULL;
char *s;
r = read_line(f, PATH_MAX, &tty);
r = read_stripped_line(f, PATH_MAX, &tty);
if (r == 0)
break;
if (r < 0) {
@ -178,11 +177,10 @@ static int add_credential_gettys(void) {
break;
}
s = strstrip(tty);
if (startswith(s, "#"))
if (startswith(tty, "#"))
continue;
r = t->func(s);
r = t->func(tty);
if (r < 0)
return r;
}

View file

@ -132,9 +132,8 @@ static int add_integritytab_devices(void) {
for (;;) {
_cleanup_free_ char *line = NULL, *name = NULL, *device_id = NULL, *device_path = NULL, *key_file = NULL, *options = NULL;
char *l;
r = read_line(f, LONG_LINE_MAX, &line);
r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return log_error_errno(r, "Failed to read %s: %m", arg_integritytab);
if (r == 0)
@ -142,17 +141,13 @@ static int add_integritytab_devices(void) {
integritytab_line++;
l = strstrip(line);
if (!l)
continue;
if (IN_SET(l[0], 0, '#'))
if (IN_SET(line[0], 0, '#'))
continue;
/* The key file and the options are optional */
r = sscanf(l, "%ms %ms %ms %ms", &name, &device_id, &key_file, &options);
r = sscanf(line, "%ms %ms %ms %ms", &name, &device_id, &key_file, &options);
if (!IN_SET(r, 2, 3, 4)) {
log_error("Failed to parse %s:%u, ignoring.", l, integritytab_line);
log_error("Failed to parse %s:%u, ignoring.", arg_integritytab, integritytab_line);
continue;
}

View file

@ -70,7 +70,6 @@ static int from_user_dir(const char *field, char **buffer, const char **ret) {
_cleanup_free_ char *b = NULL;
_cleanup_free_ const char *fn = NULL;
const char *c = NULL;
size_t n;
int r;
assert(field);
@ -93,26 +92,21 @@ static int from_user_dir(const char *field, char **buffer, const char **ret) {
return -errno;
}
/* This is an awful parse, but it follows closely what
* xdg-user-dirs does upstream */
n = strlen(field);
/* This is an awful parse, but it follows closely what xdg-user-dirs does upstream */
for (;;) {
_cleanup_free_ char *line = NULL;
char *l, *p, *e;
char *p, *e;
r = read_line(f, LONG_LINE_MAX, &line);
r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return r;
if (r == 0)
break;
l = strstrip(line);
if (!strneq(l, field, n))
p = startswith(line, field);
if (!p)
continue;
p = l + n;
p += strspn(p, WHITESPACE);
if (*p != '=')

View file

@ -314,27 +314,25 @@ static int list_x11_keymaps(int argc, char **argv, void *userdata) {
for (;;) {
_cleanup_free_ char *line = NULL;
char *l, *w;
char *w;
r = read_line(f, LONG_LINE_MAX, &line);
r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return log_error_errno(r, "Failed to read keyboard mapping list: %m");
if (r == 0)
break;
l = strstrip(line);
if (isempty(l))
if (isempty(line))
continue;
if (l[0] == '!') {
if (startswith(l, "! model"))
if (line[0] == '!') {
if (startswith(line, "! model"))
state = MODELS;
else if (startswith(l, "! layout"))
else if (startswith(line, "! layout"))
state = LAYOUTS;
else if (startswith(l, "! variant"))
else if (startswith(line, "! variant"))
state = VARIANTS;
else if (startswith(l, "! option"))
else if (startswith(line, "! option"))
state = OPTIONS;
else
state = NONE;
@ -345,7 +343,7 @@ static int list_x11_keymaps(int argc, char **argv, void *userdata) {
if (state != look_for)
continue;
w = l + strcspn(l, WHITESPACE);
w = line + strcspn(line, WHITESPACE);
if (argc > 1) {
char *e;
@ -368,8 +366,7 @@ static int list_x11_keymaps(int argc, char **argv, void *userdata) {
} else
*w = 0;
r = strv_extend(&list, l);
if (r < 0)
if (strv_consume(&list, TAKE_PTR(line)) < 0)
return log_oom();
}

View file

@ -434,22 +434,20 @@ int x11_read_data(Context *c, sd_bus_message *m) {
for (;;) {
_cleanup_free_ char *line = NULL;
char *l;
r = read_line(f, LONG_LINE_MAX, &line);
r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return r;
if (r == 0)
break;
l = strstrip(line);
if (IN_SET(l[0], 0, '#'))
if (IN_SET(line[0], 0, '#'))
continue;
if (in_section && first_word(l, "Option")) {
if (in_section && first_word(line, "Option")) {
_cleanup_strv_free_ char **a = NULL;
r = strv_split_full(&a, l, WHITESPACE, EXTRACT_UNQUOTE);
r = strv_split_full(&a, line, WHITESPACE, EXTRACT_UNQUOTE);
if (r < 0)
return r;
@ -469,17 +467,17 @@ int x11_read_data(Context *c, sd_bus_message *m) {
free_and_replace(*p, a[2]);
}
} else if (!in_section && first_word(l, "Section")) {
} else if (!in_section && first_word(line, "Section")) {
_cleanup_strv_free_ char **a = NULL;
r = strv_split_full(&a, l, WHITESPACE, EXTRACT_UNQUOTE);
r = strv_split_full(&a, line, WHITESPACE, EXTRACT_UNQUOTE);
if (r < 0)
return -ENOMEM;
if (strv_length(a) == 2 && streq(a[1], "InputClass"))
in_section = true;
} else if (in_section && first_word(l, "EndSection"))
} else if (in_section && first_word(line, "EndSection"))
in_section = false;
}
@ -618,10 +616,9 @@ static int read_next_mapping(
_cleanup_strv_free_ char **b = NULL;
_cleanup_free_ char *line = NULL;
size_t length;
const char *l;
int r;
r = read_line(f, LONG_LINE_MAX, &line);
r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return r;
if (r == 0)
@ -629,11 +626,10 @@ static int read_next_mapping(
(*n)++;
l = strstrip(line);
if (IN_SET(l[0], 0, '#'))
if (IN_SET(line[0], 0, '#'))
continue;
r = strv_split_full(&b, l, WHITESPACE, EXTRACT_UNQUOTE);
r = strv_split_full(&b, line, WHITESPACE, EXTRACT_UNQUOTE);
if (r < 0)
return r;
@ -1008,16 +1004,14 @@ static int locale_gen_locale_supported(const char *locale_entry) {
for (;;) {
_cleanup_free_ char *line = NULL;
char *l;
r = read_line(f, LONG_LINE_MAX, &line);
r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return log_debug_errno(r, "Failed to read /usr/share/i18n/SUPPORTED: %m");
if (r == 0)
return 0;
l = strstrip(line);
if (strcaseeq_ptr(l, locale_entry))
if (strcaseeq_ptr(line, locale_entry))
return 1;
}
}

View file

@ -79,22 +79,20 @@ static int apply_file(struct kmod_ctx *ctx, const char *path, bool ignore_enoent
log_debug("apply: %s", pp);
for (;;) {
_cleanup_free_ char *line = NULL;
char *l;
int k;
k = read_line(f, LONG_LINE_MAX, &line);
k = read_stripped_line(f, LONG_LINE_MAX, &line);
if (k < 0)
return log_error_errno(k, "Failed to read file '%s': %m", pp);
if (k == 0)
break;
l = strstrip(line);
if (isempty(l))
if (isempty(line))
continue;
if (strchr(COMMENTS, *l))
if (strchr(COMMENTS, *line))
continue;
k = module_load_and_warn(ctx, l, true);
k = module_load_and_warn(ctx, line, true);
if (k == -ENOENT)
continue;
RET_GATHER(r, k);

View file

@ -325,19 +325,17 @@ static int dhcp4_server_set_dns_from_resolve_conf(Link *link) {
for (;;) {
_cleanup_free_ char *line = NULL;
const char *a;
char *l;
r = read_line(f, LONG_LINE_MAX, &line);
r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return log_error_errno(r, "Failed to read " PRIVATE_UPLINK_RESOLV_CONF ": %m");
if (r == 0)
break;
l = strstrip(line);
if (IN_SET(*l, '#', ';', 0))
if (IN_SET(*line, '#', ';', 0))
continue;
a = first_word(l, "nameserver");
a = first_word(line, "nameserver");
if (!a)
continue;

View file

@ -226,9 +226,9 @@ int resolvconf_parse_argv(int argc, char *argv[]) {
for (;;) {
_cleanup_free_ char *line = NULL;
const char *a, *l;
const char *a;
r = read_line(stdin, LONG_LINE_MAX, &line);
r = read_stripped_line(stdin, LONG_LINE_MAX, &line);
if (r < 0)
return log_error_errno(r, "Failed to read from stdin: %m");
if (r == 0)
@ -236,25 +236,24 @@ int resolvconf_parse_argv(int argc, char *argv[]) {
n++;
l = strstrip(line);
if (IN_SET(*l, '#', ';', 0))
if (IN_SET(*line, '#', ';', 0))
continue;
a = first_word(l, "nameserver");
a = first_word(line, "nameserver");
if (a) {
(void) parse_nameserver(a);
continue;
}
a = first_word(l, "domain");
a = first_word(line, "domain");
if (!a)
a = first_word(l, "search");
a = first_word(line, "search");
if (a) {
(void) parse_search_domain(a);
continue;
}
log_syntax(NULL, LOG_DEBUG, "stdin", n, 0, "Ignoring resolv.conf line: %s", l);
log_syntax(NULL, LOG_DEBUG, "stdin", n, 0, "Ignoring resolv.conf line: %s", line);
}
if (type == TYPE_EXCLUSIVE) {

View file

@ -441,9 +441,8 @@ static int dns_trust_anchor_load_files(
for (;;) {
_cleanup_free_ char *line = NULL;
char *l;
r = read_line(g, LONG_LINE_MAX, &line);
r = read_stripped_line(g, LONG_LINE_MAX, &line);
if (r < 0) {
log_warning_errno(r, "Failed to read '%s', ignoring: %m", *f);
break;
@ -453,14 +452,13 @@ static int dns_trust_anchor_load_files(
n++;
l = strstrip(line);
if (isempty(l))
if (isempty(line))
continue;
if (*l == ';')
if (*line == ';')
continue;
(void) loader(d, *f, n, l);
(void) loader(d, *f, n, line);
}
}

View file

@ -122,9 +122,8 @@ int manager_read_resolv_conf(Manager *m) {
for (;;) {
_cleanup_free_ char *line = NULL;
const char *a;
char *l;
r = read_line(f, LONG_LINE_MAX, &line);
r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0) {
log_error_errno(r, "Failed to read /etc/resolv.conf: %m");
goto clear;
@ -134,11 +133,10 @@ int manager_read_resolv_conf(Manager *m) {
n++;
l = strstrip(line);
if (IN_SET(*l, '#', ';', 0))
if (IN_SET(*line, '#', ';', 0))
continue;
a = first_word(l, "nameserver");
a = first_word(line, "nameserver");
if (a) {
r = manager_parse_dns_server_string_and_warn(m, DNS_SERVER_SYSTEM, a);
if (r < 0)
@ -147,9 +145,9 @@ int manager_read_resolv_conf(Manager *m) {
continue;
}
a = first_word(l, "domain");
a = first_word(line, "domain");
if (!a) /* We treat "domain" lines, and "search" lines as equivalent, and add both to our list. */
a = first_word(l, "search");
a = first_word(line, "search");
if (a) {
r = manager_parse_search_domains_and_warn(m, a);
if (r < 0)
@ -158,7 +156,7 @@ int manager_read_resolv_conf(Manager *m) {
continue;
}
log_syntax(NULL, LOG_DEBUG, "/etc/resolv.conf", n, 0, "Ignoring resolv.conf line: %s", l);
log_syntax(NULL, LOG_DEBUG, "/etc/resolv.conf", n, 0, "Ignoring resolv.conf line: %s", line);
}
m->resolv_conf_stat = st;

View file

@ -325,9 +325,8 @@ static int boot_entry_load_type1(
for (;;) {
_cleanup_free_ char *buf = NULL, *field = NULL;
const char *p;
r = read_line(f, LONG_LINE_MAX, &buf);
r = read_stripped_line(f, LONG_LINE_MAX, &buf);
if (r == 0)
break;
if (r == -ENOBUFS)
@ -337,10 +336,10 @@ static int boot_entry_load_type1(
line++;
p = strstrip(buf);
if (IN_SET(p[0], '#', '\0'))
if (IN_SET(buf[0], '#', '\0'))
continue;
const char *p = buf;
r = extract_first_word(&p, &field, NULL, 0);
if (r < 0) {
log_syntax(NULL, LOG_WARNING, tmp.path, line, r, "Failed to parse, ignoring line: %m");
@ -450,9 +449,8 @@ int boot_loader_read_conf(BootConfig *config, FILE *file, const char *path) {
for (;;) {
_cleanup_free_ char *buf = NULL, *field = NULL;
const char *p;
r = read_line(file, LONG_LINE_MAX, &buf);
r = read_stripped_line(file, LONG_LINE_MAX, &buf);
if (r == 0)
break;
if (r == -ENOBUFS)
@ -462,10 +460,10 @@ int boot_loader_read_conf(BootConfig *config, FILE *file, const char *path) {
line++;
p = strstrip(buf);
if (IN_SET(p[0], '#', '\0'))
if (IN_SET(buf[0], '#', '\0'))
continue;
const char *p = buf;
r = extract_first_word(&p, &field, NULL, 0);
if (r < 0) {
log_syntax(NULL, LOG_WARNING, path, line, r, "Failed to parse, ignoring line: %m");

View file

@ -79,32 +79,24 @@ int read_etc_hostname_stream(FILE *f, char **ret) {
for (;;) {
_cleanup_free_ char *line = NULL;
char *p;
r = read_line(f, LONG_LINE_MAX, &line);
r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return r;
if (r == 0) /* EOF without any hostname? the file is empty, let's treat that exactly like no file at all: ENOENT */
return -ENOENT;
p = strstrip(line);
/* File may have empty lines or comments, ignore them */
if (!IN_SET(*p, '\0', '#')) {
char *copy;
if (IN_SET(line[0], '\0', '#'))
continue;
hostname_cleanup(p); /* normalize the hostname */
hostname_cleanup(line); /* normalize the hostname */
if (!hostname_is_valid(p, VALID_HOSTNAME_TRAILING_DOT)) /* check that the hostname we return is valid */
return -EBADMSG;
if (!hostname_is_valid(line, VALID_HOSTNAME_TRAILING_DOT)) /* check that the hostname we return is valid */
return -EBADMSG;
copy = strdup(p);
if (!copy)
return -ENOMEM;
*ret = copy;
return 0;
}
*ret = TAKE_PTR(line);
return 0;
}
}

View file

@ -3246,23 +3246,21 @@ static int read_presets(RuntimeScope scope, const char *root_dir, UnitFilePreset
_cleanup_free_ char *line = NULL;
_cleanup_(unit_file_preset_rule_done) UnitFilePresetRule rule = {};
const char *parameter;
char *l;
r = read_line(f, LONG_LINE_MAX, &line);
r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return r;
if (r == 0)
break;
l = strstrip(line);
n++;
if (isempty(l))
if (isempty(line))
continue;
if (strchr(COMMENTS, *l))
if (strchr(COMMENTS, line[0]))
continue;
parameter = first_word(l, "enable");
parameter = first_word(line, "enable");
if (parameter) {
char *unit_name;
char **instances = NULL;
@ -3281,7 +3279,7 @@ static int read_presets(RuntimeScope scope, const char *root_dir, UnitFilePreset
};
}
parameter = first_word(l, "disable");
parameter = first_word(line, "disable");
if (parameter) {
char *pattern;
@ -3295,7 +3293,7 @@ static int read_presets(RuntimeScope scope, const char *root_dir, UnitFilePreset
};
}
parameter = first_word(l, "ignore");
parameter = first_word(line, "ignore");
if (parameter) {
char *pattern;

View file

@ -268,7 +268,7 @@ int deserialize_read_line(FILE *f, char **ret) {
assert(f);
assert(ret);
r = read_line(f, LONG_LINE_MAX, &line);
r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return log_error_errno(r, "Failed to read serialization line: %m");
if (r == 0) { /* eof */
@ -276,15 +276,11 @@ int deserialize_read_line(FILE *f, char **ret) {
return 0;
}
const char *l = strstrip(line);
if (isempty(l)) { /* End marker */
if (isempty(line)) { /* End marker */
*ret = NULL;
return 0;
}
if (free_and_strdup(&line, l) < 0)
return log_oom();
*ret = TAKE_PTR(line);
return 1;
}

View file

@ -238,10 +238,10 @@ static int parse_file(OrderedHashmap **sysctl_options, const char *path, bool ig
_cleanup_free_ char *l = NULL;
bool ignore_failure = false;
Option *existing;
char *p, *value;
char *value;
int k;
k = read_line(f, LONG_LINE_MAX, &l);
k = read_stripped_line(f, LONG_LINE_MAX, &l);
if (k == 0)
break;
if (k < 0)
@ -249,13 +249,12 @@ static int parse_file(OrderedHashmap **sysctl_options, const char *path, bool ig
c++;
p = strstrip(l);
if (isempty(p))
if (isempty(l))
continue;
if (strchr(COMMENTS "\n", *p))
if (strchr(COMMENTS, l[0]))
continue;
char *p = l;
value = strchr(p, '=');
if (value) {
if (p[0] == '-') {

View file

@ -2005,10 +2005,9 @@ static int read_config_file(Context *c, const char *fn, bool ignore_enoent) {
for (;;) {
_cleanup_free_ char *line = NULL;
char *l;
int k;
k = read_line(f, LONG_LINE_MAX, &line);
k = read_stripped_line(f, LONG_LINE_MAX, &line);
if (k < 0)
return log_error_errno(k, "Failed to read '%s': %m", fn);
if (k == 0)
@ -2016,11 +2015,10 @@ static int read_config_file(Context *c, const char *fn, bool ignore_enoent) {
v++;
l = strstrip(line);
if (IN_SET(*l, 0, '#'))
if (IN_SET(line[0], 0, '#'))
continue;
k = parse_line(c, fn, v, l);
k = parse_line(c, fn, v, line);
if (k < 0 && r == 0)
r = k;
}

View file

@ -450,9 +450,8 @@ static int load_sysv(SysvStub *s) {
for (;;) {
_cleanup_free_ char *l = NULL;
char *t;
r = read_line(f, LONG_LINE_MAX, &l);
r = read_stripped_line(f, LONG_LINE_MAX, &l);
if (r < 0)
return log_error_errno(r, "Failed to read configuration file '%s': %m", s->path);
if (r == 0)
@ -460,17 +459,16 @@ static int load_sysv(SysvStub *s) {
line++;
t = strstrip(l);
if (*t != '#') {
if (l[0] != '#') {
/* Try to figure out whether this init script supports
* the reload operation. This heuristic looks for
* "Usage" lines which include the reload option. */
if (state == USAGE_CONTINUATION ||
(state == NORMAL && strcasestr(t, "usage"))) {
if (usage_contains_reload(t)) {
(state == NORMAL && strcasestr(l, "usage"))) {
if (usage_contains_reload(l)) {
supports_reload = true;
state = NORMAL;
} else if (t[strlen(t)-1] == '\\')
} else if (endswith(l, "\\"))
state = USAGE_CONTINUATION;
else
state = NORMAL;
@ -479,18 +477,18 @@ static int load_sysv(SysvStub *s) {
continue;
}
if (state == NORMAL && streq(t, "### BEGIN INIT INFO")) {
if (state == NORMAL && streq(l, "### BEGIN INIT INFO")) {
state = LSB;
s->has_lsb = true;
continue;
}
if (IN_SET(state, LSB_DESCRIPTION, LSB) && streq(t, "### END INIT INFO")) {
if (IN_SET(state, LSB_DESCRIPTION, LSB) && streq(l, "### END INIT INFO")) {
state = NORMAL;
continue;
}
t++;
char *t = l + 1;
t += strspn(t, WHITESPACE);
if (state == NORMAL) {

View file

@ -211,9 +211,8 @@ static int context_parse_ntp_services_from_disk(Context *c) {
for (;;) {
_cleanup_free_ char *line = NULL;
const char *word;
r = read_line(file, LINE_MAX, &line);
r = read_stripped_line(file, LINE_MAX, &line);
if (r < 0) {
log_error_errno(r, "Failed to read %s, ignoring: %m", *f);
continue;
@ -221,13 +220,12 @@ static int context_parse_ntp_services_from_disk(Context *c) {
if (r == 0)
break;
word = strstrip(line);
if (isempty(word) || startswith(word, "#"))
if (isempty(line) || startswith(line, "#"))
continue;
r = context_add_ntp_service(c, word, *f);
r = context_add_ntp_service(c, line, *f);
if (r < 0)
log_warning_errno(r, "Failed to add NTP service \"%s\", ignoring: %m", word);
log_warning_errno(r, "Failed to add NTP service \"%s\", ignoring: %m", line);
}
}

View file

@ -4203,10 +4203,9 @@ static int read_config_file(
for (;;) {
_cleanup_free_ char *line = NULL;
bool invalid_line = false;
char *l;
int k;
k = read_line(f, LONG_LINE_MAX, &line);
k = read_stripped_line(f, LONG_LINE_MAX, &line);
if (k < 0)
return log_error_errno(k, "Failed to read '%s': %m", fn);
if (k == 0)
@ -4214,11 +4213,10 @@ static int read_config_file(
v++;
l = strstrip(line);
if (IN_SET(*l, 0, '#'))
if (IN_SET(line[0], 0, '#'))
continue;
k = parse_line(c, fn, v, l, &invalid_line, &uid_cache, &gid_cache);
k = parse_line(c, fn, v, line, &invalid_line, &uid_cache, &gid_cache);
if (k < 0) {
if (invalid_line)
/* Allow reporting with a special code if the caller requested this */

View file

@ -453,9 +453,9 @@ static int add_veritytab_devices(void) {
for (;;) {
_cleanup_free_ char *line = NULL, *name = NULL, *data_device = NULL, *hash_device = NULL,
*roothash = NULL, *options = NULL;
char *l, *data_uuid, *hash_uuid;
char *data_uuid, *hash_uuid;
r = read_line(f, LONG_LINE_MAX, &line);
r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return log_error_errno(r, "Failed to read %s: %m", arg_veritytab);
if (r == 0)
@ -463,11 +463,10 @@ static int add_veritytab_devices(void) {
veritytab_line++;
l = strstrip(line);
if (IN_SET(l[0], 0, '#'))
if (IN_SET(line[0], 0, '#'))
continue;
r = sscanf(l, "%ms %ms %ms %ms %ms", &name, &data_device, &hash_device, &roothash, &options);
r = sscanf(line, "%ms %ms %ms %ms %ms", &name, &data_device, &hash_device, &roothash, &options);
if (!IN_SET(r, 4, 5)) {
log_error("Failed to parse %s:%u, ignoring.", arg_veritytab, veritytab_line);
continue;