diff --git a/src/login/logind-core.c b/src/login/logind-core.c index ebe1d686340..997c421e9a8 100644 --- a/src/login/logind-core.c +++ b/src/login/logind-core.c @@ -29,6 +29,7 @@ #include "cgroup-util.h" #include "fd-util.h" #include "logind.h" +#include "parse-util.h" #include "strv.h" #include "terminal-util.h" #include "udev-util.h" @@ -380,6 +381,42 @@ bool manager_shall_kill(Manager *m, const char *user) { return m->kill_user_processes; } +int config_parse_n_autovts( + const char *unit, + const char *filename, + unsigned line, + const char *section, + unsigned section_line, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { + + unsigned *n = data; + unsigned o; + int r; + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(data); + + r = safe_atou(rvalue, &o); + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse number of autovts, ignoring: %s", rvalue); + return 0; + } + + if (o > 15) { + log_syntax(unit, LOG_ERR, filename, line, r, "A maximum of 15 autovts are supported, ignoring: %s", rvalue); + return 0; + } + + *n = o; + return 0; +} + static int vt_is_busy(unsigned int vtnr) { struct vt_stat vt_stat; int r = 0; @@ -387,6 +424,9 @@ static int vt_is_busy(unsigned int vtnr) { assert(vtnr >= 1); + /* VT_GETSTATE "cannot return state for more than 16 VTs, since v_state is short" */ + assert(vtnr <= 15); + /* We explicitly open /dev/tty1 here instead of /dev/tty0. If * we'd open the latter we'd open the foreground tty which * hence would be unconditionally busy. By opening /dev/tty1 diff --git a/src/login/logind-gperf.gperf b/src/login/logind-gperf.gperf index 0b6a5f3cf4b..aca464427b7 100644 --- a/src/login/logind-gperf.gperf +++ b/src/login/logind-gperf.gperf @@ -14,7 +14,7 @@ struct ConfigPerfItem; %struct-type %includes %% -Login.NAutoVTs, config_parse_unsigned, 0, offsetof(Manager, n_autovts) +Login.NAutoVTs, config_parse_n_autovts, 0, offsetof(Manager, n_autovts) Login.ReserveVT, config_parse_unsigned, 0, offsetof(Manager, reserve_vt) Login.KillUserProcesses, config_parse_bool, 0, offsetof(Manager, kill_user_processes) Login.KillOnlyUsers, config_parse_strv, 0, offsetof(Manager, kill_only_users) diff --git a/src/login/logind.h b/src/login/logind.h index 7556ee2e48e..2a8c663a7d1 100644 --- a/src/login/logind.h +++ b/src/login/logind.h @@ -186,6 +186,7 @@ const struct ConfigPerfItem* logind_gperf_lookup(const char *key, GPERF_LEN_TYPE int manager_set_lid_switch_ignore(Manager *m, usec_t until); +int config_parse_n_autovts(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); int config_parse_tmpfs_size(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); int config_parse_user_tasks_max(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);