manager: port user lookup fd serialization to serialize_fd_many()

This commit is contained in:
Lennart Poettering 2024-04-23 21:41:42 +02:00
parent c3ab362dad
commit f6519d47a7

View File

@ -143,17 +143,9 @@ int manager_serialize(
}
if (m->user_lookup_fds[0] >= 0) {
int copy0, copy1;
copy0 = fdset_put_dup(fds, m->user_lookup_fds[0]);
if (copy0 < 0)
return log_error_errno(copy0, "Failed to add user lookup fd to serialization: %m");
copy1 = fdset_put_dup(fds, m->user_lookup_fds[1]);
if (copy1 < 0)
return log_error_errno(copy1, "Failed to add user lookup fd to serialization: %m");
(void) serialize_item_format(f, "user-lookup", "%i %i", copy0, copy1);
r = serialize_fd_many(f, fds, "user-lookup", m->user_lookup_fds, 2);
if (r < 0)
return r;
}
(void) serialize_ratelimit(f, "dump-ratelimit", &m->dump_ratelimit);
@ -478,16 +470,13 @@ int manager_deserialize(Manager *m, FILE *f, FDSet *fds) {
}
} else if ((val = startswith(l, "user-lookup="))) {
int fd0, fd1;
if (sscanf(val, "%i %i", &fd0, &fd1) != 2 || fd0 < 0 || fd1 < 0 || fd0 == fd1 || !fdset_contains(fds, fd0) || !fdset_contains(fds, fd1))
log_notice("Failed to parse user lookup fd, ignoring: %s", val);
else {
m->user_lookup_event_source = sd_event_source_disable_unref(m->user_lookup_event_source);
safe_close_pair(m->user_lookup_fds);
m->user_lookup_fds[0] = fdset_remove(fds, fd0);
m->user_lookup_fds[1] = fdset_remove(fds, fd1);
}
m->user_lookup_event_source = sd_event_source_disable_unref(m->user_lookup_event_source);
safe_close_pair(m->user_lookup_fds);
r = deserialize_fd_many(fds, val, 2, m->user_lookup_fds);
if (r < 0)
log_warning_errno(r, "Failed to parse user-lookup fds: \"%s\", ignoring: %m", val);
} else if ((val = startswith(l, "dynamic-user=")))
dynamic_user_deserialize_one(m, val, fds, NULL);