vconsole-setup.c revision 0d0f0c50d3a1d90f03972a6abb82e6413daaa583
/*-*- 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 <string.h>
#include <fcntl.h>
#include <ctype.h>
#include <stdbool.h>
#include <stdarg.h>
#include <limits.h>
#include <locale.h>
#include <langinfo.h>
#include "util.h"
#include "log.h"
#include "macro.h"
#include "virt.h"
static bool is_vconsole(int fd) {
unsigned char data[1];
data[0] = TIOCL_GETFGCONSOLE;
}
static bool is_locale_utf8(void) {
const char *set;
return true;
if (!set)
return true;
}
static int disable_utf8(int fd) {
int r = 0, k;
r = -errno;
r = -errno;
if (k < 0)
r = k;
if (r < 0)
return r;
}
static int enable_utf8(int fd) {
int r = 0, k;
r = -errno;
r = -errno;
if (k < 0)
r = k;
if (r < 0)
return r;
}
static int load_keymap(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) {
log_error("Failed to fork: %m");
return -errno;
} else if (pid == 0) {
}
return 0;
}
static int load_font(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) {
log_error("Failed to fork: %m");
return -errno;
} else if (pid == 0) {
}
return 0;
}
const char *vc;
char *vc_keymap_toggle = NULL;
char *vc_font_map = NULL;
char *vc_font_unimap = NULL;
#ifdef TARGET_GENTOO
char *vc_unicode = NULL;
#endif
#if defined(TARGET_MANDRIVA) || defined(TARGET_MAGEIA)
char *vc_keytable = NULL;
#endif
int fd = -1;
bool utf8;
int r = EXIT_FAILURE;
log_open();
umask(0022);
if (argv[1])
else
if (fd < 0) {
goto finish;
}
if (!is_vconsole(fd)) {
goto finish;
}
utf8 = is_locale_utf8();
log_error("Failed to allocate strings.");
goto finish;
}
r = 0;
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)
}
/* Hmm, nothing set on the kernel cmd line? Then let's
* try /etc/vconsole.conf */
if (r <= 0) {
"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)
}
if (r <= 0) {
#if defined(TARGET_FEDORA)
"SYSFONT", &vc_font,
"SYSFONTACM", &vc_font_map,
"UNIMAP", &vc_font_unimap,
NULL);
if (r < 0 && r != -ENOENT)
"KEYTABLE", &vc_keymap,
"KEYMAP", &vc_keymap,
NULL);
if (r < 0 && r != -ENOENT)
char *t;
t = strdup("/etc/sysconfig/console/default.kmap");
if (!t) {
log_oom();
goto finish;
}
vc_keymap = t;
}
#elif defined(TARGET_SUSE)
"KEYTABLE", &vc_keymap,
NULL);
if (r < 0 && r != -ENOENT)
"CONSOLE_FONT", &vc_font,
"CONSOLE_SCREENMAP", &vc_font_map,
"CONSOLE_UNICODEMAP", &vc_font_unimap,
NULL);
if (r < 0 && r != -ENOENT)
#elif defined(TARGET_ARCH)
"KEYMAP", &vc_keymap,
"CONSOLEFONT", &vc_font,
"CONSOLEMAP", &vc_font_map,
NULL);
if (r < 0 && r != -ENOENT)
#elif defined(TARGET_FRUGALWARE)
"keymap", &vc_keymap,
NULL);
if (r < 0 && r != -ENOENT)
"font", &vc_font,
NULL);
if (r < 0 && r != -ENOENT)
#elif defined(TARGET_ALTLINUX)
"KEYTABLE", &vc_keymap,
NULL)
if (r < 0 && r != -ENOENT)
"SYSFONT", &vc_font,
NULL);
if (r < 0 && r != -ENOENT)
#elif defined(TARGET_GENTOO)
"unicode", &vc_unicode,
NULL);
if (r < 0 && r != -ENOENT)
if (vc_unicode) {
int rc_unicode;
if (rc_unicode < 0)
else {
if (rc_unicode && !utf8)
log_warning("/etc/rc.conf wants unicode, but current locale is not UTF-8 capable!");
else if (!rc_unicode && utf8) {
log_debug("/etc/rc.conf does not want unicode, leave it on in kernel but does not apply to vconsole.");
utf8 = false;
}
}
}
/* /etc/conf.d/consolefont comments and gentoo
* documentation mention uppercase, but the actual
* contents are lowercase. the existing
* /etc/init.d/consolefont tries both
*/
"CONSOLEFONT", &vc_font,
"consolefont", &vc_font,
"consoletranslation", &vc_font_map,
"CONSOLETRANSLATION", &vc_font_map,
"unicodemap", &vc_font_unimap,
"UNICODEMAP", &vc_font_unimap,
NULL);
if (r < 0 && r != -ENOENT)
"keymap", &vc_keymap,
"KEYMAP", &vc_keymap,
NULL);
if (r < 0 && r != -ENOENT)
"SYSFONT", &vc_font,
"SYSFONTACM", &vc_font_map,
"UNIMAP", &vc_font_unimap,
NULL);
if (r < 0 && r != -ENOENT)
"KEYTABLE", &vc_keytable,
"KEYMAP", &vc_keymap,
"UNIKEYTABLE", &vc_keymap,
"GRP_TOGGLE", &vc_keymap_toggle,
NULL);
if (r < 0 && r != -ENOENT)
if (vc_keytable) {
if (utf8) {
else {
char *s;
if (s)
}
} else
if (!vc_keymap) {
log_oom();
goto finish;
}
}
char *t;
t = strdup("/etc/sysconfig/console/default.kmap");
if (!t) {
log_oom();
goto finish;
}
vc_keymap = t;
}
#endif
}
r = EXIT_FAILURE;
if (utf8)
else
r = EXIT_SUCCESS;
if (keymap_pid > 0)
if (font_pid > 0)
if (fd >= 0)
return r;
}