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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/all.gyp ('k') | tools/xdisplaycheck/xdisplaycheck.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/xdisplaycheck/xdisplaycheck.cc
diff --git a/tools/xdisplaycheck/xdisplaycheck.cc b/tools/xdisplaycheck/xdisplaycheck.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b7a975426684b25df39071534941a0f10f17601b
--- /dev/null
+++ b/tools/xdisplaycheck/xdisplaycheck.cc
@@ -0,0 +1,43 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// This is a small program that tries to connect to the X server. It
+// continually retries until it connects or 5 seconds pass. If it fails
+// to connect to the X server after 5 seconds, it returns an error code
+// of -1.
+//
+// This is to help verify that the X server is available before we start
+// start running tests on the build bots.
+
+#include <errno.h>
+#include <stdio.h>
+#include <time.h>
+#include <X11/Xlib.h>
+
+void Sleep(int duration_ms) {
+ struct timespec sleep_time, remaining;
+
+ // Contains the portion of duration_ms >= 1 sec.
+ sleep_time.tv_sec = duration_ms / 1000;
+ duration_ms -= sleep_time.tv_sec * 1000;
+
+ // Contains the portion of duration_ms < 1 sec.
+ sleep_time.tv_nsec = duration_ms * 1000 * 1000; // nanoseconds.
+
+ while (nanosleep(&sleep_time, &remaining) == -1 && errno == EINTR)
+ sleep_time = remaining;
+}
+
+int main(int argc, char* argv[]) {
+ int kNumTries = 50;
+ for (int i = 0; i < kNumTries; ++i) {
+ Display* display = XOpenDisplay(NULL);
+ if (display)
+ return 0;
+ Sleep(100);
+ }
+
+ printf("Failed to connect to %s\n", XDisplayName(NULL));
+ return -1;
+}
« 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