summaryrefslogtreecommitdiff
path: root/src/login/logind-session.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-session.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-session.c')
-rw-r--r--src/login/logind-session.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/login/logind-session.c b/src/login/logind-session.c
index c12683c60c..cd87088456 100644
--- a/src/login/logind-session.c
+++ b/src/login/logind-session.c
@@ -229,7 +229,7 @@ int session_save(Session *s) {
fprintf(f, "SERVICE=%s\n", s->service);
if (s->seat && seat_has_vts(s->seat))
- fprintf(f, "VTNR=%i\n", s->vtnr);
+ fprintf(f, "VTNR=%u\n", s->vtnr);
if (s->leader > 0)
fprintf(f, "LEADER=%lu\n", (unsigned long) s->leader);
@@ -343,9 +343,9 @@ int session_load(Session *s) {
}
if (vtnr && s->seat && seat_has_vts(s->seat)) {
- int v;
+ unsigned int v;
- k = safe_atoi(vtnr, &v);
+ k = safe_atou(vtnr, &v);
if (k >= 0 && v >= 1)
s->vtnr = v;
}
@@ -421,7 +421,7 @@ int session_activate(Session *s) {
/* on seats with VTs, we let VTs manage session-switching */
if (seat_has_vts(s->seat)) {
- if (s->vtnr <= 0)
+ if (!s->vtnr)
return -ENOTSUP;
return chvt(s->vtnr);
@@ -981,13 +981,13 @@ int session_kill(Session *s, KillWho who, int signo) {
static int session_open_vt(Session *s) {
char path[128];
- if (s->vtnr <= 0)
+ if (!s->vtnr)
return -1;
if (s->vtfd >= 0)
return s->vtfd;
- sprintf(path, "/dev/tty%d", s->vtnr);
+ sprintf(path, "/dev/tty%u", s->vtnr);
s->vtfd = open(path, O_RDWR | O_CLOEXEC | O_NONBLOCK | O_NOCTTY);
if (s->vtfd < 0) {
log_error("cannot open VT %s of session %s: %m", path, s->id);
@@ -1044,7 +1044,7 @@ void session_mute_vt(Session *s) {
return;
error:
- log_error("cannot mute VT %d for session %s (%d/%d)", s->vtnr, s->id, r, errno);
+ log_error("cannot mute VT %u for session %s (%d/%d)", s->vtnr, s->id, r, errno);
session_restore_vt(s);
}