core/load-fragment: modernize config_parse_socket_listen

Prompted by #31304
This commit is contained in:
Mike Yuan
2024-02-14 03:35:37 +08:00
committed by Lennart Poettering
parent 64e18af731
commit 872ffc8a82

View File

@@ -434,8 +434,9 @@ int config_parse_colon_separated_paths(
const char *rvalue,
void *data,
void *userdata) {
char ***sv = ASSERT_PTR(data);
const Unit *u = userdata;
const Unit *u = ASSERT_PTR(userdata);
int r;
assert(filename);
@@ -575,17 +576,13 @@ int config_parse_socket_listen(
void *data,
void *userdata) {
Socket *s = ASSERT_PTR(SOCKET(data));
_cleanup_free_ SocketPort *p = NULL;
SocketPort *tail;
Socket *s;
int r;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(data);
s = SOCKET(data);
if (isempty(rvalue)) {
/* An empty assignment removes all ports */
@@ -593,10 +590,15 @@ int config_parse_socket_listen(
return 0;
}
p = new0(SocketPort, 1);
p = new(SocketPort, 1);
if (!p)
return log_oom();
*p = (SocketPort) {
.socket = s,
.fd = -EBADF,
};
if (ltype != SOCKET_SOCKET) {
_cleanup_free_ char *k = NULL;
@@ -624,7 +626,7 @@ int config_parse_socket_listen(
p->type = ltype;
} else if (streq(lvalue, "ListenNetlink")) {
_cleanup_free_ char *k = NULL;
_cleanup_free_ char *k = NULL;
r = unit_path_printf(UNIT(s), rvalue, &k);
if (r < 0) {
@@ -649,7 +651,7 @@ int config_parse_socket_listen(
return 0;
}
if (k[0] == '/') { /* Only for AF_UNIX file system sockets… */
if (path_is_absolute(k)) { /* Only for AF_UNIX file system sockets… */
r = patch_var_run(unit, filename, line, lvalue, &k);
if (r < 0)
return r;
@@ -679,16 +681,7 @@ int config_parse_socket_listen(
p->type = SOCKET_SOCKET;
}
p->fd = -EBADF;
p->auxiliary_fds = NULL;
p->n_auxiliary_fds = 0;
p->socket = s;
tail = LIST_FIND_TAIL(port, s->ports);
LIST_INSERT_AFTER(port, s->ports, tail, p);
p = NULL;
LIST_APPEND(port, s->ports, TAKE_PTR(p));
return 0;
}