core/service: serialize and deserialize accept_socket
This fixes an issue during reexec — the count of connections would be lost: [zbyszek@fedora-rawhide ~]$ systemctl status testlimit.socket | grep Connected Accepted: 1; Connected: 1 [zbyszek@fedora-rawhide ~]$ sudo systemctl daemon-reexec [zbyszek@fedora-rawhide ~]$ systemctl status testlimit.socket | grep Connected Accepted: 1; Connected: 0 With the patch, Connected count is preserved. Also add "Accept Socket" to the dump output for services.
This commit is contained in:
@@ -761,6 +761,11 @@ static void service_dump(Unit *u, FILE *f, const char *prefix) {
|
||||
prefix, s->bus_name,
|
||||
prefix, yes_no(s->bus_name_good));
|
||||
|
||||
if (UNIT_ISSET(s->accept_socket))
|
||||
fprintf(f,
|
||||
"%sAccept Socket: %s\n",
|
||||
prefix, UNIT_DEREF(s->accept_socket)->id);
|
||||
|
||||
kill_context_dump(&s->kill_context, f, prefix);
|
||||
exec_context_dump(&s->exec_context, f, prefix);
|
||||
|
||||
@@ -2130,6 +2135,12 @@ static int service_serialize(Unit *u, FILE *f, FDSet *fds) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (UNIT_ISSET(s->accept_socket)) {
|
||||
r = unit_serialize_item(u, f, "accept-socket", UNIT_DEREF(s->accept_socket)->id);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
r = unit_serialize_item_fd(u, f, fds, "socket-fd", s->socket_fd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@@ -2260,6 +2271,17 @@ static int service_deserialize_item(Unit *u, const char *key, const char *value,
|
||||
s->control_command_id = id;
|
||||
s->control_command = s->exec_command[id];
|
||||
}
|
||||
} else if (streq(key, "accept-socket")) {
|
||||
Unit *socket;
|
||||
|
||||
r = manager_load_unit(u->manager, value, NULL, NULL, &socket);
|
||||
if (r < 0)
|
||||
log_unit_debug_errno(u, r, "Failed to load accept-socket unit: %s", value);
|
||||
else {
|
||||
unit_ref_set(&s->accept_socket, socket);
|
||||
SOCKET(socket)->n_connections++;
|
||||
}
|
||||
|
||||
} else if (streq(key, "socket-fd")) {
|
||||
int fd;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user