2 This file is part of systemd.
4 Copyright 2013 Tom Gundersen <teg@jklm.no>
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 #include "sd-daemon.h"
22 #include "capability-util.h"
24 #include "signal-util.h"
25 #include "user-util.h"
27 int main(int argc
, char *argv
[]) {
28 _cleanup_manager_free_ Manager
*m
= NULL
;
29 const char *user
= "systemd-network";
34 log_set_target(LOG_TARGET_AUTO
);
35 log_parse_environment();
41 log_error("This program takes no arguments.");
46 r
= get_user_creds(&user
, &uid
, &gid
, NULL
, NULL
);
48 log_error_errno(r
, "Cannot resolve user name %s: %m", user
);
52 /* Always create the directories people can create inotify
54 r
= mkdir_safe_label("/run/systemd/netif", 0755, uid
, gid
);
56 log_warning_errno(r
, "Could not create runtime directory: %m");
58 r
= mkdir_safe_label("/run/systemd/netif/links", 0755, uid
, gid
);
60 log_warning_errno(r
, "Could not create runtime directory 'links': %m");
62 r
= mkdir_safe_label("/run/systemd/netif/leases", 0755, uid
, gid
);
64 log_warning_errno(r
, "Could not create runtime directory 'leases': %m");
66 r
= mkdir_safe_label("/run/systemd/netif/lldp", 0755, uid
, gid
);
68 log_warning_errno(r
, "Could not create runtime directory 'lldp': %m");
70 r
= drop_privileges(uid
, gid
,
71 (1ULL << CAP_NET_ADMIN
) |
72 (1ULL << CAP_NET_BIND_SERVICE
) |
73 (1ULL << CAP_NET_BROADCAST
) |
74 (1ULL << CAP_NET_RAW
));
78 assert_se(sigprocmask_many(SIG_BLOCK
, NULL
, SIGTERM
, SIGINT
, -1) >= 0);
82 log_error_errno(r
, "Could not create manager: %m");
86 r
= manager_connect_bus(m
);
88 log_error_errno(r
, "Could not connect to bus: %m");
92 r
= manager_load_config(m
);
94 log_error_errno(r
, "Could not load configuration files: %m");
98 r
= manager_rtnl_enumerate_links(m
);
100 log_error_errno(r
, "Could not enumerate links: %m");
104 r
= manager_rtnl_enumerate_addresses(m
);
106 log_error_errno(r
, "Could not enumerate addresses: %m");
110 r
= manager_rtnl_enumerate_routes(m
);
112 log_error_errno(r
, "Could not enumerate routes: %m");
116 log_info("Enumeration completed");
120 "STATUS=Processing requests...");
124 log_error_errno(r
, "Event loop failed: %m");
131 "STATUS=Shutting down...");
133 return r
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;