chiark / gitweb /
networkctl: increase column width for link type to 18, to accomodate for 'ieee80211_r...
[elogind.git] / src / network / networkd.c
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 "capability.h"
23 #include "sd-event.h"
24 #include "sd-daemon.h"
25
26 #include "networkd.h"
27
28 int main(int argc, char *argv[]) {
29         _cleanup_manager_free_ Manager *m = NULL;
30         const char *user = "systemd-network";
31         uid_t uid;
32         gid_t gid;
33         int r;
34
35         log_set_target(LOG_TARGET_AUTO);
36         log_parse_environment();
37         log_open();
38
39         umask(0022);
40
41         if (argc != 1) {
42                 log_error("This program takes no arguments.");
43                 r = -EINVAL;
44                 goto out;
45         }
46
47         r = get_user_creds(&user, &uid, &gid, NULL, NULL);
48         if (r < 0) {
49                 log_error("Cannot resolve user name %s: %s", user, strerror(-r));
50                 goto out;
51         }
52
53         /* Always create the directories people can create inotify
54          * watches in. */
55         r = mkdir_safe_label("/run/systemd/netif", 0755, uid, gid);
56         if (r < 0)
57                 log_error("Could not create runtime directory: %s",
58                           strerror(-r));
59
60         r = mkdir_safe_label("/run/systemd/netif/links", 0755, uid, gid);
61         if (r < 0)
62                 log_error("Could not create runtime directory 'links': %s",
63                           strerror(-r));
64
65         r = mkdir_safe_label("/run/systemd/netif/leases", 0755, uid, gid);
66         if (r < 0)
67                 log_error("Could not create runtime directory 'leases': %s",
68                           strerror(-r));
69
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));
75         if (r < 0)
76                 goto out;
77
78         assert_se(sigprocmask_many(SIG_BLOCK, SIGTERM, SIGINT, -1) == 0);
79
80         r = manager_new(&m);
81         if (r < 0) {
82                 log_error("Could not create manager: %s", strerror(-r));
83                 goto out;
84         }
85
86         r = manager_udev_listen(m);
87         if (r < 0) {
88                 log_error("Could not connect to udev: %s", strerror(-r));
89                 goto out;
90         }
91
92         r = manager_rtnl_listen(m);
93         if (r < 0) {
94                 log_error("Could not connect to rtnl: %s", strerror(-r));
95                 goto out;
96         }
97
98         r = manager_bus_listen(m);
99         if (r < 0) {
100                 log_error("Could not connect to system bus: %s", strerror(-r));
101                 goto out;
102         }
103
104         r = manager_load_config(m);
105         if (r < 0) {
106                 log_error("Could not load configuration files: %s", strerror(-r));
107                 goto out;
108         }
109
110         r = manager_rtnl_enumerate_links(m);
111         if (r < 0) {
112                 log_error("Could not enumerate links: %s", strerror(-r));
113                 goto out;
114         }
115
116         sd_notify(false,
117                   "READY=1\n"
118                   "STATUS=Processing requests...");
119
120         r = sd_event_loop(m->event);
121         if (r < 0) {
122                 log_error("Event loop failed: %s", strerror(-r));
123                 goto out;
124         }
125
126 out:
127         sd_notify(false,
128                   "STATUS=Shutting down...");
129
130         return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
131 }