~ubuntu-branches/debian/stretch/uswsusp/stretch

« back to all changes in this revision

Viewing changes to debian/patches/improved_keypress_handling.patch

  • Committer: Bazaar Package Importer
  • Author(s): Rodolfo García Peñas (kix), Rodolfo García Peñas (kix), Closes: #552484, #576803, #528483, Closes: #495111, #595125, #486352, #433872, #590233, Closes: #550725, #549118, Closes: #437094, #586674, #547158, #567604, Closes: #520705, Anibal Monsalve Salazar
  • Date: 2011-03-14 08:26:16 UTC
  • mfrom: (0.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110314082616-7mjcl6tfzsv22arm
Tags: 1.0-1
[ Rodolfo García Peñas (kix) ]
* New 1.0 version [Closes: #589743, #578496, #617534]
* A lot of new machines. 
  [Closes: #552484, #576803, #528483] 
  [Closes: #495111, #595125, #486352, #433872, #590233] 
* A new length for addressing 
  [Closes: #550725, #549118]
  (http://lkml.org/lkml/2009/11/3/377)
* Support for Kernel Mode Set (KMS) 
  [Closes: #437094, #586674, #547158, #567604]
* Switch to dpkg-source 3.0 (quilt) format
* Compiled without splash support. 
  libsplash is not included in stable, many bugs.
* Moved the manpage file "suspend.conf.8" to manual section 5.
  [Closes: #520705]

[ Anibal Monsalve Salazar ]
* Update uploaders list

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Index: uswsusp-0.8/splash.c
2
 
===================================================================
3
 
--- uswsusp-0.8.orig/splash.c   2007-12-31 19:50:12.000000000 +0100
4
 
+++ uswsusp-0.8/splash.c        2008-07-15 16:52:51.000000000 +0200
5
 
@@ -14,6 +14,15 @@
6
 
 #include <stdlib.h>
7
 
 #include <unistd.h>
8
 
 #include <termios.h>
9
 
+#include <limits.h>
10
 
+#include <dirent.h>
11
 
+#include <string.h>
12
 
+#include <fcntl.h>
13
 
+#include <errno.h>
14
 
+#include <linux/input.h>
15
 
+#include <sys/types.h>
16
 
+#include <sys/types.h>
17
 
+#include <sys/stat.h>
18
 
 
19
 
 #include "splash.h"
20
 
 #include "bootsplash.h"
21
 
@@ -21,6 +30,14 @@
22
 
 #include "fbsplash_funcs.h"
23
 
 #include "encrypt.h"
24
 
 
25
 
+#define INPUT_PATH "/dev/input/by-path"
26
 
+#define MAX_INPUT_FD 8
27
 
+static struct {
28
 
+       int fds[MAX_INPUT_FD];
29
 
+       int count;
30
 
+       int highest;
31
 
+} input_fds;
32
 
+
33
 
 /**
34
 
  *     dummy functions in case if no splash system was found or
35
 
  *     bootsplashing is disabled
36
 
@@ -56,11 +73,42 @@
37
 
 
38
 
 static char key_pressed(void)
39
 
 {
40
 
-       char c;
41
 
-       if (read(0, &c, 1) == 0) 
42
 
+       int err, i, active;
43
 
+       struct input_event ev;
44
 
+       struct timeval timeout = {0, 0};
45
 
+       fd_set fds;
46
 
+
47
 
+       if (!input_fds.count)
48
 
+               return 0;
49
 
+
50
 
+       active = -1; /* GCC STFU */
51
 
+       FD_ZERO(&fds);
52
 
+       for (i = 0; i < input_fds.count; i++)
53
 
+               FD_SET(input_fds.fds[i], &fds);
54
 
+
55
 
+       err = select(input_fds.highest + 1, &fds, NULL, NULL, &timeout);
56
 
+       if (err < 0) {
57
 
+               perror("select()");
58
 
+               return 0;
59
 
+       }
60
 
+       if (err == 0)
61
 
                return 0;
62
 
 
63
 
-       return c;
64
 
+       /* Get only the fist active fd */
65
 
+       for (i = 0; i < input_fds.count; i++) {
66
 
+               if (FD_ISSET(input_fds.fds[i], &fds)) {
67
 
+                       active = input_fds.fds[i];
68
 
+                       break;
69
 
+               }
70
 
+       }
71
 
+
72
 
+       while ((err = read(active, &ev, sizeof(struct input_event))) != -1) {
73
 
+               /* we only need key release events */
74
 
+               if (ev.type == EV_KEY && ev.value == 0)
75
 
+                       return ev.code;
76
 
+       }
77
 
+
78
 
+       return 0;
79
 
 }
80
 
 
81
 
 static void restore_abort(struct termios *oldtrm) 
82
 
@@ -68,6 +116,49 @@
83
 
        tcsetattr(0, TCSANOW, oldtrm);
84
 
 }
85
 
 
86
 
+static int open_input_fd(void)
87
 
+{
88
 
+       int fd, i;
89
 
+       struct dirent *it;
90
 
+       DIR *dir;
91
 
+       char input_dev[PATH_MAX];
92
 
+       int err = 0;
93
 
+
94
 
+       if (!(dir = opendir(INPUT_PATH))) {
95
 
+               perror("Cannot open input directory");
96
 
+               return -1;
97
 
+       }
98
 
+
99
 
+       i = 0;
100
 
+       while ((it = readdir(dir))) {
101
 
+               if (i == MAX_INPUT_FD)
102
 
+                       break;
103
 
+
104
 
+               if (!strstr(it->d_name, "-event-kbd"))
105
 
+                       continue;
106
 
+
107
 
+               sprintf(input_dev, "%s/%s", INPUT_PATH, it->d_name);
108
 
+
109
 
+               fd = open(input_dev, O_RDONLY|O_NONBLOCK);
110
 
+               if (fd == -1) {
111
 
+                       perror("opening input fd");
112
 
+                       continue;
113
 
+               }
114
 
+               input_fds.fds[i++] = fd;
115
 
+               input_fds.count++;
116
 
+               if (fd > input_fds.highest)
117
 
+                       input_fds.highest = fd;
118
 
+       }
119
 
+
120
 
+       if (!it && errno) {
121
 
+               perror("readdir()");
122
 
+               err = -errno;
123
 
+       }
124
 
+       closedir(dir);
125
 
+
126
 
+       return err;
127
 
+}
128
 
+
129
 
 /* Tries to find a splash system and initializes interface functions */
130
 
 void splash_prepare(struct splash *splash, int mode)
131
 
 {
132
 
@@ -84,6 +175,10 @@
133
 
        splash->restore_abort   = restore_abort;
134
 
        splash->key_pressed     = key_pressed;
135
 
        splash->set_caption     = splash_dummy_set_caption;
136
 
+
137
 
+       if (open_input_fd())
138
 
+               fprintf(stderr, "Could not open keyboard input device\n");
139
 
+
140
 
        if (!mode)
141
 
                return;
142
 
 
143
 
Index: uswsusp-0.8/suspend.c
144
 
===================================================================
145
 
--- uswsusp-0.8.orig/suspend.c  2007-12-31 19:50:12.000000000 +0100
146
 
+++ uswsusp-0.8/suspend.c       2008-07-15 16:52:51.000000000 +0200
147
 
@@ -489,7 +489,7 @@
148
 
                       unsigned int nr_pages)
149
 
 {
150
 
        unsigned int m, writeout_rate;
151
 
-       int ret, abort_possible;
152
 
+       int ret, abort_possible, key;
153
 
        struct termios newtrm, savedtrm;
154
 
        int error = 0;
155
 
        char message[SPLASH_GENERIC_MESSAGE_SIZE];
156
 
@@ -530,7 +530,8 @@
157
 
                        printf("\b\b\b\b%3d%%", nr_pages / m);
158
 
                        splash.progress(20 + (nr_pages / m) * 0.75);
159
 
 
160
 
-                       switch (splash.key_pressed()) {
161
 
+                       while ((key = splash.key_pressed()) > 0) {
162
 
+                               switch (key) {
163
 
                                case ABORT_KEY_CODE:
164
 
                                        if (abort_possible) {
165
 
                                                printf(" aborted!\n");
166
 
@@ -545,6 +546,7 @@
167
 
                                        shutdown_method =
168
 
                                                        SHUTDOWN_METHOD_REBOOT;
169
 
                                        break;
170
 
+                               }
171
 
                        }
172
 
                }
173
 
 
174
 
@@ -805,8 +807,8 @@
175
 
                reboot();
176
 
        } else if (shutdown_method == SHUTDOWN_METHOD_PLATFORM) {
177
 
                int ret = platform_enter(snapshot_fd);
178
 
-               if (ret < 0)
179
 
-                       suspend_error("pm_ops->enter failed, calling power_off.");
180
 
+               //if (ret < 0)
181
 
+               //      suspend_error("pm_ops->enter failed, calling power_off.");
182
 
        }
183
 
        power_off();
184
 
        /* Signature is on disk, it is very dangerous to continue now.
185
 
Index: uswsusp-0.8/swsusp.h
186
 
===================================================================
187
 
--- uswsusp-0.8.orig/swsusp.h   2007-12-31 19:50:12.000000000 +0100
188
 
+++ uswsusp-0.8/swsusp.h        2008-07-15 16:52:51.000000000 +0200
189
 
@@ -198,7 +198,7 @@
190
 
 
191
 
 #define SUSPEND_SWAPPINESS     100
192
 
 
193
 
-#define ABORT_KEY_CODE 127
194
 
+#define ABORT_KEY_CODE 14
195
 
 #define ABORT_KEY_NAME "backspace"
196
 
-#define REBOOT_KEY_CODE        'r'
197
 
+#define REBOOT_KEY_CODE        19
198
 
 #define REBOOT_KEY_NAME        "r"