]>
Commit | Line | Data |
---|---|---|
091a364c TG |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
6 | Copyright 2014 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 "resolved.h" | |
26 | ||
27 | #include "mkdir.h" | |
682265d5 | 28 | #include "capability.h" |
091a364c TG |
29 | |
30 | int main(int argc, char *argv[]) { | |
31 | _cleanup_manager_free_ Manager *m = NULL; | |
682265d5 TG |
32 | const char *user = "systemd-resolve"; |
33 | uid_t uid; | |
34 | gid_t gid; | |
091a364c TG |
35 | int r; |
36 | ||
37 | log_set_target(LOG_TARGET_AUTO); | |
38 | log_parse_environment(); | |
39 | log_open(); | |
40 | ||
41 | umask(0022); | |
42 | ||
43 | if (argc != 1) { | |
44 | log_error("This program takes no arguments."); | |
45 | r = -EINVAL; | |
46 | goto out; | |
47 | } | |
48 | ||
682265d5 TG |
49 | r = get_user_creds(&user, &uid, &gid, NULL, NULL); |
50 | if (r < 0) { | |
51 | log_error("Cannot resolve user name %s: %s", user, strerror(-r)); | |
52 | goto out; | |
53 | } | |
54 | ||
091a364c | 55 | /* Always create the directory where resolv.conf will live */ |
682265d5 TG |
56 | r = mkdir_safe_label("/run/systemd/resolve", 0755, uid, gid); |
57 | if (r < 0) { | |
091a364c TG |
58 | log_error("Could not create runtime directory: %s", |
59 | strerror(-r)); | |
682265d5 TG |
60 | goto out; |
61 | } | |
62 | ||
63 | r = drop_privileges(uid, gid, 0); | |
64 | if (r < 0) | |
65 | goto out; | |
091a364c | 66 | |
b9e7a9d8 LP |
67 | assert_se(sigprocmask_many(SIG_BLOCK, SIGTERM, SIGINT, -1) == 0); |
68 | ||
091a364c TG |
69 | r = manager_new(&m); |
70 | if (r < 0) { | |
71 | log_error("Could not create manager: %s", strerror(-r)); | |
72 | goto out; | |
73 | } | |
74 | ||
75 | r = manager_network_monitor_listen(m); | |
76 | if (r < 0) { | |
77 | log_error("Could not listen for network events: %s", strerror(-r)); | |
78 | goto out; | |
79 | } | |
80 | ||
81 | /* write out default resolv.conf to avoid a | |
82 | * dangling symlink */ | |
83 | r = manager_update_resolv_conf(m); | |
84 | if (r < 0) { | |
85 | log_error("Could not create resolv.conf: %s", strerror(-r)); | |
86 | goto out; | |
87 | } | |
88 | ||
89 | sd_notify(false, | |
90 | "READY=1\n" | |
91 | "STATUS=Processing requests..."); | |
92 | ||
93 | r = sd_event_loop(m->event); | |
94 | if (r < 0) { | |
95 | log_error("Event loop failed: %s", strerror(-r)); | |
96 | goto out; | |
97 | } | |
98 | ||
99 | out: | |
100 | sd_notify(false, | |
101 | "STATUS=Shutting down..."); | |
102 | ||
103 | return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; | |
104 | } |