]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/networkd.c
networkd: tie links to rtnl rather than udev
[thirdparty/systemd.git] / src / network / networkd.c
CommitLineData
f579559b
TG
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3/***
4 This file is part of systemd.
5
6 Copyright 2013 Tom Gundersen <teg@jklm.no>
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
22#include "sd-event.h"
a553fd32 23#include "sd-daemon.h"
f579559b
TG
24
25#include "networkd.h"
26
27int main(int argc, char *argv[]) {
e877666c 28 _cleanup_manager_free_ Manager *m = NULL;
f579559b
TG
29 int r;
30
31 log_set_target(LOG_TARGET_AUTO);
32 log_parse_environment();
33 log_open();
34
35 umask(0022);
36
37 if (argc != 1) {
38 log_error("This program takes no arguments.");
4b6141c4
TG
39 r = -EINVAL;
40 goto out;
f579559b
TG
41 }
42
fe8db0c5
TG
43 /* Always create the directories people can create inotify
44 * watches in. */
0ea51a11
TG
45 r = mkdir_label("/run/systemd/network", 0755);
46 if (r < 0)
47 log_error("Could not create runtime directory: %s",
48 strerror(-r));
49
50 r = mkdir_label("/run/systemd/network/links", 0755);
51 if (r < 0)
52 log_error("Could not create runtime directory 'links': %s",
53 strerror(-r));
54
55 r = mkdir_label("/run/systemd/network/leases", 0755);
56 if (r < 0)
57 log_error("Could not create runtime directory 'leases': %s",
58 strerror(-r));
fe8db0c5 59
f579559b 60 r = manager_new(&m);
1f6d9bc9
TG
61 if (r < 0) {
62 log_error("Could not create manager: %s", strerror(-r));
4b6141c4 63 goto out;
1f6d9bc9 64 }
f579559b 65
f0c4cd7a 66 r = manager_udev_listen(m);
1f6d9bc9 67 if (r < 0) {
f0c4cd7a 68 log_error("Could not connect to udev: %s", strerror(-r));
1f6d9bc9
TG
69 goto out;
70 }
02b59d57 71
f0c4cd7a 72 r = manager_rtnl_listen(m);
1f6d9bc9 73 if (r < 0) {
f0c4cd7a 74 log_error("Could not connect to rtnl: %s", strerror(-r));
4b6141c4 75 goto out;
1f6d9bc9 76 }
f579559b 77
f0c4cd7a 78 r = manager_bus_listen(m);
1f6d9bc9 79 if (r < 0) {
f0c4cd7a 80 log_error("Could not connect to system bus: %s", strerror(-r));
4b6141c4 81 goto out;
1f6d9bc9 82 }
f579559b 83
f0c4cd7a 84 r = manager_load_config(m);
1f6d9bc9 85 if (r < 0) {
f0c4cd7a 86 log_error("Could not load configuration files: %s", strerror(-r));
4b6141c4 87 goto out;
1f6d9bc9 88 }
3bef724f 89
505f8da7 90 r = manager_rtnl_enumerate_links(m);
1346b1f0 91 if (r < 0) {
f0c4cd7a 92 log_error("Could not enumerate links: %s", strerror(-r));
1346b1f0
TG
93 goto out;
94 }
95
3bef724f
TG
96 /* write out empty resolv.conf to avoid a
97 * dangling symlink */
98 r = manager_update_resolv_conf(m);
1f6d9bc9
TG
99 if (r < 0) {
100 log_error("Could not create resolv.conf: %s", strerror(-r));
3bef724f 101 goto out;
1f6d9bc9 102 }
3bef724f 103
4b6141c4
TG
104 sd_notify(false,
105 "READY=1\n"
106 "STATUS=Processing requests...");
f882c247 107
f579559b 108 r = sd_event_loop(m->event);
1f6d9bc9
TG
109 if (r < 0) {
110 log_error("Event loop failed: %s", strerror(-r));
4b6141c4 111 goto out;
1f6d9bc9 112 }
4b6141c4
TG
113
114out:
115 sd_notify(false,
116 "STATUS=Shutting down...");
f579559b 117
4b6141c4 118 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
f579559b 119}