mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-24 21:34:08 +03:00
terminal-util: modernize get_kernel_consoles() a bit
Also, make sure when we run in a container, we don't use the data from /sys at all, but immediately fall back to /dev/console itself.
This commit is contained in:
parent
c2b3215941
commit
bef41af233
@ -705,24 +705,29 @@ char *resolve_dev_console(char **active) {
|
||||
return tty;
|
||||
}
|
||||
|
||||
int get_kernel_consoles(char ***consoles) {
|
||||
_cleanup_strv_free_ char **con = NULL;
|
||||
int get_kernel_consoles(char ***ret) {
|
||||
_cleanup_strv_free_ char **l = NULL;
|
||||
_cleanup_free_ char *line = NULL;
|
||||
const char *active;
|
||||
const char *p;
|
||||
int r;
|
||||
|
||||
assert(consoles);
|
||||
assert(ret);
|
||||
|
||||
/* If we /sys is mounted read-only this means we are running in some kind of container environment. In that
|
||||
* case /sys would reflect the host system, not us, hence ignore the data we can read from it. */
|
||||
if (path_is_read_only_fs("/sys") > 0)
|
||||
goto fallback;
|
||||
|
||||
r = read_one_line_file("/sys/class/tty/console/active", &line);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
active = line;
|
||||
p = line;
|
||||
for (;;) {
|
||||
_cleanup_free_ char *tty = NULL;
|
||||
char *path;
|
||||
|
||||
r = extract_first_word(&active, &tty, NULL, 0);
|
||||
r = extract_first_word(&p, &tty, NULL, 0);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r == 0)
|
||||
@ -745,21 +750,29 @@ int get_kernel_consoles(char ***consoles) {
|
||||
continue;
|
||||
}
|
||||
|
||||
r = strv_consume(&con, path);
|
||||
r = strv_consume(&l, path);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (strv_isempty(con)) {
|
||||
if (strv_isempty(l)) {
|
||||
log_debug("No devices found for system console");
|
||||
|
||||
r = strv_extend(&con, "/dev/console");
|
||||
if (r < 0)
|
||||
return r;
|
||||
goto fallback;
|
||||
}
|
||||
|
||||
*consoles = con;
|
||||
con = NULL;
|
||||
*ret = l;
|
||||
l = NULL;
|
||||
|
||||
return 0;
|
||||
|
||||
fallback:
|
||||
r = strv_extend(&l, "/dev/console");
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
*ret = l;
|
||||
l = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ int ask_string(char **ret, const char *text, ...) _printf_(2, 3);
|
||||
int vt_disallocate(const char *name);
|
||||
|
||||
char *resolve_dev_console(char **active);
|
||||
int get_kernel_consoles(char ***consoles);
|
||||
int get_kernel_consoles(char ***ret);
|
||||
bool tty_is_vc(const char *tty);
|
||||
bool tty_is_vc_resolve(const char *tty);
|
||||
bool tty_is_console(const char *tty) _pure_;
|
||||
|
Loading…
Reference in New Issue
Block a user