1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2014 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/>.
23 #include "sd-daemon.h"
25 #include "capability.h"
27 #include "resolved-manager.h"
28 #include "resolved-conf.h"
30 int main(int argc, char *argv[]) {
31 _cleanup_(manager_freep) Manager *m = NULL;
32 const char *user = "systemd-resolve";
37 log_set_target(LOG_TARGET_AUTO);
38 log_parse_environment();
44 log_error("This program takes no arguments.");
49 r = get_user_creds(&user, &uid, &gid, NULL, NULL);
51 log_error("Cannot resolve user name %s: %s", user, strerror(-r));
55 /* Always create the directory where resolv.conf will live */
56 r = mkdir_safe_label("/run/systemd/resolve", 0755, uid, gid);
58 log_error("Could not create runtime directory: %s", strerror(-r));
62 r = drop_privileges(uid, gid, 0);
66 assert_se(sigprocmask_many(SIG_BLOCK, SIGTERM, SIGINT, -1) == 0);
70 log_error("Could not create manager: %s", strerror(-r));
74 r = manager_parse_config_file(m);
76 log_warning("Failed to parse configuration file: %s", strerror(-r));
80 log_error("Failed to start manager: %s", strerror(-r));
84 /* Write finish default resolv.conf to avoid a dangling
86 r = manager_write_resolv_conf(m);
88 log_warning("Could not create resolv.conf: %s", strerror(-r));
92 "STATUS=Processing requests...");
94 r = sd_event_loop(m->event);
96 log_error("Event loop failed: %s", strerror(-r));
100 sd_event_get_exit_code(m->event, &r);
103 sd_notify(false, "STATUS=Shutting down...");
105 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;