get_pretty_hostname() so far had semantics not in line with our usual
ones: the return parameter was actually freed before the return string
written into it, because that's what parse_env_file() does. Moreover,
when the value was not set it would return NULL but succeed.
Let's normalize this, and only fill in the return value if there's
something set, and never read from it, like we usually do with return
parameter, and in particular those named "ret_xyz".
The existing callers don't really care about the differences, but it's
nicer to normalize behaviour to minimize surprises.
#include <unistd.h>
#include "alloc-util.h"
+#include "env-file.h"
#include "hostname-util.h"
#include "os-util.h"
#include "string-util.h"
endswith_no_case(hostname, ".localhost.localdomain") ||
endswith_no_case(hostname, ".localhost.localdomain.");
}
+
+int get_pretty_hostname(char **ret) {
+ _cleanup_free_ char *n = NULL;
+ int r;
+
+ assert(ret);
+
+ r = parse_env_file(NULL, "/etc/machine-info", "PRETTY_HOSTNAME", &n);
+ if (r < 0)
+ return r;
+
+ if (isempty(n))
+ return -ENXIO;
+
+ *ret = TAKE_PTR(n);
+ return 0;
+}
#include <stdbool.h>
#include <stdio.h>
-#include "env-file.h"
#include "macro.h"
#include "strv.h"
return STRCASE_IN_SET(hostname, "_outbound", "_outbound.");
}
-static inline int get_pretty_hostname(char **ret) {
- return parse_env_file(NULL, "/etc/machine-info", "PRETTY_HOSTNAME", ret);
-}
+int get_pretty_hostname(char **ret);