]>
Commit | Line | Data |
---|---|---|
6d313fb4 | 1 | From: William Jon McCann <mccann@jhu.edu> |
2 | Date: Tue, 15 May 2007 15:15:12 +0000 (-0400) | |
3 | Subject: a few fixes for getfd suggested by Lennart | |
4 | X-Git-Url: http://gitweb.freedesktop.org/?p=ConsoleKit.git;a=commitdiff;h=17ff9ceb88e0b7f6dc5a7e6eac5ff98cb4a5cabe | |
5 | ||
6 | a few fixes for getfd suggested by Lennart | |
7 | ||
8 | I am currently investigating how to best integrate PulseAudio with | |
9 | ConsoleKit/PolicyKit. While doing that I had a look on your code, and | |
10 | found a few issues in getfd.c I'd like to report, before I forget | |
11 | them. I couldn't find any bugzilla with at consolekit project (neither | |
12 | fedora, nor fdo, nor gnome?) hence I am mailing you in person. | |
13 | ||
14 | In getfd.c in open_a_console() a close() is missing if is_a_console is | |
15 | missing. | |
16 | ||
17 | The open() in open_a_console() should probably use O_NOCTTY. Otherwise | |
18 | C-c on the console might end up in a SIGINT to your daemon process! | |
19 | ||
20 | Also I'd add an isatty() check to is_a_console(), to makes sure that | |
21 | you're actually talking to a TTY before you issue KDGKBTYPE on | |
22 | it. ioctl()s are unfortunately not unique, hence i'd recommend that check. | |
23 | ||
24 | That's it, | |
25 | ||
26 | Lennart | |
27 | --- | |
28 | ||
29 | --- a/src/getfd.c | |
30 | +++ b/src/getfd.c | |
31 | @@ -30,7 +30,8 @@ is_a_console (int fd) | |
32 | char arg; | |
33 | ||
34 | arg = 0; | |
35 | - return (ioctl (fd, KDGKBTYPE, &arg) == 0 | |
36 | + return (isatty (fd) | |
37 | + && ioctl (fd, KDGKBTYPE, &arg) == 0 | |
38 | && ((arg == KB_101) || (arg == KB_84))); | |
39 | } | |
40 | ||
41 | @@ -39,11 +40,18 @@ open_a_console (char *fnam) | |
42 | { | |
43 | int fd; | |
44 | ||
45 | - fd = open (fnam, O_RDONLY); | |
46 | + fd = open (fnam, O_RDONLY | O_NOCTTY); | |
47 | if (fd < 0 && errno == EACCES) | |
48 | - fd = open(fnam, O_WRONLY); | |
49 | - if (fd < 0 || ! is_a_console (fd)) | |
50 | + fd = open (fnam, O_WRONLY | O_NOCTTY); | |
51 | + | |
52 | + if (fd < 0) | |
53 | return -1; | |
54 | + | |
55 | + if (! is_a_console (fd)) { | |
56 | + close (fd); | |
57 | + fd = -1; | |
58 | + } | |
59 | + | |
60 | return fd; | |
61 | } | |
62 |