chiark / gitweb /
remove unused includes
[elogind.git] / src / core / hostname-setup.c
index 7894f8a5f2e5f35528d8512e5359f73a778c375e..03b0ce3b4dad805d94b2cb7de2afd3c9bb549e89 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <unistd.h>
 #include <stdio.h>
 #include <errno.h>
-#include <string.h>
 #include <stdlib.h>
 
 #include "hostname-setup.h"
 #include "macro.h"
 #include "util.h"
 #include "log.h"
+#include "fileio.h"
 
 static int read_and_strip_hostname(const char *path, char **hn) {
         char *s;
@@ -41,7 +40,7 @@ static int read_and_strip_hostname(const char *path, char **hn) {
         if (r < 0)
                 return r;
 
-        hostname_cleanup(s);
+        hostname_cleanup(s, false);
 
         if (isempty(s)) {
                 free(s);
@@ -63,7 +62,7 @@ int hostname_setup(void) {
                 if (r == -ENOENT)
                         enoent = true;
                 else
-                        log_warning("Failed to read configured hostname: %s", strerror(-r));
+                        log_warning_errno(r, "Failed to read configured hostname: %m");
 
                 hn = NULL;
         } else
@@ -81,10 +80,8 @@ int hostname_setup(void) {
                 hn = "localhost";
         }
 
-        if (sethostname(hn, strlen(hn)) < 0) {
-                log_warning("Failed to set hostname to <%s>: %m", hn);
-                return -errno;
-        }
+        if (sethostname_idempotent(hn) < 0)
+                return log_warning_errno(errno, "Failed to set hostname to <%s>: %m", hn);
 
         log_info("Set hostname to <%s>.", hn);
         return 0;