Coverage Report

Created: 2025-07-09 06:39

/src/systemd/src/shared/hostname-setup.h
Line
Count
Source (jump to first uncovered line)
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2
#pragma once
3
4
#include "forward.h"
5
6
typedef enum HostnameSource {
7
        HOSTNAME_STATIC,     /* from /etc/hostname */
8
        HOSTNAME_TRANSIENT,  /* a transient hostname set through systemd, hostnamed, the container manager, or otherwise */
9
        HOSTNAME_DEFAULT,    /* the os-release default or the compiled-in fallback were used */
10
        _HOSTNAME_INVALID = -EINVAL,
11
} HostnameSource;
12
13
const char* hostname_source_to_string(HostnameSource source) _const_;
14
HostnameSource hostname_source_from_string(const char *str) _pure_;
15
16
int sethostname_idempotent(const char *s);
17
18
int shorten_overlong(const char *s, char **ret);
19
20
int read_etc_hostname_stream(FILE *f, bool substitute_wildcards, char **ret);
21
int read_etc_hostname(const char *path, bool substitute_wildcards, char **ret);
22
23
void hostname_update_source_hint(const char *hostname, HostnameSource source);
24
int hostname_setup(bool really);
25
26
int hostname_substitute_wildcards(char *name);
27
28
char* get_default_hostname(void);
29
30
typedef enum GetHostnameFlags {
31
        GET_HOSTNAME_ALLOW_LOCALHOST  = 1 << 0, /* accepts "localhost" or friends. */
32
        GET_HOSTNAME_FALLBACK_DEFAULT = 1 << 1, /* use default hostname if no hostname is set. */
33
        GET_HOSTNAME_SHORT            = 1 << 2, /* kills the FQDN part if present. */
34
} GetHostnameFlags;
35
36
int gethostname_full(GetHostnameFlags flags, char **ret);
37
38
0
static inline int gethostname_strict(char **ret) {
39
0
        return gethostname_full(0, ret);
40
0
}
Unexecuted instantiation: fuzz-hostname-setup.c:gethostname_strict
Unexecuted instantiation: journald-manager.c:gethostname_strict
Unexecuted instantiation: resolved-manager.c:gethostname_strict
Unexecuted instantiation: resolved-util.c:gethostname_strict
Unexecuted instantiation: networkd-dhcp4.c:gethostname_strict
Unexecuted instantiation: networkd-dhcp6.c:gethostname_strict
Unexecuted instantiation: sd-lldp-tx.c:gethostname_strict
Unexecuted instantiation: condition.c:gethostname_strict
Unexecuted instantiation: discover-image.c:gethostname_strict
Unexecuted instantiation: dissect-image.c:gethostname_strict
Unexecuted instantiation: hostname-setup.c:gethostname_strict
Unexecuted instantiation: osc-context.c:gethostname_strict
Unexecuted instantiation: ptyfwd.c:gethostname_strict
Unexecuted instantiation: specifier.c:gethostname_strict
Unexecuted instantiation: user-record.c:gethostname_strict
Unexecuted instantiation: wall.c:gethostname_strict
41
42
865k
static inline char* gethostname_malloc(void) {
43
865k
        char *s;
44
45
865k
        if (gethostname_full(GET_HOSTNAME_ALLOW_LOCALHOST | GET_HOSTNAME_FALLBACK_DEFAULT, &s) < 0)
46
0
                return NULL;
47
48
865k
        return s;
49
865k
}
Unexecuted instantiation: fuzz-hostname-setup.c:gethostname_malloc
Unexecuted instantiation: journald-manager.c:gethostname_malloc
Unexecuted instantiation: resolved-manager.c:gethostname_malloc
Unexecuted instantiation: resolved-util.c:gethostname_malloc
Unexecuted instantiation: networkd-dhcp4.c:gethostname_malloc
Unexecuted instantiation: networkd-dhcp6.c:gethostname_malloc
Unexecuted instantiation: sd-lldp-tx.c:gethostname_malloc
condition.c:gethostname_malloc
Line
Count
Source
42
320
static inline char* gethostname_malloc(void) {
43
320
        char *s;
44
45
320
        if (gethostname_full(GET_HOSTNAME_ALLOW_LOCALHOST | GET_HOSTNAME_FALLBACK_DEFAULT, &s) < 0)
46
0
                return NULL;
47
48
320
        return s;
49
320
}
Unexecuted instantiation: discover-image.c:gethostname_malloc
Unexecuted instantiation: dissect-image.c:gethostname_malloc
Unexecuted instantiation: hostname-setup.c:gethostname_malloc
Unexecuted instantiation: osc-context.c:gethostname_malloc
Unexecuted instantiation: ptyfwd.c:gethostname_malloc
specifier.c:gethostname_malloc
Line
Count
Source
42
42.2k
static inline char* gethostname_malloc(void) {
43
42.2k
        char *s;
44
45
42.2k
        if (gethostname_full(GET_HOSTNAME_ALLOW_LOCALHOST | GET_HOSTNAME_FALLBACK_DEFAULT, &s) < 0)
46
0
                return NULL;
47
48
42.2k
        return s;
49
42.2k
}
Unexecuted instantiation: user-record.c:gethostname_malloc
wall.c:gethostname_malloc
Line
Count
Source
42
822k
static inline char* gethostname_malloc(void) {
43
822k
        char *s;
44
45
822k
        if (gethostname_full(GET_HOSTNAME_ALLOW_LOCALHOST | GET_HOSTNAME_FALLBACK_DEFAULT, &s) < 0)
46
0
                return NULL;
47
48
822k
        return s;
49
822k
}
50
51
125k
static inline char* gethostname_short_malloc(void) {
52
125k
        char *s;
53
54
125k
        if (gethostname_full(GET_HOSTNAME_ALLOW_LOCALHOST | GET_HOSTNAME_FALLBACK_DEFAULT | GET_HOSTNAME_SHORT, &s) < 0)
55
0
                return NULL;
56
57
125k
        return s;
58
125k
}
Unexecuted instantiation: fuzz-hostname-setup.c:gethostname_short_malloc
Unexecuted instantiation: journald-manager.c:gethostname_short_malloc
Unexecuted instantiation: resolved-manager.c:gethostname_short_malloc
Unexecuted instantiation: resolved-util.c:gethostname_short_malloc
Unexecuted instantiation: networkd-dhcp4.c:gethostname_short_malloc
Unexecuted instantiation: networkd-dhcp6.c:gethostname_short_malloc
Unexecuted instantiation: sd-lldp-tx.c:gethostname_short_malloc
Unexecuted instantiation: condition.c:gethostname_short_malloc
Unexecuted instantiation: discover-image.c:gethostname_short_malloc
Unexecuted instantiation: dissect-image.c:gethostname_short_malloc
Unexecuted instantiation: hostname-setup.c:gethostname_short_malloc
Unexecuted instantiation: osc-context.c:gethostname_short_malloc
Unexecuted instantiation: ptyfwd.c:gethostname_short_malloc
specifier.c:gethostname_short_malloc
Line
Count
Source
51
125k
static inline char* gethostname_short_malloc(void) {
52
125k
        char *s;
53
54
125k
        if (gethostname_full(GET_HOSTNAME_ALLOW_LOCALHOST | GET_HOSTNAME_FALLBACK_DEFAULT | GET_HOSTNAME_SHORT, &s) < 0)
55
0
                return NULL;
56
57
125k
        return s;
58
125k
}
Unexecuted instantiation: user-record.c:gethostname_short_malloc
Unexecuted instantiation: wall.c:gethostname_short_malloc