summaryrefslogtreecommitdiff
path: root/src/vconsole
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-03-22 17:12:23 +0100
committerLennart Poettering <lennart@poettering.net>2018-03-22 20:30:40 +0100
commitb53f3386e514c53221a127e5b9192108b8f63793 (patch)
tree1acd2d8f4c1a631123967c90e24c1416977d53a0 /src/vconsole
parent16dbd110a7469f703cf17e5d15bce18e00fdc302 (diff)
downloadsystemd-b53f3386e514c53221a127e5b9192108b8f63793.tar.gz
vconsole: minor modernizations
Diffstat (limited to 'src/vconsole')
-rw-r--r--src/vconsole/vconsole-setup.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/src/vconsole/vconsole-setup.c b/src/vconsole/vconsole-setup.c
index b91968e81f..e7fced247d 100644
--- a/src/vconsole/vconsole-setup.c
+++ b/src/vconsole/vconsole-setup.c
@@ -49,35 +49,42 @@
#include "virt.h"
static int verify_vc_device(int fd) {
- unsigned char data[1];
+ unsigned char data[] = {
+ TIOCL_GETFGCONSOLE,
+ };
+
int r;
- data[0] = TIOCL_GETFGCONSOLE;
r = ioctl(fd, TIOCLINUX, data);
- return r < 0 ? -errno : r;
+ if (r < 0)
+ return -errno;
+
+ return r;
}
static int verify_vc_allocation(unsigned idx) {
char vcname[sizeof("/dev/vcs") + DECIMAL_STR_MAX(unsigned) - 2];
- int r;
xsprintf(vcname, "/dev/vcs%u", idx);
- r = access(vcname, F_OK);
- return r < 0 ? -errno : r;
+
+ if (access(vcname, F_OK) < 0)
+ return -errno;
+
+ return 0;
}
static int verify_vc_allocation_byfd(int fd) {
struct vt_stat vcs = {};
- int r;
- r = ioctl(fd, VT_GETSTATE, &vcs);
- return r < 0 ? -errno : verify_vc_allocation(vcs.v_active);
+ if (ioctl(fd, VT_GETSTATE, &vcs) < 0)
+ return -errno;
+
+ return verify_vc_allocation(vcs.v_active);
}
static int verify_vc_kbmode(int fd) {
- int r, curr_mode;
+ int curr_mode;
- r = ioctl(fd, KDGKBMODE, &curr_mode);
/*
* Make sure we only adjust consoles in K_XLATE or K_UNICODE mode.
* Otherwise we would (likely) interfere with X11's processing of the
@@ -85,7 +92,8 @@ static int verify_vc_kbmode(int fd) {
*
* http://lists.freedesktop.org/archives/systemd-devel/2013-February/008573.html
*/
- if (r < 0)
+
+ if (ioctl(fd, KDGKBMODE, &curr_mode) < 0)
return -errno;
return IN_SET(curr_mode, K_XLATE, K_UNICODE) ? 0 : -EBUSY;
@@ -420,7 +428,6 @@ int main(int argc, char **argv) {
fd = verify_source_vc(&vc, argv[1]);
else
fd = find_source_vc(&vc, &idx);
-
if (fd < 0)
return EXIT_FAILURE;