]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: port various parsers over to read_stripped_line() 29586/head
authorLennart Poettering <lennart@poettering.net>
Mon, 16 Oct 2023 16:01:00 +0000 (18:01 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 17 Oct 2023 12:36:54 +0000 (14:36 +0200)
26 files changed:
src/basic/process-util.c
src/binfmt/binfmt.c
src/cgtop/cgtop.c
src/core/manager-serialize.c
src/core/unit-serialize.c
src/cryptsetup/cryptsetup-generator.c
src/getty-generator/getty-generator.c
src/integritysetup/integritysetup-generator.c
src/libsystemd/sd-path/sd-path.c
src/locale/localectl.c
src/locale/localed-util.c
src/modules-load/modules-load.c
src/network/networkd-dhcp-server.c
src/resolve/resolvconf-compat.c
src/resolve/resolved-dns-trust-anchor.c
src/resolve/resolved-resolv-conf.c
src/shared/bootspec.c
src/shared/hostname-setup.c
src/shared/install.c
src/shared/serialize.c
src/sysctl/sysctl.c
src/sysusers/sysusers.c
src/sysv-generator/sysv-generator.c
src/timedate/timedated.c
src/tmpfiles/tmpfiles.c
src/veritysetup/veritysetup-generator.c

index ed096900ac587fdd124118efa122728c1511bcc9..6e5152806544293d2a042bbd4b509af4ae874a79 100644 (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;
index 675ae185e2486ce57cef82844b020ab22b01c297..817d593c239c718f00911724947ef8c4d56b140d 100644 (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;
index 2e517a16362221f02950a48ae26f1ecbb35cb8e9..a6adb8ce314be7bb1d5abbdaacf777a1a21b4a00 100644 (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) {
index 04393cf11da75ee205050b513f17f7b05469f83a..09c49b6d6ca1331f0457752dc636467a46fbd1ed 100644 (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) {
index cd7f2ee86b64e9a2fe5f14505ad9a12fc55d1851..be041010312a47505d8631cf03b1240b763b20ec 100644 (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;
         }
 }
index 2caf15fa497b954a0920e72942bcd1a1fcc5ccff..904e4cd3fafaf9730e26f443954476e1f7cb2e9e 100644 (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;
index 4379b4b6480dadc32aec2ecc456a95500986fde4..7486118365f1b7814ccacacd5c7c148529024d1a 100644 (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;
                 }
index 05154908aea53767acd9cd628c2d569096eab09e..72b890575ce1dae554c3332249e1cd979bd1c73c 100644 (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;
                 }
 
index 33adc314d6ce1908b5f4ee2f8b7a9ad1046b7f12..7290d1c40a0e43c32d248cedc27e5c2d8b6dd106 100644 (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 != '=')
index d8db9d9d22acc13bd2b2900c00d2322f681cb2bf..32354027f1755ef6d445b44fbc716f35fbf2e598 100644 (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();
         }
 
index 9b6949e14dc959727d58a70b59dfe542ceebbc00..d78b878cf9580469aec0d8fc413a304aab7840f6 100644 (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;
         }
 }
index 4adeef3afbddcf974a490219a40a60ab6375007b..efca2379eac71e5850cfaa897e6fd166e55048c8 100644 (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);
index 569398571c02796a36e90705be0dcddcaf0e774c..17939ce54ac8c0e68c5651619dbb3d2454190f2f 100644 (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;
 
index 3804d3dde3b7e41ef7bab1dd105793d18922b4c1..bef95c0bb64313f81314850c9505c47e1dc38639 100644 (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) {
index d626638c01034c4f102ef42689bc04744c6242a6..1703c43d4b0ab0d906b0a4011108886fbdbfa9ad 100644 (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);
                 }
         }
 
index 1da0ac899552601c1d5c8377592ef8ed428a5f56..2071e0810cccbac6ad5698727810ec183e4dfcd5 100644 (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;
index f347ccdd8a86b691b44152af6691b9b0dc82dd1f..746ae743cd234d5215c56f07bdab11c0c2756474 100644 (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");
index a3b2a913b1e126879cfe15122340e681385b8f98..137c29aef5c44e3565dd875632b2caacd5ec6abb 100644 (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;
-
-                        hostname_cleanup(p); /* normalize the hostname */
+                if (IN_SET(line[0], '\0', '#'))
+                        continue;
 
-                        if (!hostname_is_valid(p, VALID_HOSTNAME_TRAILING_DOT)) /* check that the hostname we return is valid */
-                                return -EBADMSG;
+                hostname_cleanup(line); /* normalize the hostname */
 
-                        copy = strdup(p);
-                        if (!copy)
-                                return -ENOMEM;
+                if (!hostname_is_valid(line, VALID_HOSTNAME_TRAILING_DOT)) /* check that the hostname we return is valid */
+                        return -EBADMSG;
 
-                        *ret = copy;
-                        return 0;
-                }
+                *ret = TAKE_PTR(line);
+                return 0;
         }
 }
 
index 8b0705eb9ef1d79c650e5ad387fed0953ba916ea..0f4dab4aa27651358316a859bfc081a4f7b3d714 100644 (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;
 
index edb232e2eef58c3d4341109e6577f08f9c54ebde..ee35055aeaeb02460030768b7302478c34dbdf7d 100644 (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;
 }
index ca41f02fdd53cc400b73719090b7633c244945b0..3e1f79887dbb83a72f7536ceb03e12b16f14070a 100644 (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] == '-') {
index 0fcbf261c115744060d73aa167cead6ac01ca459..c0deae11655db16fa5f411e2118b70bfbfc55560 100644 (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;
         }
index 30f82d573699d3ed4902ede2ea0024f39d82d3f9..4485e2e3680ec9cc1eda27ec20576209b7f07bb6 100644 (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) {
index 6406d6fefd5370251a10c43f4a8485bf1021d6dd..c7be30f563f9c1f98924cc2438a44d7c66bfeda5 100644 (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);
                 }
         }
 
index aab65f49d12733f76d305039e33183a5a1411066..93ac53792f59fd8604db20ac6361c22f6c41a302 100644 (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 */
index 59ff4cd7a52741bd1c793ee7738a5bb5b6ed6c11..d55d4aab0b5ff4bcebccd7cbbc194a37d2da8419 100644 (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;