OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // This is a small program that tries to connect to the X server. It | 5 // This is a small program that tries to connect to the X server. It |
6 // continually retries until it connects or 30 seconds pass. If it fails | 6 // continually retries until it connects or 30 seconds pass. If it fails |
7 // to connect to the X server or fails to find needed functiona, it returns | 7 // to connect to the X server or fails to find needed functiona, it returns |
8 // an error code of -1. | 8 // an error code of -1. |
9 // | 9 // |
10 // This is to help verify that a useful X server is available before we start | 10 // This is to help verify that a useful X server is available before we start |
(...skipping 23 matching lines...) Expand all Loading... | |
34 sleep_time = remaining; | 34 sleep_time = remaining; |
35 } | 35 } |
36 | 36 |
37 int main(int argc, char* argv[]) { | 37 int main(int argc, char* argv[]) { |
38 Display* display = NULL; | 38 Display* display = NULL; |
39 if (argv[1] && strcmp(argv[1], "--noserver") == 0) { | 39 if (argv[1] && strcmp(argv[1], "--noserver") == 0) { |
40 display = XOpenDisplay(NULL); | 40 display = XOpenDisplay(NULL); |
41 if (display) { | 41 if (display) { |
42 fprintf(stderr, "Found unexpected connectable display %s\n", | 42 fprintf(stderr, "Found unexpected connectable display %s\n", |
43 XDisplayName(NULL)); | 43 XDisplayName(NULL)); |
44 XCloseDisplay(display); | |
44 } | 45 } |
45 // Return success when we got an unexpected display so that the code | 46 // Return success when we got an unexpected display so that the code |
46 // without the --noserver is the same, but slow, rather than inverted. | 47 // without the --noserver is the same, but slow, rather than inverted. |
47 return !display; | 48 return !display; |
48 } | 49 } |
49 | 50 |
50 int kNumTries = 78; // 78*77/2 * 10 = 30s of waiting | 51 int kNumTries = 78; // 78*77/2 * 10 = 30s of waiting |
51 int tries; | 52 int tries; |
52 for (tries = 0; tries < kNumTries; ++tries) { | 53 for (tries = 0; tries < kNumTries; ++tries) { |
53 display = XOpenDisplay(NULL); | 54 display = XOpenDisplay(NULL); |
54 if (display) | 55 if (display) |
55 break; | 56 break; |
56 Sleep(10 * tries); | 57 Sleep(10 * tries); |
57 } | 58 } |
58 | 59 |
59 if (!display) { | 60 if (!display) { |
60 fprintf(stderr, "Failed to connect to %s\n", XDisplayName(NULL)); | 61 fprintf(stderr, "Failed to connect to %s\n", XDisplayName(NULL)); |
61 return -1; | 62 return -1; |
62 } | 63 } |
63 | 64 |
64 fprintf(stderr, "Connected after %d retries\n", tries); | 65 fprintf(stderr, "Connected after %d retries\n", tries); |
65 | 66 |
66 #if defined(USE_AURA) | 67 #if defined(USE_AURA) |
67 // Check for XInput2 | 68 // Check for XInput2 |
68 int opcode, event, err; | 69 int opcode, event, err; |
69 if (!XQueryExtension(display, "XInputExtension", &opcode, &event, &err)) { | 70 if (!XQueryExtension(display, "XInputExtension", &opcode, &event, &err)) { |
70 fprintf(stderr, | 71 fprintf(stderr, |
71 "Failed to get XInputExtension on %s.\n", XDisplayName(NULL)); | 72 "Failed to get XInputExtension on %s.\n", XDisplayName(NULL)); |
72 return -1; | 73 return -1; |
sadrul
2013/07/04 13:51:39
For completeness, you should XCloseDisplay(display
| |
73 } | 74 } |
74 | 75 |
75 int major = 2, minor = 0; | 76 int major = 2, minor = 0; |
76 if (XIQueryVersion(display, &major, &minor) == BadRequest) { | 77 if (XIQueryVersion(display, &major, &minor) == BadRequest) { |
77 fprintf(stderr, | 78 fprintf(stderr, |
78 "Server does not have XInput2 on %s.\n", XDisplayName(NULL)); | 79 "Server does not have XInput2 on %s.\n", XDisplayName(NULL)); |
79 return -1; | 80 return -1; |
80 } | 81 } |
81 | 82 |
82 // Ask for the list of devices. This can cause some Xvfb to crash. | 83 // Ask for the list of devices. This can cause some Xvfb to crash. |
83 int count = 0; | 84 int count = 0; |
84 XIDeviceInfo* devices = XIQueryDevice(display, XIAllDevices, &count); | 85 XIDeviceInfo* devices = XIQueryDevice(display, XIAllDevices, &count); |
85 if (devices) | 86 if (devices) |
86 XIFreeDeviceInfo(devices); | 87 XIFreeDeviceInfo(devices); |
87 | 88 |
88 fprintf(stderr, | 89 fprintf(stderr, |
89 "XInput2 verified initially sane on %s.\n", XDisplayName(NULL)); | 90 "XInput2 verified initially sane on %s.\n", XDisplayName(NULL)); |
90 #endif | 91 #endif |
91 | 92 if (display) |
93 XCloseDisplay(display); | |
92 return 0; | 94 return 0; |
93 } | 95 } |
OLD | NEW |