Skip to content

Commit 00463fb

Browse files
committed
load-fragment: make SocketProtocol= accept the empty string
1 parent fa65c28 commit 00463fb

File tree

3 files changed

+16
-31
lines changed

3 files changed

+16
-31
lines changed

src/core/dbus-socket.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ static inline bool check_size_t_truncation(uint64_t t) {
142142
return (size_t) t == t;
143143
}
144144

145-
static inline const char* socket_protocol_to_name_supported(int32_t i) {
145+
static inline const char* supported_socket_protocol_to_string(int32_t i) {
146+
if (i == IPPROTO_IP)
147+
return "";
148+
146149
if (!IN_SET(i, IPPROTO_UDPLITE, IPPROTO_SCTP))
147150
return NULL;
148151

@@ -156,7 +159,7 @@ static BUS_DEFINE_SET_TRANSIENT_PARSE(bind_ipv6_only, SocketAddressBindIPv6Only,
156159
static BUS_DEFINE_SET_TRANSIENT_STRING_WITH_CHECK(fdname, fdname_is_valid);
157160
static BUS_DEFINE_SET_TRANSIENT_STRING_WITH_CHECK(ifname, ifname_valid);
158161
static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(ip_tos, "i", int32_t, int, "%" PRIi32, ip_tos_to_string_alloc);
159-
static BUS_DEFINE_SET_TRANSIENT_TO_STRING(socket_protocol, "i", int32_t, int, "%" PRIi32, socket_protocol_to_name_supported);
162+
static BUS_DEFINE_SET_TRANSIENT_TO_STRING(socket_protocol, "i", int32_t, int, "%" PRIi32, supported_socket_protocol_to_string);
160163

161164
static int bus_socket_set_transient_property(
162165
Socket *s,

src/core/load-fragment-gperf.gperf.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ Socket.ListenNetlink, config_parse_socket_listen, SOCKET_SOCK
330330
Socket.ListenSpecial, config_parse_socket_listen, SOCKET_SPECIAL, 0
331331
Socket.ListenMessageQueue, config_parse_socket_listen, SOCKET_MQUEUE, 0
332332
Socket.ListenUSBFunction, config_parse_socket_listen, SOCKET_USB_FUNCTION, 0
333-
Socket.SocketProtocol, config_parse_socket_protocol, 0, 0
333+
Socket.SocketProtocol, config_parse_socket_protocol, 0, offsetof(Socket, socket_protocol)
334334
Socket.BindIPv6Only, config_parse_socket_bind, 0, offsetof(Socket, bind_ipv6_only)
335335
Socket.Backlog, config_parse_unsigned, 0, offsetof(Socket, backlog)
336336
Socket.BindToDevice, config_parse_socket_bindtodevice, 0, 0

src/core/load-fragment.c

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -404,40 +404,22 @@ int config_parse_socket_listen(const char *unit,
404404
return 0;
405405
}
406406

407-
int config_parse_socket_protocol(const char *unit,
408-
const char *filename,
409-
unsigned line,
410-
const char *section,
411-
unsigned section_line,
412-
const char *lvalue,
413-
int ltype,
414-
const char *rvalue,
415-
void *data,
416-
void *userdata) {
417-
Socket *s;
407+
static int supported_socket_protocol_from_string(const char *s) {
418408
int r;
419409

420-
assert(filename);
421-
assert(lvalue);
422-
assert(rvalue);
423-
assert(data);
424-
425-
s = SOCKET(data);
426-
427-
r = socket_protocol_from_name(rvalue);
428-
if (r < 0) {
429-
log_syntax(unit, LOG_ERR, filename, line, r, "Invalid socket protocol '%s', ignoring: %m", rvalue);
430-
return 0;
431-
} else if (!IN_SET(r, IPPROTO_UDPLITE, IPPROTO_SCTP)) {
432-
log_syntax(unit, LOG_ERR, filename, line, 0, "Socket protocol not supported, ignoring: %s", rvalue);
433-
return 0;
434-
}
410+
if (isempty(s))
411+
return IPPROTO_IP;
435412

436-
s->socket_protocol = r;
413+
r = socket_protocol_from_name(s);
414+
if (r < 0)
415+
return -EINVAL;
416+
if (!IN_SET(r, IPPROTO_UDPLITE, IPPROTO_SCTP))
417+
return -EPROTONOSUPPORT;
437418

438-
return 0;
419+
return r;
439420
}
440421

422+
DEFINE_CONFIG_PARSE(config_parse_socket_protocol, supported_socket_protocol_from_string, "Failed to parse socket protocol");
441423
DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind, socket_address_bind_ipv6_only_or_bool, SocketAddressBindIPv6Only, "Failed to parse bind IPv6 only value");
442424

443425
int config_parse_exec_nice(

0 commit comments

Comments
 (0)