summaryrefslogtreecommitdiff
path: root/src/login/logind-seat.c
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2013-11-28 17:05:34 +0100
committerDavid Herrmann <dh.herrmann@gmail.com>2013-11-28 17:38:16 +0100
commit92bd5ff3a062c3f9475b9d9d39b9335bfeb7705e (patch)
tree0769b098958778286b006da515dca801c64e30d3 /src/login/logind-seat.c
parent92fe133abf2de889659464ae8affd1db1710f72e (diff)
logind: make VT numbers unsigned
Fix the whole code to use "unsigned int" for vtnr. 0 is an invalid vtnr so we don't need negative numbers at all. Note that most code already assumes it's unsigned so in case there's a negative vtnr, our code may, under special circumstances, silently break. So this patch makes sure all sources of vtnrs verify the validity. Also note that the dbus api already uses unsigned ints.
Diffstat (limited to 'src/login/logind-seat.c')
-rw-r--r--src/login/logind-seat.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c
index ca0e8d7fcf..eac5a5f26b 100644
--- a/src/login/logind-seat.c
+++ b/src/login/logind-seat.c
@@ -166,13 +166,13 @@ int seat_load(Seat *s) {
return 0;
}
-static int vt_allocate(int vtnr) {
+static int vt_allocate(unsigned int vtnr) {
_cleanup_free_ char *p = NULL;
_cleanup_close_ int fd = -1;
assert(vtnr >= 1);
- if (asprintf(&p, "/dev/tty%i", vtnr) < 0)
+ if (asprintf(&p, "/dev/tty%u", vtnr) < 0)
return -ENOMEM;
fd = open_terminal(p, O_RDWR|O_NOCTTY|O_CLOEXEC);
@@ -270,7 +270,7 @@ int seat_set_active(Seat *s, Session *session) {
return 0;
}
-int seat_active_vt_changed(Seat *s, int vtnr) {
+int seat_active_vt_changed(Seat *s, unsigned int vtnr) {
Session *i, *new_active = NULL;
int r;
@@ -280,7 +280,7 @@ int seat_active_vt_changed(Seat *s, int vtnr) {
if (!seat_has_vts(s))
return -EINVAL;
- log_debug("VT changed to %i", vtnr);
+ log_debug("VT changed to %u", vtnr);
LIST_FOREACH(sessions_by_seat, i, s->sessions)
if (i->vtnr == vtnr) {
@@ -297,7 +297,8 @@ int seat_active_vt_changed(Seat *s, int vtnr) {
int seat_read_active_vt(Seat *s) {
char t[64];
ssize_t k;
- int r, vtnr;
+ unsigned int vtnr;
+ int r;
assert(s);
@@ -320,13 +321,13 @@ int seat_read_active_vt(Seat *s) {
return -EIO;
}
- r = safe_atoi(t+3, &vtnr);
+ r = safe_atou(t+3, &vtnr);
if (r < 0) {
log_error("Failed to parse VT number %s", t+3);
return r;
}
- if (vtnr <= 0) {
+ if (!vtnr) {
log_error("VT number invalid: %s", t+3);
return -EIO;
}