/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  | }  | 
41  |  |  | 
42  | 0  | static inline char* gethostname_malloc(void) { | 
43  | 0  |         char *s;  | 
44  |  | 
  | 
45  | 0  |         if (gethostname_full(GET_HOSTNAME_ALLOW_LOCALHOST | GET_HOSTNAME_FALLBACK_DEFAULT, &s) < 0)  | 
46  | 0  |                 return NULL;  | 
47  |  |  | 
48  | 0  |         return s;  | 
49  | 0  | }  | 
50  |  |  | 
51  | 0  | static inline char* gethostname_short_malloc(void) { | 
52  | 0  |         char *s;  | 
53  | 0  | 
  | 
54  | 0  |         if (gethostname_full(GET_HOSTNAME_ALLOW_LOCALHOST | GET_HOSTNAME_FALLBACK_DEFAULT | GET_HOSTNAME_SHORT, &s) < 0)  | 
55  | 0  |                 return NULL;  | 
56  | 0  | 
  | 
57  | 0  |         return s;  | 
58  | 0  | }  |