Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Side by Side Diff: tools/xdisplaycheck/xdisplaycheck.cc

Issue 126165: Add a small untility for checking to see if the X server is alive. (Closed)
Patch Set: typo Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/all.gyp ('k') | tools/xdisplaycheck/xdisplaycheck.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 }
OLDNEW
« no previous file with comments | « build/all.gyp ('k') | tools/xdisplaycheck/xdisplaycheck.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698