load-fragment: make SocketProtocol= accept the empty string

This commit is contained in:
Yu Watanabe
2018-05-29 12:49:47 +09:00
parent fa65c28176
commit 00463fbf0d
3 changed files with 16 additions and 31 deletions

View File

@@ -142,7 +142,10 @@ static inline bool check_size_t_truncation(uint64_t t) {
return (size_t) t == t;
}
static inline const char* socket_protocol_to_name_supported(int32_t i) {
static inline const char* supported_socket_protocol_to_string(int32_t i) {
if (i == IPPROTO_IP)
return "";
if (!IN_SET(i, IPPROTO_UDPLITE, IPPROTO_SCTP))
return NULL;
@@ -156,7 +159,7 @@ static BUS_DEFINE_SET_TRANSIENT_PARSE(bind_ipv6_only, SocketAddressBindIPv6Only,
static BUS_DEFINE_SET_TRANSIENT_STRING_WITH_CHECK(fdname, fdname_is_valid);
static BUS_DEFINE_SET_TRANSIENT_STRING_WITH_CHECK(ifname, ifname_valid);
static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(ip_tos, "i", int32_t, int, "%" PRIi32, ip_tos_to_string_alloc);
static BUS_DEFINE_SET_TRANSIENT_TO_STRING(socket_protocol, "i", int32_t, int, "%" PRIi32, socket_protocol_to_name_supported);
static BUS_DEFINE_SET_TRANSIENT_TO_STRING(socket_protocol, "i", int32_t, int, "%" PRIi32, supported_socket_protocol_to_string);
static int bus_socket_set_transient_property(
Socket *s,

View File

@@ -330,7 +330,7 @@ Socket.ListenNetlink, config_parse_socket_listen, SOCKET_SOCK
Socket.ListenSpecial, config_parse_socket_listen, SOCKET_SPECIAL, 0
Socket.ListenMessageQueue, config_parse_socket_listen, SOCKET_MQUEUE, 0
Socket.ListenUSBFunction, config_parse_socket_listen, SOCKET_USB_FUNCTION, 0
Socket.SocketProtocol, config_parse_socket_protocol, 0, 0
Socket.SocketProtocol, config_parse_socket_protocol, 0, offsetof(Socket, socket_protocol)
Socket.BindIPv6Only, config_parse_socket_bind, 0, offsetof(Socket, bind_ipv6_only)
Socket.Backlog, config_parse_unsigned, 0, offsetof(Socket, backlog)
Socket.BindToDevice, config_parse_socket_bindtodevice, 0, 0

View File

@@ -404,40 +404,22 @@ int config_parse_socket_listen(const char *unit,
return 0;
}
int config_parse_socket_protocol(const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
Socket *s;
static int supported_socket_protocol_from_string(const char *s) {
int r;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(data);
if (isempty(s))
return IPPROTO_IP;
s = SOCKET(data);
r = socket_protocol_from_name(s);
if (r < 0)
return -EINVAL;
if (!IN_SET(r, IPPROTO_UDPLITE, IPPROTO_SCTP))
return -EPROTONOSUPPORT;
r = socket_protocol_from_name(rvalue);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r, "Invalid socket protocol '%s', ignoring: %m", rvalue);
return 0;
} else if (!IN_SET(r, IPPROTO_UDPLITE, IPPROTO_SCTP)) {
log_syntax(unit, LOG_ERR, filename, line, 0, "Socket protocol not supported, ignoring: %s", rvalue);
return 0;
}
s->socket_protocol = r;
return 0;
return r;
}
DEFINE_CONFIG_PARSE(config_parse_socket_protocol, supported_socket_protocol_from_string, "Failed to parse socket protocol");
DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind, socket_address_bind_ipv6_only_or_bool, SocketAddressBindIPv6Only, "Failed to parse bind IPv6 only value");
int config_parse_exec_nice(