chiark / gitweb /
resolved: Support resolved.conf.d directories in the usual search paths
[elogind.git] / src / resolve / resolved.c
index 892bb51386d8f27b97323085f6002415db458c86..c0ab947c0e88759fab91aeed87919bdcaba82dc3 100644 (file)
@@ -22,6 +22,7 @@
 #include "sd-event.h"
 #include "sd-daemon.h"
 #include "mkdir.h"
+#include "label.h"
 #include "capability.h"
 
 #include "resolved-manager.h"
@@ -38,24 +39,30 @@ int main(int argc, char *argv[]) {
         log_parse_environment();
         log_open();
 
-        umask(0022);
-
         if (argc != 1) {
                 log_error("This program takes no arguments.");
                 r = -EINVAL;
                 goto finish;
         }
 
+        umask(0022);
+
+        r = mac_selinux_init(NULL);
+        if (r < 0) {
+                log_error_errno(r, "SELinux setup failed: %m");
+                goto finish;
+        }
+
         r = get_user_creds(&user, &uid, &gid, NULL, NULL);
         if (r < 0) {
-                log_error("Cannot resolve user name %s: %s", user, strerror(-r));
+                log_error_errno(r, "Cannot resolve user name %s: %m", user);
                 goto finish;
         }
 
         /* Always create the directory where resolv.conf will live */
         r = mkdir_safe_label("/run/systemd/resolve", 0755, uid, gid);
         if (r < 0) {
-                log_error("Could not create runtime directory: %s", strerror(-r));
+                log_error_errno(r, "Could not create runtime directory: %m");
                 goto finish;
         }
 
@@ -67,17 +74,17 @@ int main(int argc, char *argv[]) {
 
         r = manager_new(&m);
         if (r < 0) {
-                log_error("Could not create manager: %s", strerror(-r));
+                log_error_errno(r, "Could not create manager: %m");
                 goto finish;
         }
 
         r = manager_parse_config_file(m);
         if (r < 0)
-                log_warning("Failed to parse configuration file: %s", strerror(-r));
+                log_warning_errno(r, "Failed to parse configuration file: %m");
 
         r = manager_start(m);
         if (r < 0) {
-                log_error("Failed to start manager: %s", strerror(-r));
+                log_error_errno(r, "Failed to start manager: %m");
                 goto finish;
         }
 
@@ -85,7 +92,7 @@ int main(int argc, char *argv[]) {
          * symlink */
         r = manager_write_resolv_conf(m);
         if (r < 0)
-                log_warning("Could not create resolv.conf: %s", strerror(-r));
+                log_warning_errno(r, "Could not create resolv.conf: %m");
 
         sd_notify(false,
                   "READY=1\n"
@@ -93,12 +100,16 @@ int main(int argc, char *argv[]) {
 
         r = sd_event_loop(m->event);
         if (r < 0) {
-                log_error("Event loop failed: %s", strerror(-r));
+                log_error_errno(r, "Event loop failed: %m");
                 goto finish;
         }
 
+        sd_event_get_exit_code(m->event, &r);
+
 finish:
-        sd_notify(false, "STATUS=Shutting down...");
+        sd_notify(false,
+                  "STOPPING=1\n"
+                  "STATUS=Shutting down...");
 
         return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
 }