networkd.c revision e877666c1553a3dd5b05b4c48090f889ffc079e6
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen/***
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen This file is part of systemd.
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen Copyright 2013 Tom Gundersen <teg@jklm.no>
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen systemd is free software; you can redistribute it and/or modify it
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen under the terms of the GNU Lesser General Public License as published by
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen the Free Software Foundation; either version 2.1 of the License, or
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen (at your option) any later version.
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen systemd is distributed in the hope that it will be useful, but
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen WITHOUT ANY WARRANTY; without even the implied warranty of
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen Lesser General Public License for more details.
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen You should have received a copy of the GNU Lesser General Public License
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen***/
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include "sd-event.h"
a553fd32d14739b746a05ae502b8acc38e5f9a50Tom Gundersen#include "sd-daemon.h"
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include "networkd.h"
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenint main(int argc, char *argv[]) {
e877666c1553a3dd5b05b4c48090f889ffc079e6Patrik Flykt _cleanup_manager_free_ Manager *m = NULL;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen int r;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen log_set_target(LOG_TARGET_AUTO);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen log_parse_environment();
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen log_open();
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen umask(0022);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (argc != 1) {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen log_error("This program takes no arguments.");
4b6141c42497dc199618f95fa3f359615eecfaa0Tom Gundersen r = -EINVAL;
4b6141c42497dc199618f95fa3f359615eecfaa0Tom Gundersen goto out;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen }
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen r = manager_new(&m);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (r < 0)
4b6141c42497dc199618f95fa3f359615eecfaa0Tom Gundersen goto out;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen r = manager_load_config(m);
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen if (r < 0)
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen return EXIT_FAILURE;
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen r = manager_udev_listen(m);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (r < 0)
4b6141c42497dc199618f95fa3f359615eecfaa0Tom Gundersen goto out;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen r = manager_udev_enumerate_links(m);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (r < 0)
4b6141c42497dc199618f95fa3f359615eecfaa0Tom Gundersen goto out;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersen r = manager_rtnl_listen(m);
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersen if (r < 0)
4b6141c42497dc199618f95fa3f359615eecfaa0Tom Gundersen goto out;
4b6141c42497dc199618f95fa3f359615eecfaa0Tom Gundersen
4b6141c42497dc199618f95fa3f359615eecfaa0Tom Gundersen sd_notify(false,
4b6141c42497dc199618f95fa3f359615eecfaa0Tom Gundersen "READY=1\n"
4b6141c42497dc199618f95fa3f359615eecfaa0Tom Gundersen "STATUS=Processing requests...");
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen r = sd_event_loop(m->event);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (r < 0)
4b6141c42497dc199618f95fa3f359615eecfaa0Tom Gundersen goto out;
4b6141c42497dc199618f95fa3f359615eecfaa0Tom Gundersen
4b6141c42497dc199618f95fa3f359615eecfaa0Tom Gundersenout:
4b6141c42497dc199618f95fa3f359615eecfaa0Tom Gundersen sd_notify(false,
4b6141c42497dc199618f95fa3f359615eecfaa0Tom Gundersen "STATUS=Shutting down...");
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
4b6141c42497dc199618f95fa3f359615eecfaa0Tom Gundersen return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen}