Merge pull request #6582 from poettering/logind-tty
various tty path parsing fixes
This commit is contained in:
@@ -143,3 +143,13 @@ bool is_deviceallow_pattern(const char *path);
|
||||
int systemd_installation_has_version(const char *root, unsigned minimal_version);
|
||||
|
||||
bool dot_or_dot_dot(const char *path);
|
||||
|
||||
static inline const char *skip_dev_prefix(const char *p) {
|
||||
const char *e;
|
||||
|
||||
/* Drop any /dev prefix if there is any */
|
||||
|
||||
e = path_startswith(p, "/dev/");
|
||||
|
||||
return e ?: p;
|
||||
}
|
||||
|
||||
+11
-14
@@ -55,6 +55,7 @@
|
||||
#include "terminal-util.h"
|
||||
#include "time-util.h"
|
||||
#include "util.h"
|
||||
#include "path-util.h"
|
||||
|
||||
static volatile unsigned cached_columns = 0;
|
||||
static volatile unsigned cached_lines = 0;
|
||||
@@ -556,6 +557,7 @@ int terminal_vhangup(const char *name) {
|
||||
|
||||
int vt_disallocate(const char *name) {
|
||||
_cleanup_close_ int fd = -1;
|
||||
const char *e, *n;
|
||||
unsigned u;
|
||||
int r;
|
||||
|
||||
@@ -563,7 +565,8 @@ int vt_disallocate(const char *name) {
|
||||
* (i.e. because it is the active one), at least clear it
|
||||
* entirely (including the scrollback buffer) */
|
||||
|
||||
if (!startswith(name, "/dev/"))
|
||||
e = path_startswith(name, "/dev/");
|
||||
if (!e)
|
||||
return -EINVAL;
|
||||
|
||||
if (!tty_is_vc(name)) {
|
||||
@@ -582,10 +585,11 @@ int vt_disallocate(const char *name) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!startswith(name, "/dev/tty"))
|
||||
n = startswith(e, "tty");
|
||||
if (!n)
|
||||
return -EINVAL;
|
||||
|
||||
r = safe_atou(name+8, &u);
|
||||
r = safe_atou(n, &u);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -649,10 +653,7 @@ bool tty_is_vc(const char *tty) {
|
||||
bool tty_is_console(const char *tty) {
|
||||
assert(tty);
|
||||
|
||||
if (startswith(tty, "/dev/"))
|
||||
tty += 5;
|
||||
|
||||
return streq(tty, "console");
|
||||
return streq(skip_dev_prefix(tty), "console");
|
||||
}
|
||||
|
||||
int vtnr_from_tty(const char *tty) {
|
||||
@@ -660,8 +661,7 @@ int vtnr_from_tty(const char *tty) {
|
||||
|
||||
assert(tty);
|
||||
|
||||
if (startswith(tty, "/dev/"))
|
||||
tty += 5;
|
||||
tty = skip_dev_prefix(tty);
|
||||
|
||||
if (!startswith(tty, "tty") )
|
||||
return -EINVAL;
|
||||
@@ -775,8 +775,7 @@ bool tty_is_vc_resolve(const char *tty) {
|
||||
|
||||
assert(tty);
|
||||
|
||||
if (startswith(tty, "/dev/"))
|
||||
tty += 5;
|
||||
tty = skip_dev_prefix(tty);
|
||||
|
||||
if (streq(tty, "console")) {
|
||||
tty = resolve_dev_console(&active);
|
||||
@@ -918,11 +917,9 @@ int getttyname_malloc(int fd, char **ret) {
|
||||
|
||||
r = ttyname_r(fd, path, sizeof(path));
|
||||
if (r == 0) {
|
||||
const char *p;
|
||||
char *c;
|
||||
|
||||
p = startswith(path, "/dev/");
|
||||
c = strdup(p ?: path);
|
||||
c = strdup(skip_dev_prefix(path));
|
||||
if (!c)
|
||||
return -ENOMEM;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user