]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/networkd.c
networkd: handle SIGINT and SIGTERM
[thirdparty/systemd.git] / src / network / networkd.c
CommitLineData
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
22#include "sd-event.h"
a553fd32 23#include "sd-daemon.h"
f579559b
TG
24
25#include "networkd.h"
26
27int main(int argc, char *argv[]) {
e877666c 28 _cleanup_manager_free_ Manager *m = NULL;
f579559b
TG
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.");
4b6141c4
TG
39 r = -EINVAL;
40 goto out;
f579559b
TG
41 }
42
43 r = manager_new(&m);
1f6d9bc9
TG
44 if (r < 0) {
45 log_error("Could not create manager: %s", strerror(-r));
4b6141c4 46 goto out;
1f6d9bc9 47 }
f579559b 48
02b59d57 49 r = manager_load_config(m);
1f6d9bc9
TG
50 if (r < 0) {
51 log_error("Could not load configuration files: %s", strerror(-r));
52 goto out;
53 }
02b59d57 54
f579559b 55 r = manager_udev_listen(m);
1f6d9bc9
TG
56 if (r < 0) {
57 log_error("Could not connect to udev: %s", strerror(-r));
4b6141c4 58 goto out;
1f6d9bc9 59 }
f579559b
TG
60
61 r = manager_udev_enumerate_links(m);
1f6d9bc9
TG
62 if (r < 0) {
63 log_error("Could not enumerate links: %s", strerror(-r));
4b6141c4 64 goto out;
1f6d9bc9 65 }
f579559b 66
f882c247 67 r = manager_rtnl_listen(m);
1f6d9bc9
TG
68 if (r < 0) {
69 log_error("Could not connect to rtnl: %s", strerror(-r));
4b6141c4 70 goto out;
1f6d9bc9 71 }
3bef724f 72
1346b1f0
TG
73 r = manager_bus_listen(m);
74 if (r < 0) {
75 log_error("Could not connect to system bus: %s", strerror(-r));
76 goto out;
77 }
78
3bef724f
TG
79 /* write out empty resolv.conf to avoid a
80 * dangling symlink */
81 r = manager_update_resolv_conf(m);
1f6d9bc9
TG
82 if (r < 0) {
83 log_error("Could not create resolv.conf: %s", strerror(-r));
3bef724f 84 goto out;
1f6d9bc9 85 }
3bef724f 86
4b6141c4
TG
87 sd_notify(false,
88 "READY=1\n"
89 "STATUS=Processing requests...");
f882c247 90
f579559b 91 r = sd_event_loop(m->event);
1f6d9bc9
TG
92 if (r < 0) {
93 log_error("Event loop failed: %s", strerror(-r));
4b6141c4 94 goto out;
1f6d9bc9 95 }
4b6141c4
TG
96
97out:
98 sd_notify(false,
99 "STATUS=Shutting down...");
f579559b 100
4b6141c4 101 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
f579559b 102}