]>
Commit | Line | Data |
---|---|---|
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 | ||
a553fd32 | 22 | #include "sd-daemon.h" |
24882e06 LP |
23 | #include "capability.h" |
24 | #include "signal-util.h" | |
f579559b TG |
25 | #include "networkd.h" |
26 | ||
27 | int main(int argc, char *argv[]) { | |
e877666c | 28 | _cleanup_manager_free_ Manager *m = NULL; |
d3cf48f4 LP |
29 | const char *user = "systemd-network"; |
30 | uid_t uid; | |
31 | gid_t gid; | |
f579559b TG |
32 | int r; |
33 | ||
34 | log_set_target(LOG_TARGET_AUTO); | |
35 | log_parse_environment(); | |
36 | log_open(); | |
37 | ||
38 | umask(0022); | |
39 | ||
40 | if (argc != 1) { | |
41 | log_error("This program takes no arguments."); | |
4b6141c4 TG |
42 | r = -EINVAL; |
43 | goto out; | |
f579559b TG |
44 | } |
45 | ||
d3cf48f4 LP |
46 | r = get_user_creds(&user, &uid, &gid, NULL, NULL); |
47 | if (r < 0) { | |
da927ba9 | 48 | log_error_errno(r, "Cannot resolve user name %s: %m", user); |
d3cf48f4 LP |
49 | goto out; |
50 | } | |
51 | ||
fe8db0c5 TG |
52 | /* Always create the directories people can create inotify |
53 | * watches in. */ | |
85b5673b | 54 | r = mkdir_safe_label("/run/systemd/netif", 0755, uid, gid); |
0ea51a11 | 55 | if (r < 0) |
8bde1d0c | 56 | log_warning_errno(r, "Could not create runtime directory: %m"); |
0ea51a11 | 57 | |
85b5673b | 58 | r = mkdir_safe_label("/run/systemd/netif/links", 0755, uid, gid); |
0ea51a11 | 59 | if (r < 0) |
8bde1d0c | 60 | log_warning_errno(r, "Could not create runtime directory 'links': %m"); |
0ea51a11 | 61 | |
85b5673b | 62 | r = mkdir_safe_label("/run/systemd/netif/leases", 0755, uid, gid); |
0ea51a11 | 63 | if (r < 0) |
8bde1d0c | 64 | log_warning_errno(r, "Could not create runtime directory 'leases': %m"); |
fe8db0c5 | 65 | |
49699bac SS |
66 | r = mkdir_safe_label("/run/systemd/netif/lldp", 0755, uid, gid); |
67 | if (r < 0) | |
8bde1d0c | 68 | log_warning_errno(r, "Could not create runtime directory 'lldp': %m"); |
49699bac | 69 | |
d3cf48f4 LP |
70 | r = drop_privileges(uid, gid, |
71 | (1ULL << CAP_NET_ADMIN) | | |
72 | (1ULL << CAP_NET_BIND_SERVICE) | | |
73 | (1ULL << CAP_NET_BROADCAST) | | |
bddfc8af | 74 | (1ULL << CAP_NET_RAW)); |
d3cf48f4 LP |
75 | if (r < 0) |
76 | goto out; | |
77 | ||
186fe1db LP |
78 | assert_se(sigprocmask_many(SIG_BLOCK, SIGTERM, SIGINT, -1) == 0); |
79 | ||
f579559b | 80 | r = manager_new(&m); |
1f6d9bc9 | 81 | if (r < 0) { |
da927ba9 | 82 | log_error_errno(r, "Could not create manager: %m"); |
8f203c16 TG |
83 | goto out; |
84 | } | |
85 | ||
86 | r = manager_connect_bus(m); | |
87 | if (r < 0) { | |
88 | log_error_errno(r, "Could not connect to bus: %m"); | |
4b6141c4 | 89 | goto out; |
1f6d9bc9 | 90 | } |
f579559b | 91 | |
f0c4cd7a | 92 | r = manager_load_config(m); |
1f6d9bc9 | 93 | if (r < 0) { |
da927ba9 | 94 | log_error_errno(r, "Could not load configuration files: %m"); |
4b6141c4 | 95 | goto out; |
1f6d9bc9 | 96 | } |
3bef724f | 97 | |
505f8da7 | 98 | r = manager_rtnl_enumerate_links(m); |
1346b1f0 | 99 | if (r < 0) { |
da927ba9 | 100 | log_error_errno(r, "Could not enumerate links: %m"); |
1346b1f0 TG |
101 | goto out; |
102 | } | |
103 | ||
45af44d4 TG |
104 | r = manager_rtnl_enumerate_addresses(m); |
105 | if (r < 0) { | |
106 | log_error_errno(r, "Could not enumerate links: %m"); | |
107 | goto out; | |
108 | } | |
109 | ||
73432d67 TG |
110 | log_info("Enumeration completed"); |
111 | ||
4b6141c4 TG |
112 | sd_notify(false, |
113 | "READY=1\n" | |
114 | "STATUS=Processing requests..."); | |
f882c247 | 115 | |
a97dcc12 | 116 | r = manager_run(m); |
1f6d9bc9 | 117 | if (r < 0) { |
da927ba9 | 118 | log_error_errno(r, "Event loop failed: %m"); |
4b6141c4 | 119 | goto out; |
1f6d9bc9 | 120 | } |
4b6141c4 TG |
121 | |
122 | out: | |
123 | sd_notify(false, | |
af4ec430 | 124 | "STOPPING=1\n" |
4b6141c4 | 125 | "STATUS=Shutting down..."); |
f579559b | 126 | |
4b6141c4 | 127 | return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; |
f579559b | 128 | } |