summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-09-08 17:02:11 +0200
committerLuca Boccassi <luca.boccassi@gmail.com>2023-09-08 21:59:44 +0200
commit0df7d525763ce76269c414d9c0a9ee9978edf299 (patch)
tree1f75d063077ba0dca01a637404b017d921cb9254 /src/core
parentconf-parser: parse main config first only if not symlinked to/as drop-in (diff)
downloadsystemd-0df7d525763ce76269c414d9c0a9ee9978edf299.tar.xz
systemd-0df7d525763ce76269c414d9c0a9ee9978edf299.zip
serialize: add common deserialize_read_line() helper and use it everywhere
This introduces a common helper replacing three very similar uses. Prompted by review of: #27890
Diffstat (limited to 'src/core')
-rw-r--r--src/core/job.c20
-rw-r--r--src/core/manager-serialize.c14
-rw-r--r--src/core/unit-serialize.c14
3 files changed, 18 insertions, 30 deletions
diff --git a/src/core/job.c b/src/core/job.c
index acf8a78f41..e7d1f65dbc 100644
--- a/src/core/job.c
+++ b/src/core/job.c
@@ -1233,21 +1233,15 @@ int job_deserialize(Job *j, FILE *f) {
assert(f);
for (;;) {
- _cleanup_free_ char *line = NULL;
- char *l, *v;
+ _cleanup_free_ char *l = NULL;
size_t k;
+ char *v;
- r = read_line(f, LONG_LINE_MAX, &line);
+ r = deserialize_read_line(f, &l);
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))
- return 0;
+ return r;
+ if (r == 0) /* eof or end marker */
+ break;
k = strcspn(l, "=");
@@ -1326,6 +1320,8 @@ int job_deserialize(Job *j, FILE *f) {
} else
log_debug("Unknown job serialization key: %s", l);
}
+
+ return 0;
}
int job_coldplug(Job *j) {
diff --git a/src/core/manager-serialize.c b/src/core/manager-serialize.c
index f4ad9b0642..71234ae936 100644
--- a/src/core/manager-serialize.c
+++ b/src/core/manager-serialize.c
@@ -338,17 +338,13 @@ int manager_deserialize(Manager *m, FILE *f, FDSet *fds) {
_cleanup_(manager_reloading_stopp) _unused_ Manager *reloading = manager_reloading_start(m);
for (;;) {
- _cleanup_free_ char *line = NULL;
- const char *val, *l;
+ _cleanup_free_ char *l = NULL;
+ const char *val;
- r = read_line(f, LONG_LINE_MAX, &line);
+ r = deserialize_read_line(f, &l);
if (r < 0)
- return log_error_errno(r, "Failed to read serialization line: %m");
- if (r == 0)
- break;
-
- l = strstrip(line);
- if (isempty(l)) /* end marker */
+ return r;
+ if (r == 0) /* eof or end marker */
break;
if ((val = startswith(l, "current-job-id="))) {
diff --git a/src/core/unit-serialize.c b/src/core/unit-serialize.c
index cb209c5bde..f0030d3211 100644
--- a/src/core/unit-serialize.c
+++ b/src/core/unit-serialize.c
@@ -272,19 +272,15 @@ int unit_deserialize(Unit *u, FILE *f, FDSet *fds) {
assert(fds);
for (;;) {
- _cleanup_free_ char *line = NULL;
- char *l, *v;
+ _cleanup_free_ char *l = NULL;
ssize_t m;
size_t k;
+ char *v;
- r = read_line(f, LONG_LINE_MAX, &line);
+ r = deserialize_read_line(f, &l);
if (r < 0)
- return log_error_errno(r, "Failed to read serialization line: %m");
- if (r == 0) /* eof */
- break;
-
- l = strstrip(line);
- if (isempty(l)) /* End marker */
+ return r;
+ if (r == 0) /* eof or end marker */
break;
k = strcspn(l, "=");