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

« back to all changes in this revision

Viewing changes to splash.c

  • 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:
14
14
#include <stdlib.h>
15
15
#include <unistd.h>
16
16
#include <termios.h>
 
17
#include <limits.h>
 
18
#include <dirent.h>
 
19
#include <string.h>
 
20
#include <fcntl.h>
 
21
#include <errno.h>
 
22
#include <sys/types.h>
 
23
#include <sys/types.h>
 
24
#include <sys/stat.h>
17
25
 
18
26
#include "splash.h"
19
27
#include "bootsplash.h"
21
29
#include "fbsplash_funcs.h"
22
30
#include "encrypt.h"
23
31
 
 
32
#define INPUT_PATH "/dev/input/by-path"
 
33
#define MAX_INPUT_FD 8
 
34
static struct {
 
35
        int fds[MAX_INPUT_FD];
 
36
        int count;
 
37
        int highest;
 
38
} input_fds;
 
39
 
 
40
struct splash splash;
 
41
 
24
42
/**
25
43
 *      dummy functions in case if no splash system was found or
26
44
 *      bootsplashing is disabled
32
50
#ifndef CONFIG_ENCRYPT
33
51
static void splash_dummy_readpass(char *a, int b) { }
34
52
#endif
 
53
 
35
54
static int splash_dialog(const char *prompt) 
36
55
{
37
56
        printf(prompt);
38
57
        return getchar();
39
58
}
 
59
 
40
60
static int prepare_abort(struct termios *oldtrm, struct termios *newtrm) 
41
61
{
42
62
        int ret;
54
74
        return ret;
55
75
}
56
76
 
 
77
static char simple_key_pressed(void)
 
78
{
 
79
        char c;
 
80
 
 
81
        if (read(0, &c, 1) == 0)
 
82
                return 0;
 
83
 
 
84
        switch (c) {
 
85
        case 127:
 
86
                return KEY_BACKSPACE;
 
87
        case 'r':
 
88
                return KEY_R;
 
89
        case '\n':
 
90
                return KEY_ENTER;
 
91
        }
 
92
 
 
93
        return 0;
 
94
}
 
95
 
57
96
static char key_pressed(void)
58
97
{
59
 
        char c;
60
 
        if (read(0, &c, 1) == 0) 
61
 
                return 0;
62
 
 
63
 
        return c;
 
98
        int err, i, active;
 
99
        struct input_event ev;
 
100
        struct timeval timeout = {0, 0};
 
101
        fd_set fds;
 
102
 
 
103
        if (!input_fds.count)
 
104
                return 0;
 
105
 
 
106
        active = -1; /* GCC STFU */
 
107
        FD_ZERO(&fds);
 
108
        for (i = 0; i < input_fds.count; i++)
 
109
                FD_SET(input_fds.fds[i], &fds);
 
110
 
 
111
        err = select(input_fds.highest + 1, &fds, NULL, NULL, &timeout);
 
112
        if (err <= 0) {
 
113
                if (err < 0)
 
114
                        perror("select() failed");
 
115
                return 0;
 
116
        }
 
117
 
 
118
        /* Get only the fist active fd */
 
119
        for (i = 0; i < input_fds.count; i++) {
 
120
                if (FD_ISSET(input_fds.fds[i], &fds)) {
 
121
                        active = input_fds.fds[i];
 
122
                        break;
 
123
                }
 
124
        }
 
125
 
 
126
        while ((err = read(active, &ev, sizeof(ev))) != -1) {
 
127
                /* we only need key release events */
 
128
                if (ev.type == EV_KEY && ev.value == 0)
 
129
                        return ev.code;
 
130
        }
 
131
 
 
132
        return 0;
64
133
}
65
134
 
66
135
static void restore_abort(struct termios *oldtrm) 
68
137
        tcsetattr(0, TCSANOW, oldtrm);
69
138
}
70
139
 
 
140
static int open_input_fd(void)
 
141
{
 
142
        int fd, i;
 
143
        struct dirent *it;
 
144
        DIR *dir;
 
145
        char input_dev[PATH_MAX];
 
146
        int err = 0;
 
147
 
 
148
        if (!(dir = opendir(INPUT_PATH))) {
 
149
                perror("Cannot open input directory");
 
150
                return -EIO;
 
151
        }
 
152
 
 
153
        i = 0;
 
154
        errno = 0;
 
155
        while ((it = readdir(dir))) {
 
156
                if (i >= MAX_INPUT_FD)
 
157
                        break;
 
158
 
 
159
                if (!strstr(it->d_name, "-event-kbd"))
 
160
                        continue;
 
161
 
 
162
                snprintf(input_dev, PATH_MAX, "%s/%s", INPUT_PATH, it->d_name);
 
163
 
 
164
                fd = open(input_dev, O_RDONLY | O_NONBLOCK);
 
165
                if (fd < 0) {
 
166
                        perror("Unable to open input fd");
 
167
                        continue;
 
168
                }
 
169
                input_fds.fds[i++] = fd;
 
170
                input_fds.count++;
 
171
                if (fd > input_fds.highest)
 
172
                        input_fds.highest = fd;
 
173
        }
 
174
 
 
175
        if (!it && errno) {
 
176
                perror("readdir() failed");
 
177
                err = -errno;
 
178
        }
 
179
 
 
180
        closedir(dir);
 
181
 
 
182
        if (err)
 
183
                fprintf(stderr, "Could not open keyboard input device\n");
 
184
 
 
185
        return err;
 
186
}
 
187
 
71
188
/* Tries to find a splash system and initializes interface functions */
72
189
void splash_prepare(struct splash *splash, int mode)
73
190
{
82
199
#endif
83
200
        splash->prepare_abort   = prepare_abort;
84
201
        splash->restore_abort   = restore_abort;
85
 
        splash->key_pressed     = key_pressed;
 
202
        splash->key_pressed     = simple_key_pressed;
86
203
        splash->set_caption     = splash_dummy_set_caption;
 
204
 
87
205
        if (!mode)
88
206
                return;
89
207
 
95
213
                splash->switch_to   = bootsplash_switch_to;
96
214
                splash->dialog      = bootsplash_dialog;
97
215
                splash->read_password = bootsplash_read_password;
 
216
                if (!open_input_fd())
 
217
                        splash->key_pressed = key_pressed;
98
218
#ifdef CONFIG_FBSPLASH
99
219
        } else if (!fbsplashfuncs_open(mode)) {
100
220
                splash->finish      = fbsplashfuncs_finish;
110
230
                splash->progress    = splashy_progress;
111
231
                splash->dialog      = splashy_dialog;
112
232
                splash->read_password   = splashy_read_password;
 
233
                if (!open_input_fd())
 
234
                        splash->key_pressed = key_pressed;
113
235
#endif
114
236
        } else if (0) {
115
237
                /* add another splash system here */
116
238
        } else {
117
239
                printf("none\n");
 
240
                if (!open_input_fd())
 
241
                        splash->key_pressed = key_pressed;
118
242
                return;
119
243
        }
120
244
        printf("found\n");