chiark / gitweb /
networkd: improve logging
[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 "sd-event.h"
23 #include "sd-daemon.h"
24
25 #include "networkd.h"
26
27 int main(int argc, char *argv[]) {
28         _cleanup_manager_free_ Manager *m = NULL;
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.");
39                 r = -EINVAL;
40                 goto out;
41         }
42
43         r = manager_new(&m);
44         if (r < 0) {
45                 log_error("Could not create manager: %s", strerror(-r));
46                 goto out;
47         }
48
49         r = manager_load_config(m);
50         if (r < 0) {
51                 log_error("Could not load configuration files: %s", strerror(-r));
52                 goto out;
53         }
54
55         r = manager_udev_listen(m);
56         if (r < 0) {
57                 log_error("Could not connect to udev: %s", strerror(-r));
58                 goto out;
59         }
60
61         r = manager_udev_enumerate_links(m);
62         if (r < 0) {
63                 log_error("Could not enumerate links: %s", strerror(-r));
64                 goto out;
65         }
66
67         r = manager_rtnl_listen(m);
68         if (r < 0) {
69                 log_error("Could not connect to rtnl: %s", strerror(-r));
70                 goto out;
71         }
72
73         /* write out empty resolv.conf to avoid a
74          * dangling symlink */
75         r = manager_update_resolv_conf(m);
76         if (r < 0) {
77                 log_error("Could not create resolv.conf: %s", strerror(-r));
78                 goto out;
79         }
80
81         sd_notify(false,
82                   "READY=1\n"
83                   "STATUS=Processing requests...");
84
85         r = sd_event_loop(m->event);
86         if (r < 0) {
87                 log_error("Event loop failed: %s", strerror(-r));
88                 goto out;
89         }
90
91 out:
92         sd_notify(false,
93                   "STATUS=Shutting down...");
94
95         return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
96 }