LCOV - code coverage report
Current view: top level - core - hostname-setup.c (source / functions) Hit Total Coverage
Test: systemd_full.info Lines: 0 21 0.0 %
Date: 2019-08-23 13:36:53 Functions: 0 1 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 20 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: LGPL-2.1+ */
       2                 :            : 
       3                 :            : #include <errno.h>
       4                 :            : #include <stdio.h>
       5                 :            : #include <stdlib.h>
       6                 :            : 
       7                 :            : #include "alloc-util.h"
       8                 :            : #include "fileio.h"
       9                 :            : #include "hostname-setup.h"
      10                 :            : #include "hostname-util.h"
      11                 :            : #include "log.h"
      12                 :            : #include "macro.h"
      13                 :            : #include "string-util.h"
      14                 :            : #include "util.h"
      15                 :            : 
      16                 :          0 : int hostname_setup(void) {
      17                 :          0 :         _cleanup_free_ char *b = NULL;
      18                 :          0 :         bool enoent = false;
      19                 :            :         const char *hn;
      20                 :            :         int r;
      21                 :            : 
      22                 :          0 :         r = read_etc_hostname(NULL, &b);
      23         [ #  # ]:          0 :         if (r < 0) {
      24         [ #  # ]:          0 :                 if (r == -ENOENT)
      25                 :          0 :                         enoent = true;
      26                 :            :                 else
      27         [ #  # ]:          0 :                         log_warning_errno(r, "Failed to read configured hostname: %m");
      28                 :            : 
      29                 :          0 :                 hn = NULL;
      30                 :            :         } else
      31                 :          0 :                 hn = b;
      32                 :            : 
      33         [ #  # ]:          0 :         if (isempty(hn)) {
      34                 :            :                 /* Don't override the hostname if it is already set
      35                 :            :                  * and not explicitly configured */
      36         [ #  # ]:          0 :                 if (hostname_is_set())
      37                 :          0 :                         return 0;
      38                 :            : 
      39         [ #  # ]:          0 :                 if (enoent)
      40         [ #  # ]:          0 :                         log_info("No hostname configured.");
      41                 :            : 
      42                 :          0 :                 hn = FALLBACK_HOSTNAME;
      43                 :            :         }
      44                 :            : 
      45                 :          0 :         r = sethostname_idempotent(hn);
      46         [ #  # ]:          0 :         if (r < 0)
      47         [ #  # ]:          0 :                 return log_warning_errno(r, "Failed to set hostname to <%s>: %m", hn);
      48                 :            : 
      49         [ #  # ]:          0 :         log_info("Set hostname to <%s>.", hn);
      50                 :          0 :         return 0;
      51                 :            : }

Generated by: LCOV version 1.14