SHA256
1
0
forked from pool/systemd

Accepting request 178889 from home:sbrabec:branches:Base:System

- Cleanup NumLock setting code
  (handle-numlock-value-in-etc-sysconfig-keyboard.patch).

OBS-URL: https://build.opensuse.org/request/show/178889
OBS-URL: https://build.opensuse.org/package/show/Base:System/systemd?expand=0&rev=393
This commit is contained in:
Frederic Crozat 2013-06-13 15:43:52 +00:00 committed by Git OBS Bridge
parent d3cbd4a150
commit 6926882e37
3 changed files with 141 additions and 138 deletions

View File

@ -1,19 +1,105 @@
From: Stanislav Brabec <sbrabec@suse.cz>
Date: Fri, 20 Apr 2012 17:16:37 +0200
Subject: handle numlock value in /etc/sysconfig/keyboard
Set NumLock according to /etc/sysconfig/keyboard.
(bnc#746595)
---
Makefile.am | 13 +++++++++++
configure.ac | 5 +++++
rules/73-seat-numlock.rules | 8 +++++++
src/login/numlock-on.c | 37 ++++++++++++++++++++++++++++++++
src/vconsole/vconsole-setup.c | 38 +++++++++++++++++++++++++++++++++
units/systemd-vconsole-setup.service.in | 2 +-
6 files changed, 102 insertions(+), 1 deletion(-)
create mode 100644 rules/73-seat-numlock.rules
create mode 100644 src/login/numlock-on.c
https://bugzilla.novell.com/show_bug.cgi?id=746595
Authors:
Stanislav Brabec <sbrabec@suse.cz>
Cristian Rodríguez <crrodriguez@opensuse.org>
Index: systemd-204/src/vconsole/vconsole-setup.c
===================================================================
--- systemd-204.orig/src/vconsole/vconsole-setup.c
+++ systemd-204/src/vconsole/vconsole-setup.c
@@ -42,6 +42,10 @@
#include "fileio.h"
#include "strv.h"
+#define BIOS_DATA_AREA 0x400
+#define BDA_KEYBOARD_STATUS_FLAGS_4 0x97
+#define BDA_KSF4_NUMLOCK_MASK 0x02
+
static bool is_vconsole(int fd) {
unsigned char data[1];
@@ -321,12 +325,14 @@ int main(int argc, char **argv) {
char *vc_kbd_delay = NULL;
char *vc_kbd_rate = NULL;
char *vc_kbd_disable_caps_lock = NULL;
+ char *vc_kbd_numlock = NULL;
char *vc_compose_table = NULL;
pid_t kbd_rate_pid = 0, compose_table_pid = 0;
#endif
int fd = -1;
bool utf8;
bool disable_capslock = false;
+ bool numlock = false;
pid_t font_pid = 0, keymap_pid = 0;
bool font_copy = false;
int r = EXIT_FAILURE;
@@ -389,6 +395,7 @@ int main(int argc, char **argv) {
"KBD_DELAY", &vc_kbd_delay,
"KBD_RATE", &vc_kbd_rate,
"KBD_DISABLE_CAPS_LOCK", &vc_kbd_disable_caps_lock,
+ "KBD_NUMLOCK", &vc_kbd_numlock,
"COMPOSETABLE", &vc_compose_table,
NULL);
if (r < 0 && r != -ENOENT)
@@ -403,6 +410,36 @@ int main(int argc, char **argv) {
log_warning("Failed to read /etc/sysconfig/console: %s", strerror(-r));
disable_capslock = vc_kbd_disable_caps_lock && strcasecmp(vc_kbd_disable_caps_lock, "YES") == 0;
+#if defined(__i386__) || defined(__x86_64__)
+ if (vc_kbd_numlock && strcaseeq(vc_kbd_numlock, "bios")) {
+ int _cleanup_close_ fdmem;
+ char c;
+
+ fdmem = open ("/dev/mem", O_RDONLY);
+
+ if(fdmem < 0) {
+ r = EXIT_FAILURE;
+ log_error("Failed to open /dev/mem: %m");
+ goto finish;
+ }
+
+ if(lseek(fdmem, BIOS_DATA_AREA + BDA_KEYBOARD_STATUS_FLAGS_4, SEEK_SET) == (off_t) -1) {
+ r = EXIT_FAILURE;
+ log_error("Failed to seek /dev/mem: %m");
+ goto finish;
+ }
+
+ if(read (fdmem, &c, sizeof(char)) == -1) {
+ r = EXIT_FAILURE;
+ log_error("Failed to read /dev/mem: %m");
+ goto finish;
+ }
+
+ if (c & BDA_KSF4_NUMLOCK_MASK)
+ numlock = true;
+ } else
+#endif
+ numlock = vc_kbd_numlock && strcaseeq(vc_kbd_numlock, "yes");
#endif
}
@@ -425,6 +462,10 @@ int main(int argc, char **argv) {
finish:
if (keymap_pid > 0)
wait_for_terminate_and_warn(KBD_LOADKEYS, keymap_pid);
+ if (numlock)
+ touch("/run/numlock-on");
+ else
+ unlink("/run/numlock-on");
#ifdef HAVE_SYSV_COMPAT
if (compose_table_pid > 0)
@@ -444,6 +485,7 @@ finish:
free(vc_font);
free(vc_font_map);
free(vc_font_unimap);
+ free(vc_kbd_numlock);
#ifdef HAVE_SYSV_COMPAT
free(vc_kbd_delay);
free(vc_kbd_rate);
Index: systemd-204/Makefile.am
===================================================================
--- systemd-204.orig/Makefile.am
@ -38,28 +124,12 @@ Index: systemd-204/Makefile.am
if ENABLE_GUDEV
if ENABLE_GTK_DOC
SUBDIRS += \
Index: systemd-204/configure.ac
===================================================================
--- systemd-204.orig/configure.ac
+++ systemd-204/configure.ac
@@ -791,6 +791,11 @@ AM_CONDITIONAL(ENABLE_MANPAGES, [test "x
# ------------------------------------------------------------------------------
+AC_PATH_PROG([HWINFO], [hwinfo], [/usr/sbin/hwinfo], [/sbin:/usr/sbin:/usr/bin:/bin])
+AC_DEFINE_UNQUOTED([HWINFO], ["${HWINFO}"], [Path to hwinfo binary. (SUSE)])
+AC_PATH_PROG([SETLEDS], [setleds], [/bin/setleds], [/sbin:/usr/sbin:/usr/bin:/bin])
+AC_DEFINE_UNQUOTED([SETLEDS], ["${SETLEDS}"], [Path to setleds binary.])
+
# Location of the init scripts as mandated by LSB
SYSTEM_SYSVINIT_PATH=/etc/init.d
SYSTEM_SYSVRCND_PATH=/etc/rc.d
Index: systemd-204/rules/73-seat-numlock.rules
===================================================================
--- /dev/null
+++ systemd-204/rules/73-seat-numlock.rules
@@ -0,0 +1,8 @@
+# This file is part of systemd.
+# This file is part of SUSE customization of systemd.
+#
+# systemd is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
@ -71,120 +141,41 @@ Index: systemd-204/src/login/numlock-on.c
===================================================================
--- /dev/null
+++ systemd-204/src/login/numlock-on.c
@@ -0,0 +1,37 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
@@ -0,0 +1,34 @@
+/*
+ * numlock-on.c: Turn numlock-on
+ *
+ * This file may be freely copied under the terms of the GNU General
+ * Public License (GPL), version 2, or at your option any later
+ * version.
+
+/***
+ This file is part of systemd.
+ * Copyright (C) 2013 Stanislav Brabec, SUSE
+ *
+ * based on setleds.c, which is
+ * Copyright (C) 1994-1999 Andries E. Brouwer
+ */
+
+ Copyright 2012 Stanislav Brabec
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <linux/kd.h>
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+int
+main(int argc, char **argv) {
+ char flags;
+
+ 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
+ General Public License for more details.
+ if (ioctl(0, KDGKBLED, &flags)) {
+ perror("KDGKBLED");
+ exit(1);
+ }
+
+ You should have received a copy of the GNU General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+ if (ioctl(0, KDSKBLED, flags | LED_NUM | (LED_NUM << 4))) {
+ perror("KDSKBLED");
+ exit(1);
+ }
+
+#include "config.h"
+#include <fcntl.h>
+#include <sysexits.h>
+#include <unistd.h>
+
+int main (int argc, char *argv[]) {
+ static const char *args[] = { SETLEDS, "-D", "+num", NULL };
+
+ if (argc != 2)
+ return EX_USAGE;
+ close (STDIN_FILENO);
+ if (open (argv[1], O_RDONLY) != STDIN_FILENO)
+ return EX_IOERR;
+ /* add cast to prevent warning caused by -Wwrite-strings */
+ return execv(args[0], (char * const*) args);
+ exit(0);
+}
Index: systemd-204/src/vconsole/vconsole-setup.c
===================================================================
--- systemd-204.orig/src/vconsole/vconsole-setup.c
+++ systemd-204/src/vconsole/vconsole-setup.c
@@ -321,12 +321,14 @@ int main(int argc, char **argv) {
char *vc_kbd_delay = NULL;
char *vc_kbd_rate = NULL;
char *vc_kbd_disable_caps_lock = NULL;
+ char *vc_kbd_numlock = NULL;
char *vc_compose_table = NULL;
pid_t kbd_rate_pid = 0, compose_table_pid = 0;
#endif
int fd = -1;
bool utf8;
bool disable_capslock = false;
+ bool numlock = false;
pid_t font_pid = 0, keymap_pid = 0;
bool font_copy = false;
int r = EXIT_FAILURE;
@@ -389,6 +391,7 @@ int main(int argc, char **argv) {
"KBD_DELAY", &vc_kbd_delay,
"KBD_RATE", &vc_kbd_rate,
"KBD_DISABLE_CAPS_LOCK", &vc_kbd_disable_caps_lock,
+ "KBD_NUMLOCK", &vc_kbd_numlock,
"COMPOSETABLE", &vc_compose_table,
NULL);
if (r < 0 && r != -ENOENT)
@@ -403,6 +406,37 @@ int main(int argc, char **argv) {
log_warning("Failed to read /etc/sysconfig/console: %s", strerror(-r));
disable_capslock = vc_kbd_disable_caps_lock && strcasecmp(vc_kbd_disable_caps_lock, "YES") == 0;
+ if (vc_kbd_numlock && strcasecmp(vc_kbd_numlock, "BIOS") == 0) {
+ int hwinfo_fd[2];
+ pid_t hwinfo_pid;
+
+ pipe(hwinfo_fd);
+ if ((hwinfo_pid = fork()) < 0) {
+ log_error("Failed to fork: %m");
+ _exit(EXIT_FAILURE);
+ } else if (hwinfo_pid == 0) {
+ const char *args[3];
+ int i = 0;
+ args[i++] = HWINFO;
+ args[i++] = "--bios";
+ args[i++] = NULL;
+ close(hwinfo_fd[0]);
+ fclose(stdout);
+ dup2(hwinfo_fd[1], STDOUT_FILENO);
+ execv(args[0], (char **) args);
+ _exit(EXIT_FAILURE);
+ } else {
+ char line[17];
+ FILE *hwinfo_file = fdopen(hwinfo_fd[0], "r");
+ close(hwinfo_fd[1]);
+ while (fgets(line, 17, hwinfo_file))
+ if (strstr(line, "Num Lock: on"))
+ numlock = true;
+ close(hwinfo_fd[0]);
+ fclose(hwinfo_file);
+ }
+ } else
+ numlock = vc_kbd_numlock && strcasecmp(vc_kbd_numlock, "YES") == 0;
#endif
}
@@ -425,6 +459,10 @@ int main(int argc, char **argv) {
finish:
if (keymap_pid > 0)
wait_for_terminate_and_warn(KBD_LOADKEYS, keymap_pid);
+ if (numlock)
+ close(open("/run/numlock-on", O_WRONLY|O_CREAT, 0644));
+ else
+ unlink("/run/numlock-on");
#ifdef HAVE_SYSV_COMPAT
if (compose_table_pid > 0)
Index: systemd-204/units/systemd-vconsole-setup.service.in
===================================================================
--- systemd-204.orig/units/systemd-vconsole-setup.service.in

View File

@ -1,3 +1,9 @@
-------------------------------------------------------------------
Thu Jun 13 16:00:25 CEST 2013 - sbrabec@suse.cz
- Cleanup NumLock setting code
(handle-numlock-value-in-etc-sysconfig-keyboard.patch).
-------------------------------------------------------------------
Wed Jun 12 10:00:53 UTC 2013 - fcrozat@suse.com

View File

@ -1,3 +1,9 @@
-------------------------------------------------------------------
Thu Jun 13 16:00:25 CEST 2013 - sbrabec@suse.cz
- Cleanup NumLock setting code
(handle-numlock-value-in-etc-sysconfig-keyboard.patch).
-------------------------------------------------------------------
Wed Jun 12 10:00:53 UTC 2013 - fcrozat@suse.com