tree-wide: port various parsers over to read_stripped_line()
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user