Chromium Code Reviews| 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 |
| 11 // start running tests on the build bots. | 11 // start running tests on the build bots. |
| 12 | 12 |
| 13 #include <errno.h> | 13 #include <errno.h> |
| 14 #include <stdio.h> | 14 #include <stdio.h> |
| 15 #include <string.h> | |
| 15 #include <time.h> | 16 #include <time.h> |
| 16 #include <X11/Xlib.h> | 17 #include <X11/Xlib.h> |
| 17 | 18 |
| 18 #if defined(USE_AURA) | 19 #if defined(USE_AURA) |
| 19 #include <X11/extensions/XInput2.h> | 20 #include <X11/extensions/XInput2.h> |
| 20 #endif | 21 #endif |
| 21 | 22 |
| 22 void Sleep(int duration_ms) { | 23 void Sleep(int duration_ms) { |
| 23 struct timespec sleep_time, remaining; | 24 struct timespec sleep_time, remaining; |
| 24 | 25 |
| 25 // Contains the portion of duration_ms >= 1 sec. | 26 // Contains the portion of duration_ms >= 1 sec. |
| 26 sleep_time.tv_sec = duration_ms / 1000; | 27 sleep_time.tv_sec = duration_ms / 1000; |
| 27 duration_ms -= sleep_time.tv_sec * 1000; | 28 duration_ms -= sleep_time.tv_sec * 1000; |
| 28 | 29 |
| 29 // Contains the portion of duration_ms < 1 sec. | 30 // Contains the portion of duration_ms < 1 sec. |
| 30 sleep_time.tv_nsec = duration_ms * 1000 * 1000; // nanoseconds. | 31 sleep_time.tv_nsec = duration_ms * 1000 * 1000; // nanoseconds. |
| 31 | 32 |
| 32 while (nanosleep(&sleep_time, &remaining) == -1 && errno == EINTR) | 33 while (nanosleep(&sleep_time, &remaining) == -1 && errno == EINTR) |
| 33 sleep_time = remaining; | 34 sleep_time = remaining; |
| 34 } | 35 } |
| 35 | 36 |
| 36 int main(int argc, char* argv[]) { | 37 int main(int argc, char* argv[]) { |
| 38 Display* display = NULL; | |
| 39 if (argv[1] && strcmp(argv[1], "--noserver")==0) { | |
|
cmp
2012/05/18 20:05:24
spaces around ==
Peter Mayo
2012/05/18 20:25:44
Done.
| |
| 40 display = XOpenDisplay(NULL); | |
| 41 if (display) { | |
| 42 fprintf(stderr, "Found unexpected connectable display %s\n", | |
| 43 XDisplayName(NULL)); | |
| 44 } | |
| 45 // Use upside down logic to resemble previous behaviour. | |
|
cmp
2012/05/18 20:05:24
can you change this comment to be more explicit ab
Peter Mayo
2012/05/18 20:25:44
Better?
| |
| 46 return !display; | |
| 47 } | |
| 48 | |
| 37 int kNumTries = 78; // 78*77/2 * 10 = 30s of waiting | 49 int kNumTries = 78; // 78*77/2 * 10 = 30s of waiting |
| 38 Display* display = NULL; | |
| 39 int tries; | 50 int tries; |
| 40 for (tries = 0; tries < kNumTries; ++tries) { | 51 for (tries = 0; tries < kNumTries; ++tries) { |
| 41 display = XOpenDisplay(NULL); | 52 display = XOpenDisplay(NULL); |
| 42 if (display) | 53 if (display) |
| 43 break; | 54 break; |
| 44 Sleep(10 * tries); | 55 Sleep(10 * tries); |
| 45 } | 56 } |
| 46 | 57 |
| 47 if (!display) { | 58 if (!display) { |
| 48 fprintf(stderr, "Failed to connect to %s\n", XDisplayName(NULL)); | 59 fprintf(stderr, "Failed to connect to %s\n", XDisplayName(NULL)); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 72 XIDeviceInfo* devices = XIQueryDevice(display, XIAllDevices, &count); | 83 XIDeviceInfo* devices = XIQueryDevice(display, XIAllDevices, &count); |
| 73 if (devices) | 84 if (devices) |
| 74 XIFreeDeviceInfo(devices); | 85 XIFreeDeviceInfo(devices); |
| 75 | 86 |
| 76 fprintf(stderr, | 87 fprintf(stderr, |
| 77 "XInput2 verified initially sane on %s.\n", XDisplayName(NULL)); | 88 "XInput2 verified initially sane on %s.\n", XDisplayName(NULL)); |
| 78 #endif | 89 #endif |
| 79 | 90 |
| 80 return 0; | 91 return 0; |
| 81 } | 92 } |
| OLD | NEW |