1
0
mirror of https://github.com/systemd/systemd synced 2026-04-26 17:04:50 +02:00

Compare commits

..

5 Commits

Author SHA1 Message Date
Yu Watanabe
31090c17f4
Merge pull request #23321 from poettering/sockaddr-no-cast
tests: avoid sockaddr casts
2022-05-09 23:44:01 +09:00
Yu Watanabe
d171e72e7a core/slice: make slice_freezer_action() return 0 if freezing state is unchanged
Fixes #23278.
2022-05-09 23:43:32 +09:00
Luca Boccassi
37b7eef35d mkosi: add shadow package to SUSE Tumbleweed
[1958/1958] Generating export-dbus-interfaces with a custom command
/root/mkosi.build: line 70: groupadd: command not found
2022-05-09 14:58:06 +01:00
Lennart Poettering
3bf175f076 tests: avoid (struct sockaddr*) casts
We prefer using using union sockaddr_union instead of casting sockaddr
to the correct types.

Coding style, nothing else.

Follow-up for 0dd5ec58faa329410f1f363769209e95b058b7c3.
2022-05-09 13:56:39 +02:00
Lennart Poettering
b501e42e71 socket-util: don't reference field by macro parameter name
Let's avoid ambigituies here. (Interesting that the current users
compiled at all, in fact)
2022-05-09 13:55:28 +02:00
6 changed files with 26 additions and 25 deletions

View File

@ -39,6 +39,7 @@ BuildPackages=
python3-Jinja2
python3-lxml
qrencode-devel
shadow
system-user-nobody
systemd-sysvinit
zlib-devel

View File

@ -224,9 +224,9 @@ struct cmsghdr* cmsg_find(struct msghdr *mh, int level, int type, socklen_t leng
strnlen(_sa->sun_path, sizeof(_sa->sun_path))+1); \
})
#define SOCKADDR_LEN(sa) \
#define SOCKADDR_LEN(saddr) \
({ \
const union sockaddr_union *__sa = &(sa); \
const union sockaddr_union *__sa = &(saddr); \
size_t _len; \
switch (__sa->sa.sa_family) { \
case AF_INET: \

View File

@ -389,11 +389,7 @@ static int slice_freezer_action(Unit *s, FreezerAction action) {
return r;
}
r = unit_cgroup_freezer_action(s, action);
if (r < 0)
return r;
return 1;
return unit_cgroup_freezer_action(s, action);
}
static int slice_freeze(Unit *s) {

View File

@ -5849,6 +5849,8 @@ static int unit_freezer_action(Unit *u, FreezerAction action) {
if (r <= 0)
return r;
assert(IN_SET(u->freezer_state, FREEZER_FREEZING, FREEZER_THAWING));
return 1;
}

View File

@ -2,6 +2,7 @@
#include <arpa/inet.h>
#include <errno.h>
#include <net/if_arp.h>
#include <netinet/in.h>
#include <resolv.h>
#include <stdio.h>
@ -58,12 +59,12 @@ int main(int argc, char *argv[]) {
struct addrinfo hints = {
.ai_family = AF_UNSPEC,
.ai_socktype = SOCK_STREAM,
.ai_flags = AI_CANONNAME
.ai_flags = AI_CANONNAME,
};
struct sockaddr_in sa = {
.sin_family = AF_INET,
.sin_port = htobe16(80)
union sockaddr_union sa = {
.in.sin_family = AF_INET,
.in.sin_port = htobe16(80),
};
assert_se(sd_resolve_default(&resolve) >= 0);
@ -79,8 +80,8 @@ int main(int argc, char *argv[]) {
log_error_errno(r, "sd_resolve_getaddrinfo(): %m");
/* Make an address -> name query */
sa.sin_addr.s_addr = inet_addr(argc >= 3 ? argv[2] : "193.99.144.71");
r = sd_resolve_getnameinfo(resolve, &q2, (struct sockaddr*) &sa, sizeof(sa), 0, SD_RESOLVE_GET_BOTH, getnameinfo_handler, NULL);
sa.in.sin_addr.s_addr = inet_addr(argc >= 3 ? argv[2] : "193.99.144.71");
r = sd_resolve_getnameinfo(resolve, &q2, &sa.sa, SOCKADDR_LEN(sa), 0, SD_RESOLVE_GET_BOTH, getnameinfo_handler, NULL);
if (r < 0)
log_error_errno(r, "sd_resolve_getnameinfo(): %m");

View File

@ -3,6 +3,7 @@
#include <arpa/inet.h>
#include <fcntl.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <pthread.h>
#include <signal.h>
#include <stdlib.h>
@ -31,7 +32,7 @@
#include "sparse-endian.h"
#include "tests.h"
static struct sockaddr_in SERVER_ADDRESS;
static union sockaddr_union server_address;
/* Bytes of the questions & answers used in the test, including TCP DNS 2-byte length prefix */
static const uint8_t QUESTION_A[] = {
@ -110,7 +111,7 @@ static void *tcp_dns_server(void *p) {
assert_se((bindfd = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0)) >= 0);
assert_se(setsockopt(bindfd, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int)) >= 0);
assert_se(bind(bindfd, (struct sockaddr*)&SERVER_ADDRESS, sizeof(SERVER_ADDRESS)) >= 0);
assert_se(bind(bindfd, &server_address.sa, SOCKADDR_LEN(server_address)) >= 0);
assert_se(listen(bindfd, 1) >= 0);
assert_se((acceptfd = accept(bindfd, NULL, NULL)) >= 0);
server_handle(acceptfd);
@ -131,10 +132,10 @@ static void *tls_dns_server(void *p) {
assert_se(get_testdata_dir("test-resolve/selfsigned.cert", &cert_path) >= 0);
assert_se(get_testdata_dir("test-resolve/selfsigned.key", &key_path) >= 0);
assert_se(in_addr_to_string(SERVER_ADDRESS.sin_family,
&(union in_addr_union){.in = SERVER_ADDRESS.sin_addr},
assert_se(in_addr_to_string(server_address.in.sin_family,
sockaddr_in_addr(&server_address.sa),
&ip_str) >= 0);
assert_se(asprintf(&bind_str, "%s:%d", ip_str, be16toh(SERVER_ADDRESS.sin_port)) >= 0);
assert_se(asprintf(&bind_str, "%s:%d", ip_str, be16toh(server_address.in.sin_port)) >= 0);
/* We will hook one of the socketpair ends to OpenSSL's TLS server
* stdin/stdout, so we will be able to read and write plaintext
@ -247,7 +248,7 @@ static void test_dns_stream(bool tls) {
assert_se((clientfd = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0)) >= 0);
for (int i = 0; i < 100; i++) {
r = connect(clientfd, (struct sockaddr*)&SERVER_ADDRESS, sizeof(SERVER_ADDRESS));
r = connect(clientfd, &server_address.sa, SOCKADDR_LEN(server_address));
if (r >= 0)
break;
usleep(EVENT_TIMEOUT_USEC / 100);
@ -266,8 +267,8 @@ static void test_dns_stream(bool tls) {
if (tls) {
DnsServer server = {
.manager = &manager,
.family = SERVER_ADDRESS.sin_family,
.address.in = SERVER_ADDRESS.sin_addr
.family = server_address.sa.sa_family,
.address = *sockaddr_in_addr(&server_address.sa),
};
assert_se(dnstls_manager_init(&manager) >= 0);
@ -373,10 +374,10 @@ static void try_isolate_network(void) {
}
int main(int argc, char **argv) {
SERVER_ADDRESS = (struct sockaddr_in) {
.sin_family = AF_INET,
.sin_port = htobe16(12345),
.sin_addr.s_addr = htobe32(INADDR_LOOPBACK)
server_address = (union sockaddr_union) {
.in.sin_family = AF_INET,
.in.sin_port = htobe16(12345),
.in.sin_addr.s_addr = htobe32(INADDR_LOOPBACK)
};
test_setup_logging(LOG_DEBUG);