mirror of
https://github.com/morgan9e/systemd
synced 2026-04-15 00:47:10 +09:00
terminal-util: modernize vtnr_from_tty() a bit
This commit is contained in:
@@ -777,26 +777,24 @@ bool tty_is_console(const char *tty) {
|
||||
}
|
||||
|
||||
int vtnr_from_tty(const char *tty) {
|
||||
int i, r;
|
||||
int r;
|
||||
|
||||
assert(tty);
|
||||
|
||||
tty = skip_dev_prefix(tty);
|
||||
|
||||
if (!startswith(tty, "tty") )
|
||||
const char *e = startswith(tty, "tty");
|
||||
if (!e)
|
||||
return -EINVAL;
|
||||
|
||||
if (!ascii_isdigit(tty[3]))
|
||||
return -EINVAL;
|
||||
|
||||
r = safe_atoi(tty+3, &i);
|
||||
unsigned u;
|
||||
r = safe_atou(e, &u);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (!vtnr_is_valid(u))
|
||||
return -ERANGE;
|
||||
|
||||
if (i < 0 || i > 63)
|
||||
return -EINVAL;
|
||||
|
||||
return i;
|
||||
return (int) u;
|
||||
}
|
||||
|
||||
int resolve_dev_console(char **ret) {
|
||||
|
||||
@@ -172,3 +172,7 @@ static inline bool osc_char_is_valid(char c) {
|
||||
* ECMA-48 5th edition, section 8.3.89 */
|
||||
return (unsigned char) c >= 32U && (unsigned char) c < 127;
|
||||
}
|
||||
|
||||
static inline bool vtnr_is_valid(unsigned n) {
|
||||
return n >= 1 && n <= 63;
|
||||
}
|
||||
|
||||
@@ -952,7 +952,7 @@ static int create_session(
|
||||
|
||||
if (seat) {
|
||||
if (seat_has_vts(seat)) {
|
||||
if (vtnr <= 0 || vtnr > 63)
|
||||
if (!vtnr_is_valid(vtnr))
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
|
||||
"VT number out of range");
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user