OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 // |
| 5 // This is a small program that tries to connect to the X server. It |
| 6 // continually retries until it connects or 5 seconds pass. If it fails |
| 7 // to connect to the X server after 5 seconds, it returns an error code |
| 8 // of -1. |
| 9 // |
| 10 // This is to help verify that the X server is available before we start |
| 11 // start running tests on the build bots. |
| 12 |
| 13 #include <errno.h> |
| 14 #include <stdio.h> |
| 15 #include <time.h> |
| 16 #include <X11/Xlib.h> |
| 17 |
| 18 void Sleep(int duration_ms) { |
| 19 struct timespec sleep_time, remaining; |
| 20 |
| 21 // Contains the portion of duration_ms >= 1 sec. |
| 22 sleep_time.tv_sec = duration_ms / 1000; |
| 23 duration_ms -= sleep_time.tv_sec * 1000; |
| 24 |
| 25 // Contains the portion of duration_ms < 1 sec. |
| 26 sleep_time.tv_nsec = duration_ms * 1000 * 1000; // nanoseconds. |
| 27 |
| 28 while (nanosleep(&sleep_time, &remaining) == -1 && errno == EINTR) |
| 29 sleep_time = remaining; |
| 30 } |
| 31 |
| 32 int main(int argc, char* argv[]) { |
| 33 int kNumTries = 50; |
| 34 for (int i = 0; i < kNumTries; ++i) { |
| 35 Display* display = XOpenDisplay(NULL); |
| 36 if (display) |
| 37 return 0; |
| 38 Sleep(100); |
| 39 } |
| 40 |
| 41 printf("Failed to connect to %s\n", XDisplayName(NULL)); |
| 42 return -1; |
| 43 } |
OLD | NEW |