Compare commits

...

5 Commits

Author SHA1 Message Date
fangxiuning 6d95e7d9b2
tree-wide: drop pointless zero initialization (#16900) 2020-08-30 06:21:20 +09:00
Fabrice Fontaine 28e2641a1a
src/shared/dissect-image.c: fix build without blkdid (#16901)
N_DEVICE_NODE_LIST_ATTEMPTS is unconditionally used since version 246 and
ac1f3ad05f

However, this variable is only defined if HAVE_BLKID is set resulting in
the following build failure if cryptsetup is enabled but not libblkid:

../src/shared/dissect-image.c:1336:34: error: 'N_DEVICE_NODE_LIST_ATTEMPTS' undeclared (first use in this function)
 1336 |         for (unsigned i = 0; i < N_DEVICE_NODE_LIST_ATTEMPTS; i++) {
      |

Fixes:
 - http://autobuild.buildroot.org/results/67782c225c08387c1bbcbea9eee3ca12bc6577cd
2020-08-30 06:17:18 +09:00
Michael Biebl 9654645b62
Merge pull request #16850 from mbiebl/networkd-socket-activation
networkd: use socket activation when starting networkd
2020-08-29 16:12:46 +02:00
Michael Biebl 3aa645f0c0 test-network: stop networkd and its socket
With the changes from 2c0dffe82d, starting
systemd-networkd.service will also activate systemd-networkd.socket.
When tearing down a test, we need to stop the socket as well, to make
sure networkd can't be activated accidentally with the wrong
configuration.
2020-08-28 21:03:09 +02:00
Michael Biebl 2c0dffe82d networkd: use socket activation when starting networkd
Add After=systemd-networkd.socket to avoid a race condition and networkd
falling back to the non-socket activation code.

Also add Wants=systemd-networkd.socket, so the socket is started when
networkd is started via `systemctl start systemd-networkd.service`.
A Requires is not strictly necessary, as networkd still ships the
non-socket activation code. Should this code be removed one day, the
Wants should be bumped to Requires accordingly.

See also 5544ee8516.

Fixes: #16809
2020-08-26 16:54:45 +02:00
14 changed files with 36 additions and 28 deletions

View File

@ -1695,7 +1695,7 @@ int sd_dhcp6_client_is_running(sd_dhcp6_client *client) {
int sd_dhcp6_client_start(sd_dhcp6_client *client) { int sd_dhcp6_client_start(sd_dhcp6_client *client) {
enum DHCP6State state = DHCP6_STATE_SOLICITATION; enum DHCP6State state = DHCP6_STATE_SOLICITATION;
int r = 0; int r;
assert_return(client, -EINVAL); assert_return(client, -EINVAL);
assert_return(client->event, -EINVAL); assert_return(client->event, -EINVAL);

View File

@ -477,7 +477,7 @@ static int import_file(struct trie *trie, const char *filename, uint16_t file_pr
_cleanup_fclose_ FILE *f = NULL; _cleanup_fclose_ FILE *f = NULL;
_cleanup_strv_free_ char **match_list = NULL; _cleanup_strv_free_ char **match_list = NULL;
uint32_t line_number = 0; uint32_t line_number = 0;
int r = 0, err; int r, err;
f = fopen(filename, "re"); f = fopen(filename, "re");
if (!f) if (!f)

View File

@ -53,7 +53,7 @@ static int getnameinfo_handler(sd_resolve_query *q, int ret, const char *host, c
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
_cleanup_(sd_resolve_query_unrefp) sd_resolve_query *q1 = NULL, *q2 = NULL; _cleanup_(sd_resolve_query_unrefp) sd_resolve_query *q1 = NULL, *q2 = NULL;
_cleanup_(sd_resolve_unrefp) sd_resolve *resolve = NULL; _cleanup_(sd_resolve_unrefp) sd_resolve *resolve = NULL;
int r = 0; int r;
struct addrinfo hints = { struct addrinfo hints = {
.ai_family = PF_UNSPEC, .ai_family = PF_UNSPEC,

View File

@ -478,7 +478,7 @@ int config_parse_n_autovts(
static int vt_is_busy(unsigned vtnr) { static int vt_is_busy(unsigned vtnr) {
struct vt_stat vt_stat; struct vt_stat vt_stat;
int r = 0; int r;
_cleanup_close_ int fd; _cleanup_close_ int fd;
assert(vtnr >= 1); assert(vtnr >= 1);

View File

@ -202,7 +202,7 @@ static void session_save_devices(Session *s, FILE *f) {
int session_save(Session *s) { int session_save(Session *s) {
_cleanup_free_ char *temp_path = NULL; _cleanup_free_ char *temp_path = NULL;
_cleanup_fclose_ FILE *f = NULL; _cleanup_fclose_ FILE *f = NULL;
int r = 0; int r;
assert(s); assert(s);

View File

@ -136,7 +136,7 @@ static int manager_add_host_machine(Manager *m) {
static int manager_enumerate_machines(Manager *m) { static int manager_enumerate_machines(Manager *m) {
_cleanup_closedir_ DIR *d = NULL; _cleanup_closedir_ DIR *d = NULL;
struct dirent *de; struct dirent *de;
int r = 0; int r;
assert(m); assert(m);

View File

@ -84,7 +84,7 @@ static int context_save(Context *context) {
NetDev *netdev; NetDev *netdev;
Link *link; Link *link;
Iterator i; Iterator i;
int k, r = 0; int k, r;
const char *p; const char *p;
p = prefix_roota(arg_root, NETWORKD_UNIT_DIRECTORY); p = prefix_roota(arg_root, NETWORKD_UNIT_DIRECTORY);

View File

@ -54,6 +54,9 @@
#include "user-util.h" #include "user-util.h"
#include "xattr-util.h" #include "xattr-util.h"
/* how many times to wait for the device nodes to appear */
#define N_DEVICE_NODE_LIST_ATTEMPTS 10
int probe_filesystem(const char *node, char **ret_fstype) { int probe_filesystem(const char *node, char **ret_fstype) {
/* Try to find device content type and return it in *ret_fstype. If nothing is found, /* Try to find device content type and return it in *ret_fstype. If nothing is found,
* 0/NULL will be returned. -EUCLEAN will be returned for ambiguous results, and an * 0/NULL will be returned. -EUCLEAN will be returned for ambiguous results, and an
@ -154,9 +157,6 @@ static int enumerator_for_parent(sd_device *d, sd_device_enumerator **ret) {
return 0; return 0;
} }
/* how many times to wait for the device nodes to appear */
#define N_DEVICE_NODE_LIST_ATTEMPTS 10
static int wait_for_partitions_to_appear( static int wait_for_partitions_to_appear(
int fd, int fd,
sd_device *d, sd_device *d,

View File

@ -8,7 +8,7 @@ int module_load_and_warn(struct kmod_ctx *ctx, const char *module, bool verbose)
const int probe_flags = KMOD_PROBE_APPLY_BLACKLIST; const int probe_flags = KMOD_PROBE_APPLY_BLACKLIST;
struct kmod_list *itr; struct kmod_list *itr;
_cleanup_(kmod_module_unref_listp) struct kmod_list *modlist = NULL; _cleanup_(kmod_module_unref_listp) struct kmod_list *modlist = NULL;
int r = 0; int r;
/* verbose==true means we should log at non-debug level if we /* verbose==true means we should log at non-debug level if we
* fail to find or load the module. */ * fail to find or load the module. */

View File

@ -1941,7 +1941,7 @@ static int seccomp_restrict_sxid(scmp_filter_ctx seccomp, mode_t m) {
* *
* Returns error if *everything* failed, and 0 otherwise. * Returns error if *everything* failed, and 0 otherwise.
*/ */
int r = 0; int r;
bool any = false; bool any = false;
r = seccomp_rule_add_exact( r = seccomp_rule_add_exact(

View File

@ -1064,7 +1064,7 @@ static int list_sockets(int argc, char *argv[], void *userdata) {
struct socket_info *s; struct socket_info *s;
unsigned cs = 0; unsigned cs = 0;
size_t size = 0; size_t size = 0;
int r = 0, n; int r, n;
sd_bus *bus; sd_bus *bus;
r = acquire_bus(BUS_MANAGER, &bus); r = acquire_bus(BUS_MANAGER, &bus);
@ -1333,7 +1333,7 @@ static int list_timers(int argc, char *argv[], void *userdata) {
int n, c = 0; int n, c = 0;
dual_timestamp nw; dual_timestamp nw;
sd_bus *bus; sd_bus *bus;
int r = 0; int r;
r = acquire_bus(BUS_MANAGER, &bus); r = acquire_bus(BUS_MANAGER, &bus);
if (r < 0) if (r < 0)
@ -1731,7 +1731,7 @@ static int list_dependencies_one(
_cleanup_strv_free_ char **deps = NULL; _cleanup_strv_free_ char **deps = NULL;
char **c; char **c;
int r = 0; int r;
assert(bus); assert(bus);
assert(name); assert(name);
@ -2397,7 +2397,7 @@ static int list_jobs(int argc, char *argv[], void *userdata) {
static int cancel_job(int argc, char *argv[], void *userdata) { static int cancel_job(int argc, char *argv[], void *userdata) {
sd_bus *bus; sd_bus *bus;
char **name; char **name;
int r = 0; int r;
if (argc <= 1) if (argc <= 1)
return trivial_method(argc, argv, userdata); return trivial_method(argc, argv, userdata);
@ -6973,7 +6973,7 @@ static int add_dependency(int argc, char *argv[], void *userdata) {
UnitFileChange *changes = NULL; UnitFileChange *changes = NULL;
size_t n_changes = 0; size_t n_changes = 0;
UnitDependency dep; UnitDependency dep;
int r = 0; int r;
if (!argv[1]) if (!argv[1])
return 0; return 0;

View File

@ -223,7 +223,8 @@ Gateway=192.168.250.1''')
subprocess.check_call(['systemctl', 'start', 'systemd-networkd']) subprocess.check_call(['systemctl', 'start', 'systemd-networkd'])
def tearDown(self): def tearDown(self):
subprocess.check_call(['systemctl', 'stop', 'systemd-networkd']) subprocess.check_call(['systemctl', 'stop', 'systemd-networkd.socket'])
subprocess.check_call(['systemctl', 'stop', 'systemd-networkd.service'])
subprocess.check_call(['ip', 'link', 'del', 'mybridge']) subprocess.check_call(['ip', 'link', 'del', 'mybridge'])
subprocess.check_call(['ip', 'link', 'del', 'port1']) subprocess.check_call(['ip', 'link', 'del', 'port1'])
subprocess.check_call(['ip', 'link', 'del', 'port2']) subprocess.check_call(['ip', 'link', 'del', 'port2'])
@ -309,7 +310,8 @@ class ClientTestBase(NetworkdTestingUtilities):
def tearDown(self): def tearDown(self):
self.shutdown_iface() self.shutdown_iface()
subprocess.call(['systemctl', 'stop', 'systemd-networkd']) subprocess.call(['systemctl', 'stop', 'systemd-networkd.socket'])
subprocess.call(['systemctl', 'stop', 'systemd-networkd.service'])
subprocess.call(['ip', 'link', 'del', 'dummy0'], subprocess.call(['ip', 'link', 'del', 'dummy0'],
stderr=subprocess.DEVNULL) stderr=subprocess.DEVNULL)
@ -987,7 +989,8 @@ class MatchClientTest(unittest.TestCase, NetworkdTestingUtilities):
def tearDown(self): def tearDown(self):
"""Stop networkd.""" """Stop networkd."""
subprocess.call(['systemctl', 'stop', 'systemd-networkd']) subprocess.call(['systemctl', 'stop', 'systemd-networkd.socket'])
subprocess.call(['systemctl', 'stop', 'systemd-networkd.service'])
def test_basic_matching(self): def test_basic_matching(self):
"""Verify the Name= line works throughout this class.""" """Verify the Name= line works throughout this class."""
@ -1037,7 +1040,8 @@ class UnmanagedClientTest(unittest.TestCase, NetworkdTestingUtilities):
def tearDown(self): def tearDown(self):
"""Stop networkd.""" """Stop networkd."""
subprocess.call(['systemctl', 'stop', 'systemd-networkd']) subprocess.call(['systemctl', 'stop', 'systemd-networkd.socket'])
subprocess.call(['systemctl', 'stop', 'systemd-networkd.service'])
def create_iface(self): def create_iface(self):
"""Create temporary veth pairs for interface matching.""" """Create temporary veth pairs for interface matching."""

View File

@ -328,7 +328,7 @@ def tearDownModule():
shutil.rmtree(networkd_ci_path) shutil.rmtree(networkd_ci_path)
for u in ['systemd-networkd.service', 'systemd-resolved.service']: for u in ['systemd-networkd.socket', 'systemd-networkd.service', 'systemd-resolved.service']:
check_output(f'systemctl stop {u}') check_output(f'systemctl stop {u}')
shutil.rmtree('/run/systemd/system/systemd-networkd.service.d') shutil.rmtree('/run/systemd/system/systemd-networkd.service.d')
@ -464,7 +464,8 @@ def remove_networkd_state_files():
def stop_networkd(show_logs=True, remove_state_files=True): def stop_networkd(show_logs=True, remove_state_files=True):
if show_logs: if show_logs:
invocation_id = check_output('systemctl show systemd-networkd -p InvocationID --value') invocation_id = check_output('systemctl show systemd-networkd -p InvocationID --value')
check_output('systemctl stop systemd-networkd') check_output('systemctl stop systemd-networkd.socket')
check_output('systemctl stop systemd-networkd.service')
if show_logs: if show_logs:
print(check_output('journalctl _SYSTEMD_INVOCATION_ID=' + invocation_id)) print(check_output('journalctl _SYSTEMD_INVOCATION_ID=' + invocation_id))
if remove_state_files: if remove_state_files:
@ -2447,7 +2448,8 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
self.assertRegex(output, 'Search Domains: one') self.assertRegex(output, 'Search Domains: one')
def test_keep_configuration_static(self): def test_keep_configuration_static(self):
check_output('systemctl stop systemd-networkd') check_output('systemctl stop systemd-networkd.socket')
check_output('systemctl stop systemd-networkd.service')
check_output('ip link add name dummy98 type dummy') check_output('ip link add name dummy98 type dummy')
check_output('ip address add 10.1.2.3/16 dev dummy98') check_output('ip address add 10.1.2.3/16 dev dummy98')
@ -3610,7 +3612,8 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
print(output) print(output)
self.assertRegex(output, r'192.168.5.*') self.assertRegex(output, r'192.168.5.*')
check_output('systemctl stop systemd-networkd') check_output('systemctl stop systemd-networkd.socket')
check_output('systemctl stop systemd-networkd.service')
print('The lease address should be kept after networkd stopped') print('The lease address should be kept after networkd stopped')
output = check_output('ip address show dev veth99 scope global') output = check_output('ip address show dev veth99 scope global')
@ -3645,7 +3648,8 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
self.assertRegex(output, r'192.168.5.*') self.assertRegex(output, r'192.168.5.*')
stop_dnsmasq(dnsmasq_pid_file) stop_dnsmasq(dnsmasq_pid_file)
check_output('systemctl stop systemd-networkd') check_output('systemctl stop systemd-networkd.socket')
check_output('systemctl stop systemd-networkd.service')
output = check_output('ip address show dev veth99 scope global') output = check_output('ip address show dev veth99 scope global')
print(output) print(output)

View File

@ -13,10 +13,10 @@ Documentation=man:systemd-networkd.service(8)
ConditionCapability=CAP_NET_ADMIN ConditionCapability=CAP_NET_ADMIN
DefaultDependencies=no DefaultDependencies=no
# systemd-udevd.service can be dropped once tuntap is moved to netlink # systemd-udevd.service can be dropped once tuntap is moved to netlink
After=systemd-udevd.service network-pre.target systemd-sysusers.service systemd-sysctl.service After=systemd-networkd.socket systemd-udevd.service network-pre.target systemd-sysusers.service systemd-sysctl.service
Before=network.target multi-user.target shutdown.target Before=network.target multi-user.target shutdown.target
Conflicts=shutdown.target Conflicts=shutdown.target
Wants=network.target Wants=systemd-networkd.socket network.target
[Service] [Service]
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_BROADCAST CAP_NET_RAW AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_BROADCAST CAP_NET_RAW