firstboot,sysinstall,hostnamed: always show FANCY_NAME=
This makes sure that whenever we want to show the OS name we can show the fancy name. Thus this moves the escaping/validation of the fancy name out of hostnamed into generic code, and then makes use of it in sysinstall,firstboot,prompt-util.
This commit is contained in:
committed by
Luca Boccassi
parent
d0168f4db6
commit
324fab7ed6
@@ -3,10 +3,12 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "ansi-color.h"
|
||||
#include "chase.h"
|
||||
#include "dirent-util.h"
|
||||
#include "env-file.h"
|
||||
#include "errno-util.h"
|
||||
#include "escape.h"
|
||||
#include "fd-util.h"
|
||||
#include "fs-util.h"
|
||||
#include "glyph-util.h"
|
||||
@@ -512,3 +514,46 @@ const char* os_release_pretty_name(const char *pretty_name, const char *name) {
|
||||
return empty_to_null(pretty_name) ?:
|
||||
empty_to_null(name) ?: "Linux";
|
||||
}
|
||||
|
||||
char *unescape_fancy_name(char **fancy_name) {
|
||||
assert(fancy_name);
|
||||
|
||||
/* Checks if the fancy name is valid, unescapes if it is, nullifies it if not */
|
||||
|
||||
_cleanup_free_ char *unescaped_fancy_name = NULL;
|
||||
|
||||
if (isempty(*fancy_name))
|
||||
goto clear;
|
||||
|
||||
/* We undo one level of C escapes on this */
|
||||
ssize_t n = cunescape(*fancy_name, /* flags= */ 0, &unescaped_fancy_name);
|
||||
if (n < 0) {
|
||||
log_debug_errno((int) n, "Failed to unescape FANCY_NAME= string, suppressing: %m");
|
||||
goto clear;
|
||||
}
|
||||
|
||||
if (!utf8_is_valid(unescaped_fancy_name)) {
|
||||
log_debug("Unescaped FANCY_NAME= string is not valid UTF-8, suppressing.");
|
||||
goto clear;
|
||||
}
|
||||
|
||||
free_and_replace(*fancy_name, unescaped_fancy_name);
|
||||
return *fancy_name;
|
||||
|
||||
clear:
|
||||
*fancy_name = mfree(*fancy_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool use_fancy_name(const char *fancy_name) {
|
||||
|
||||
/* Decides whether to show the specified fancy name */
|
||||
|
||||
if (isempty(fancy_name))
|
||||
return false;
|
||||
|
||||
if (!colors_enabled())
|
||||
return false;
|
||||
|
||||
return emoji_enabled() || ascii_is_valid(fancy_name);
|
||||
}
|
||||
|
||||
@@ -55,3 +55,6 @@ int load_os_release_pairs_with_prefix(const char *root, const char *prefix, char
|
||||
int os_release_support_ended(const char *support_end, bool quiet, usec_t *ret_eol);
|
||||
|
||||
const char* os_release_pretty_name(const char *pretty_name, const char *name);
|
||||
|
||||
bool use_fancy_name(const char *fancy_name);
|
||||
char *unescape_fancy_name(char **fancy_name);
|
||||
|
||||
Reference in New Issue
Block a user