vconsole-setup.c revision 2eec67acbb00593e414549a7e5b35eb7dd776b1b
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2010 Kay Sievers
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <limits.h>
#include "util.h"
#include "log.h"
#include "virt.h"
#include "fileio.h"
static bool is_vconsole(int fd) {
unsigned char data[1];
data[0] = TIOCL_GETFGCONSOLE;
}
static int disable_utf8(int fd) {
int r = 0, k;
r = -errno;
if (k < 0)
r = k;
if (k < 0)
r = k;
if (r < 0)
log_warning_errno(r, "Failed to disable UTF-8: %m");
return r;
}
static int enable_utf8(int fd) {
int r = 0, k;
long current = 0;
/*
* Change the current keyboard to unicode, unless it
* is currently in raw or off mode anyway. We
* shouldn't interfere with X11's processing of the
* key events.
*
*
*/
r = -errno;
}
if (k < 0)
r = k;
if (k < 0)
r = k;
if (r < 0)
log_warning_errno(r, "Failed to enable UTF-8: %m");
return r;
}
static int keymap_load(const char *vc, const char *map, const char *map_toggle, bool utf8, pid_t *_pid) {
const char *args[8];
int i = 0;
/* An empty map means kernel map */
*_pid = 0;
return 0;
}
args[i++] = KBD_LOADKEYS;
args[i++] = "-q";
args[i++] = "-C";
if (utf8)
args[i++] = "-u";
if (map_toggle)
args[i++] = map_toggle;
if (pid < 0)
else if (pid == 0) {
}
return 0;
}
static int font_load(const char *vc, const char *font, const char *map, const char *unimap, pid_t *_pid) {
const char *args[9];
int i = 0;
/* An empty font means kernel font */
*_pid = 0;
return 0;
}
args[i++] = KBD_SETFONT;
args[i++] = "-C";
if (map) {
args[i++] = "-m";
}
if (unimap) {
args[i++] = "-u";
}
if (pid < 0)
else if (pid == 0) {
}
return 0;
}
/*
* A newly allocated VT uses the font from the active VT. Here
* we update all possibly already allocated VTs with the configured
* font. It also allows to restart systemd-vconsole-setup.service,
* to apply a new font to all VTs.
*/
static void font_copy_to_all_vcs(int fd) {
struct unimapdesc unimapd;
int i, r;
/* get active, and 16 bit mask of used VT numbers */
if (r < 0)
return;
for (i = 1; i <= 15; i++) {
char vcname[16];
struct console_font_op cfo = {};
continue;
/* skip non-allocated ttys */
continue;
if (vcfd < 0)
continue;
/* copy font from active VT, where the font was uploaded to */
/* copy map of 8bit chars */
/* copy map of 8bit chars -> 16bit Unicode values */
/* copy unicode translation table */
/* unimapd is a ushort count and a pointer to an
array of struct unipair { ushort, ushort } */
struct unimapinit adv = { 0, 0, 0 };
}
}
}
const char *vc;
_cleanup_free_ char
bool utf8;
bool font_copy = false;
int r = EXIT_FAILURE;
log_open();
umask(0022);
if (argv[1])
else {
font_copy = true;
}
if (fd < 0) {
return EXIT_FAILURE;
}
if (!is_vconsole(fd)) {
return EXIT_FAILURE;
}
utf8 = is_locale_utf8();
"KEYMAP", &vc_keymap,
"KEYMAP_TOGGLE", &vc_keymap_toggle,
"FONT", &vc_font,
"FONT_MAP", &vc_font_map,
"FONT_UNIMAP", &vc_font_unimap,
NULL);
if (r < 0 && r != -ENOENT)
log_warning_errno(r, "Failed to read /etc/vconsole.conf: %m");
/* Let the kernel command line override /etc/vconsole.conf */
if (detect_container(NULL) <= 0) {
"vconsole.keymap", &vc_keymap,
"vconsole.keymap.toggle", &vc_keymap_toggle,
"vconsole.font", &vc_font,
"vconsole.font.map", &vc_font_map,
"vconsole.font.unimap", &vc_font_unimap,
NULL);
if (r < 0 && r != -ENOENT)
log_warning_errno(r, "Failed to read /proc/cmdline: %m");
}
if (utf8)
else
if (r < 0) {
return EXIT_FAILURE;
}
if (font_pid > 0)
if (r < 0) {
return EXIT_FAILURE;
}
if (keymap_pid > 0)
/* Only copy the font when we started setfont successfully */
return EXIT_SUCCESS;
}