1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-23 17:34:00 +03:00

shared: voidify call to loop_write() and trim duplicate code

Coverity CID#1402375.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2019-07-17 09:49:01 +02:00
parent 60b17d6fcd
commit ba5d26ccb2

View File

@ -526,34 +526,21 @@ int terminal_vhangup(const char *name) {
}
int vt_disallocate(const char *name) {
_cleanup_close_ int fd = -1;
const char *e, *n;
unsigned u;
const char *e;
int r;
/* Deallocate the VT if possible. If not possible
* (i.e. because it is the active one), at least clear it
* entirely (including the scrollback buffer) */
* entirely (including the scrollback buffer). */
e = path_startswith(name, "/dev/");
if (!e)
return -EINVAL;
if (!tty_is_vc(name)) {
/* So this is not a VT. I guess we cannot deallocate
* it then. But let's at least clear the screen */
fd = open_terminal(name, O_RDWR|O_NOCTTY|O_CLOEXEC);
if (fd < 0)
return fd;
loop_write(fd,
"\033[r" /* clear scrolling region */
"\033[H" /* move home */
"\033[2J", /* clear screen */
10, false);
return 0;
}
if (tty_is_vc(name)) {
_cleanup_close_ int fd = -1;
unsigned u;
const char *n;
n = startswith(e, "tty");
if (!n)
@ -572,21 +559,20 @@ int vt_disallocate(const char *name) {
return fd;
r = ioctl(fd, VT_DISALLOCATE, u);
fd = safe_close(fd);
if (r >= 0)
return 0;
if (errno != EBUSY)
return -errno;
}
/* Couldn't deallocate, so let's clear it fully with
* scrollback */
fd = open_terminal(name, O_RDWR|O_NOCTTY|O_CLOEXEC);
if (fd < 0)
return fd;
/* So this is not a VT (in which case we cannot deallocate it),
* or we failed to deallocate. Let's at least clear the screen. */
loop_write(fd,
_cleanup_close_ int fd2 = open_terminal(name, O_RDWR|O_NOCTTY|O_CLOEXEC);
if (fd2 < 0)
return fd2;
(void) loop_write(fd2,
"\033[r" /* clear scrolling region */
"\033[H" /* move home */
"\033[3J", /* clear screen including scrollback, requires Linux 2.6.40 */