1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2013 Tom Gundersen <teg@jklm.no>
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.
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.
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/>.
22 #include "capability.h"
24 #include "sd-daemon.h"
28 int main(int argc, char *argv[]) {
29 _cleanup_manager_free_ Manager *m = NULL;
30 const char *user = "systemd-network";
35 log_set_target(LOG_TARGET_AUTO);
36 log_parse_environment();
42 log_error("This program takes no arguments.");
47 r = get_user_creds(&user, &uid, &gid, NULL, NULL);
49 log_error_errno(r, "Cannot resolve user name %s: %m", user);
53 /* Always create the directories people can create inotify
55 r = mkdir_safe_label("/run/systemd/netif", 0755, uid, gid);
57 log_error_errno(r, "Could not create runtime directory: %m");
59 r = mkdir_safe_label("/run/systemd/netif/links", 0755, uid, gid);
61 log_error_errno(r, "Could not create runtime directory 'links': %m");
63 r = mkdir_safe_label("/run/systemd/netif/leases", 0755, uid, gid);
65 log_error_errno(r, "Could not create runtime directory 'leases': %m");
67 r = mkdir_safe_label("/run/systemd/netif/lldp", 0755, uid, gid);
69 log_error("Could not create runtime directory 'lldp': %s",
73 r = drop_privileges(uid, gid,
74 (1ULL << CAP_NET_ADMIN) |
75 (1ULL << CAP_NET_BIND_SERVICE) |
76 (1ULL << CAP_NET_BROADCAST) |
77 (1ULL << CAP_NET_RAW));
81 assert_se(sigprocmask_many(SIG_BLOCK, SIGTERM, SIGINT, -1) == 0);
85 log_error_errno(r, "Could not create manager: %m");
89 r = manager_connect_bus(m);
91 log_error_errno(r, "Could not connect to bus: %m");
95 r = manager_load_config(m);
97 log_error_errno(r, "Could not load configuration files: %m");
101 r = manager_rtnl_enumerate_links(m);
103 log_error_errno(r, "Could not enumerate links: %m");
107 r = manager_rtnl_enumerate_addresses(m);
109 log_error_errno(r, "Could not enumerate links: %m");
113 log_info("Enumeration completed");
117 "STATUS=Processing requests...");
121 log_error_errno(r, "Event loop failed: %m");
128 "STATUS=Shutting down...");
130 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;