Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 34474 Details for
Bug 55648
acpid 1.0.3 with support for Toshiba laptops
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
toshiba-keys.patch, used by acpid-1.0.3 ebuild
toshiba-keys.patch (text/plain), 11.84 KB, created by
Sebastian Bergmann (RETIRED)
on 2004-06-30 02:28:37 UTC
(
hide
)
Description:
toshiba-keys.patch, used by acpid-1.0.3 ebuild
Filename:
MIME Type:
Creator:
Sebastian Bergmann (RETIRED)
Created:
2004-06-30 02:28:37 UTC
Size:
11.84 KB
patch
obsolete
>Binary files acpid-1.0.3/acpid and acpid-1.0.3-wez/acpid differ >Binary files acpid-1.0.3/acpid.8.gz and acpid-1.0.3-wez/acpid.8.gz differ >diff -u -r -N acpid-1.0.3/acpid.c acpid-1.0.3-wez/acpid.c >--- acpid-1.0.3/acpid.c 2004-02-12 20:03:33.000000000 +0000 >+++ acpid-1.0.3-wez/acpid.c 2004-06-21 11:46:48.481573600 +0100 >@@ -3,6 +3,7 @@ > * > * Portions Copyright (C) 2000 Andrew Henroid > * Portions Copyright (C) 2001 Sun Microsystems (thockin@sun.com) >+ * Portions Copyright (C) 2004 Wez Furlong > * > * This program is free software; you can redistribute it and/or modify > * it under the terms of the GNU General Public License as published by >@@ -51,20 +52,251 @@ > static const char *logfile = ACPI_LOGFILE; > static const char *eventfile = ACPI_EVENTFILE; > static const char *socketfile = ACPI_SOCKETFILE; >+static const char *toshiba_keys = ACPI_TOSHIBA_KEYS; >+ > static int nosocket; > static const char *socketgroup; > static mode_t socketmode = ACPI_SOCKETMODE; > static int foreground; > >+struct powstate { >+ /* battery life remaining */ >+ int remain; >+ int hours, mins; >+ int pct; >+ /* on ac power? */ >+ int on_ac; >+ /* name of the battery */ >+ char batname[8]; >+ /* design capacity */ >+ int dcap; >+ /* last full capacity */ >+ int fullcap; >+ /* cap level at which to warn */ >+ int capwarn; >+ /* time at which we last warned the user */ >+ time_t last_warn; >+} pow = { 0, }; >+ >+int tosh_get_key(void) >+{ >+ char keybuf[256]; >+ int n; >+ int ready, keyval; >+ int tosh_fd; >+ >+ tosh_fd = open(toshiba_keys, O_RDONLY); >+ if (tosh_fd < 0) >+ return 0; >+ >+ n = read(tosh_fd, keybuf, sizeof(keybuf)); >+ close(tosh_fd); >+ >+ /* remove that button from the queue */ >+ tosh_fd = open(toshiba_keys, O_WRONLY); >+ if (tosh_fd >= 0) { >+ write(tosh_fd, "hotkey_ready:0", sizeof("hotkey_ready:0")-1); >+ close(tosh_fd); >+ } >+ >+ /* did we get a key ? */ >+ if (n == 0) >+ return 0; >+ >+ ready = keyval = 0; >+ if (sscanf(keybuf, " hotkey_ready : %i hotkey : %i", &ready, &keyval) && ready) { >+ return keyval; >+ } >+ >+ return 0; >+} >+ >+static int get_value(const char *filename, const char *thing) >+{ >+ int fd = open(filename, O_RDONLY); >+ char buf[256]; >+ int n; >+ >+ if (fd < 0) >+ return -1; >+ >+ n = read(fd, buf, sizeof(buf)); >+ close(fd); >+ >+ if (n < 0) >+ return -1; >+ >+ buf[n] = '\0'; >+ >+ if (sscanf(buf, thing, &n)) { >+ return n; >+ } >+ >+ return -1; >+} >+ >+static void set_value(const char *filename, const char *thing, int val) >+{ >+ int fd = open(filename, O_WRONLY); >+ char buf[256]; >+ int n; >+ >+ if (fd < 0) >+ return; >+ >+ n = sprintf(buf, thing, val); >+ write(fd, buf, n); >+ close(fd); >+} >+ >+ >+/* probe for, and flush, toshiba key queue */ >+int flush_tosh(void) >+{ >+ int t; >+ >+ t = open(toshiba_keys, O_RDONLY); >+ if (t < 0) >+ return 0; >+ >+ fprintf(stderr, "%s: opened %s: will handle hotkey events\n", progname, >+ toshiba_keys); >+ >+ /* now, we need to flush that queue */ >+ close(t); >+ >+ while (tosh_get_key()) >+ ; >+ >+ return 1; >+} >+ >+static void update_proc_title(void) >+{ >+ if (pow.mins == -1) { >+ setproctitle("%s [%s full %d%%]", progname, pow.batname, pow.pct); >+ } else { >+ setproctitle("%s [%s %d:%d %d%%%s]", progname, pow.batname, pow.hours, >+ pow.mins, pow.pct, pow.remain < pow.capwarn ? " ***" : ""); >+ } >+} >+ >+static void check_power_status(void) >+{ >+ char buf[1024]; >+ int fd, n; >+ int rate = 0; >+ int voltage = 0; >+ double time_left; >+ char present[16]; >+ char capstate[16], chgstate[16]; >+ >+ sprintf(buf, ACPI_BAT_STATE, pow.batname); >+ fd = open(buf, O_RDONLY); >+ if (fd < 0) >+ return; >+ >+ n = read(fd, buf, sizeof(buf)); >+ buf[n] = 0; >+ close(fd); >+ >+ sscanf(buf, "present: %s capacity state: %s charging state: %s " >+ "present rate: %i mW remaining capacity: %i mWh " >+ "present voltage: %i mV", >+ present, capstate, chgstate, &rate, &pow.remain, &voltage); >+ >+ if (rate == 0) { >+ pow.hours = pow.mins = -1; >+ pow.pct = -1; >+ } else { >+ time_left = (double)pow.remain / (double)rate; >+ pow.hours = (int)time_left; >+ pow.mins = (time_left - pow.hours) * 60; >+ pow.pct = -2; >+ } >+ >+ sprintf(buf, ACPI_BAT_INFO, pow.batname); >+ fd = open(buf, O_RDONLY); >+ if (fd >= 0) { >+ n = read(fd, buf, sizeof(buf)); >+ buf[n] = 0; >+ close(fd); >+ >+ sscanf(buf, "present: %s design capacity: %i mWh " >+ "last full capacity: %i mWh battery technology: %s " >+ "design voltage: %i mV design capacity warning: %i mWh ", >+ present, &pow.dcap, &pow.fullcap, capstate /* ignored */, >+ &voltage, &pow.capwarn); >+ >+ pow.pct = (pow.remain * 100) / pow.fullcap; >+ } >+ >+ update_proc_title(); >+ >+ /* if we are at or below the capwarn level, we are going to >+ * initiate a shutdown */ >+ if (rate && pow.remain < pow.capwarn && time(NULL) >= pow.last_warn + 60) { >+ time(&pow.last_warn); >+ acpid_handle_event("critical low power"); >+ } else if (rate && pow.hours == 0 && pow.mins <= 15) { >+ /* if there is less than 15 minutes power, send a warning >+ * event. Repeat this warning every 5 minutes until we >+ * hit the capwarn level */ >+ if (pow.mins == 15 || time(NULL) >= pow.last_warn + (5 * 60)) { >+ >+ /* turn down the brightness one notch */ >+ if (access(ACPI_TOSHIBA_LCD, R_OK|W_OK) == 0) >+ set_value(ACPI_TOSHIBA_LCD, "brightness:%i", get_value(ACPI_TOSHIBA_LCD, " brightness : %i") - 1); >+ >+ sprintf(buf, "warning power %d %d", pow.mins, pow.pct); >+ acpid_handle_event(buf); >+ } >+ time(&pow.last_warn); >+ } >+} >+ >+static void acpid_check_power_event(const char *event) >+{ >+ if (!sscanf(event, "battery %s", pow.batname)) >+ return; >+ check_power_status(); >+} >+ >+static void handle_key(int keycode) >+{ >+ char keybuf[64]; >+ >+ switch (keycode) { >+ case 0x0140: /* bright down */ >+ if (access(ACPI_TOSHIBA_LCD, R_OK|W_OK) == 0) >+ set_value(ACPI_TOSHIBA_LCD, "brightness:%i", get_value(ACPI_TOSHIBA_LCD, " brightness : %i") - 1); >+ break; >+ >+ case 0x0141: /* bright up */ >+ if (access(ACPI_TOSHIBA_LCD, R_OK|W_OK) == 0) >+ set_value(ACPI_TOSHIBA_LCD, "brightness:%i", get_value(ACPI_TOSHIBA_LCD, " brightness : %i") + 1); >+ break; >+ >+ default: >+ /* format it into a button event */ >+ sprintf(keybuf, "button/toshiba 0x%04x", keycode); >+ acpid_log("received event \"%s\"\n", keybuf); >+ acpid_handle_event(keybuf); >+ //acpid_log("completed event \"%s\"\n", keybuf); >+ } >+} >+ > int > main(int argc, char **argv) > { > int event_fd; > int sock_fd; >+ int have_tosh; > > /* learn who we really are */ >+ initproctitle(argc, argv); > progname = (const char *)strrchr(argv[0], '/'); >- progname = progname ? (progname + 1) : argv[0]; >+ progname = strdup(progname ? (progname + 1) : argv[0]); > > /* handle the commandline */ > handle_cmdline(&argc, &argv); >@@ -111,6 +343,9 @@ > } > #endif > >+ /* for toshiba keys */ >+ have_tosh = flush_tosh(); >+ > /* open our socket */ > if (!nosocket) { > sock_fd = ud_create_socket(socketfile); >@@ -177,7 +412,7 @@ > if (!nosocket) { > ar[1].fd = sock_fd; ar[1].events = POLLIN; fds++; > } >- r = poll(ar, fds, -1); >+ r = poll(ar, fds, have_tosh >= 0 ? 200 : -1); > > if (r < 0 && errno == EINTR) { > continue; >@@ -201,8 +436,9 @@ > event = read_line(event_fd); > if (event) { > acpid_log("received event \"%s\"\n", event); >+ acpid_check_power_event(event); > acpid_handle_event(event); >- acpid_log("completed event \"%s\"\n", event); >+ //acpid_log("completed event \"%s\"\n", event); > } else { > static int nerrs; > if (++nerrs >= ACPI_MAX_ERRS) { >@@ -237,6 +473,15 @@ > creds.pid, creds.uid, creds.gid); > acpid_add_client(cli_fd, buf); > } >+ >+ /* was it a toshiba key ? */ >+ if (have_tosh) { >+ int keyval; >+ >+ while ((keyval = tosh_get_key())) { >+ handle_key(keyval); >+ } >+ } > } > > clean_exit(EXIT_SUCCESS); >diff -u -r -N acpid-1.0.3/acpid.h acpid-1.0.3-wez/acpid.h >--- acpid-1.0.3/acpid.h 2001-08-17 19:30:31.000000000 +0100 >+++ acpid-1.0.3-wez/acpid.h 2004-06-21 10:43:31.563792840 +0100 >@@ -30,9 +30,15 @@ > > #define ACPI_PROCDIR "/proc/acpi" > #define ACPI_EVENTFILE ACPI_PROCDIR "/event" >+#define ACPI_TOSHIBA_KEYS ACPI_PROCDIR "/toshiba/keys" > #define ACPI_CONFDIR "/etc/acpi/events" > #define ACPI_LOGFILE "/var/log/acpid" > #define ACPI_SOCKETFILE "/var/run/acpid.socket" >+ >+#define ACPI_BAT_STATE "/proc/acpi/battery/%s/state" >+#define ACPI_BAT_INFO "/proc/acpi/battery/%s/info" >+#define ACPI_TOSHIBA_LCD "/proc/acpi/toshiba/lcd" >+ > #define ACPI_SOCKETMODE 0666 > #define ACPI_MAX_ERRS 5 > >@@ -44,6 +50,10 @@ > extern int acpid_debug; > extern int acpid_log(const char *fmt, ...); > >+/* setproctitle.c */ >+void setproctitle (const char *fmt,...); >+void initproctitle (int argc, char **argv); >+ > /* > * event.c > */ >Binary files acpid-1.0.3/acpid.o and acpid-1.0.3-wez/acpid.o differ >Binary files acpid-1.0.3/acpi_listen and acpid-1.0.3-wez/acpi_listen differ >Binary files acpid-1.0.3/acpi_listen.8.gz and acpid-1.0.3-wez/acpi_listen.8.gz differ >Binary files acpid-1.0.3/acpi_listen.o and acpid-1.0.3-wez/acpi_listen.o differ >Binary files acpid-1.0.3/event.o and acpid-1.0.3-wez/event.o differ >diff -u -r -N acpid-1.0.3/Makefile acpid-1.0.3-wez/Makefile >--- acpid-1.0.3/Makefile 2004-02-24 23:52:37.000000000 +0000 >+++ acpid-1.0.3-wez/Makefile 2004-06-21 09:45:59.363607040 +0100 >@@ -12,7 +12,7 @@ > BIN_PROGS = acpi_listen > PROGS = $(SBIN_PROGS) $(BIN_PROGS) > >-acpid_SRCS = acpid.c event.c ud_socket.c >+acpid_SRCS = acpid.c event.c ud_socket.c setproctitle.c > acpid_OBJS = $(acpid_SRCS:.c=.o) > > acpi_listen_SRCS = acpi_listen.c ud_socket.c >diff -u -r -N acpid-1.0.3/setproctitle.c acpid-1.0.3-wez/setproctitle.c >--- acpid-1.0.3/setproctitle.c 1970-01-01 01:00:00.000000000 +0100 >+++ acpid-1.0.3-wez/setproctitle.c 2004-06-21 09:46:45.283626136 +0100 >@@ -0,0 +1,109 @@ >+/* proctitle code - we know this to work only on linux... */ >+ >+/* >+** SETPROCTITLE -- set process title for ps (from sendmail) >+** >+** Parameters: >+** fmt -- a printf style format string. >+** >+** Returns: >+** none. >+** >+** Side Effects: >+** Clobbers argv of our main procedure so ps(1) will >+** display the title. >+*/ >+ >+#include <stdio.h> >+#include <stdlib.h> >+#include <string.h> >+#include <stdarg.h> >+#include "acpid.h" >+ >+#ifndef SPT_BUFSIZE >+#define SPT_BUFSIZE 2048 >+#endif >+ >+extern char** environ; >+ >+static char** argv0; >+static int argv_lth; >+ >+void >+initproctitle (int argc, char **argv) { >+ int i; >+ char **envp = environ; >+ >+ /* >+ * Move the environment so we can reuse the memory. >+ * (Code borrowed from sendmail.) >+ * WARNING: ugly assumptions on memory layout here; >+ * if this ever causes problems, #undef DO_PS_FIDDLING >+ */ >+ for (i = 0; envp[i] != NULL; i++) >+ continue; >+ environ = (char **) malloc(sizeof(char *) * (i + 1)); >+ if (environ == NULL) >+ return; >+ for (i = 0; envp[i] != NULL; i++) >+ if ((environ[i] = strdup(envp[i])) == NULL) >+ return; >+ environ[i] = NULL; >+ >+ argv0 = argv; >+ if (i > 0) >+ argv_lth = envp[i-1] + strlen(envp[i-1]) - argv0[0]; >+ else >+ argv_lth = argv0[argc-1] + strlen(argv0[argc-1]) - argv0[0]; >+} >+ >+#if 1 >+/* Nice code, but many places do not know about vsnprintf ... */ >+void >+setproctitle (const char *fmt,...) { >+ int i; >+ char buf[SPT_BUFSIZE]; >+ va_list ap; >+ >+ if (!argv0) >+ return; >+ >+ va_start(ap, fmt); >+ (void) vsnprintf(buf, SPT_BUFSIZE, fmt, ap); >+ va_end(ap); >+ >+ i = strlen (buf); >+ if (i > argv_lth - 2) { >+ i = argv_lth - 2; >+ buf[i] = '\0'; >+ } >+ memset(argv0[0], '\0', argv_lth); /* clear the memory area */ >+ (void) strcpy (argv0[0], buf); >+ >+ argv0[1] = NULL; >+} >+#else >+void >+setproctitle (const char *prog, const char *txt) { >+ int i; >+ char buf[SPT_BUFSIZE]; >+ >+ if (!argv0) >+ return; >+ >+ if (strlen(prog) + strlen(txt) + 5 > SPT_BUFSIZE) >+ return; >+ >+ (void) sprintf(buf, "%s -- %s", prog, txt); >+ >+ i = strlen (buf); >+ if (i > argv_lth - 2) { >+ i = argv_lth - 2; >+ buf[i] = '\0'; >+ } >+ memset(argv0[0], '\0', argv_lth); /* clear the memory area */ >+ (void) strcpy (argv0[0], buf); >+ >+ argv0[1] = NULL; >+} >+#endif >Binary files acpid-1.0.3/setproctitle.o and acpid-1.0.3-wez/setproctitle.o differ >Binary files acpid-1.0.3/ud_socket.o and acpid-1.0.3-wez/ud_socket.o differ
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 55648
:
34473
| 34474 |
34475