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

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

Issue 18345020: Correctly release resources in xdisplaycheck. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 16 matching lines...) Expand all
27 sleep_time.tv_sec = duration_ms / 1000; 27 sleep_time.tv_sec = duration_ms / 1000;
28 duration_ms -= sleep_time.tv_sec * 1000; 28 duration_ms -= sleep_time.tv_sec * 1000;
29 29
30 // Contains the portion of duration_ms < 1 sec. 30 // Contains the portion of duration_ms < 1 sec.
31 sleep_time.tv_nsec = duration_ms * 1000 * 1000; // nanoseconds. 31 sleep_time.tv_nsec = duration_ms * 1000 * 1000; // nanoseconds.
32 32
33 while (nanosleep(&sleep_time, &remaining) == -1 && errno == EINTR) 33 while (nanosleep(&sleep_time, &remaining) == -1 && errno == EINTR)
34 sleep_time = remaining; 34 sleep_time = remaining;
35 } 35 }
36 36
37 class XScopedDisplay {
38 public:
39 XScopedDisplay() : display_(NULL) {}
40 ~XScopedDisplay() {
41 if (display_) XCloseDisplay(display_);
42 }
43
44 void set(Display* display) { display_ = display; }
45 Display* display() { return display_; }
46
47 private:
48 Display* display_;
49 };
50
37 int main(int argc, char* argv[]) { 51 int main(int argc, char* argv[]) {
38 Display* display = NULL; 52 XScopedDisplay scoped_display;
39 if (argv[1] && strcmp(argv[1], "--noserver") == 0) { 53 if (argv[1] && strcmp(argv[1], "--noserver") == 0) {
40 display = XOpenDisplay(NULL); 54 scoped_display.set(XOpenDisplay(NULL));
41 if (display) { 55 if (scoped_display.display()) {
42 fprintf(stderr, "Found unexpected connectable display %s\n", 56 fprintf(stderr, "Found unexpected connectable display %s\n",
43 XDisplayName(NULL)); 57 XDisplayName(NULL));
44 } 58 }
45 // Return success when we got an unexpected display so that the code 59 // Return success when we got an unexpected display so that the code
46 // without the --noserver is the same, but slow, rather than inverted. 60 // without the --noserver is the same, but slow, rather than inverted.
47 return !display; 61 return !scoped_display.display();
48 } 62 }
49 63
50 int kNumTries = 78; // 78*77/2 * 10 = 30s of waiting 64 int kNumTries = 78; // 78*77/2 * 10 = 30s of waiting
51 int tries; 65 int tries;
52 for (tries = 0; tries < kNumTries; ++tries) { 66 for (tries = 0; tries < kNumTries; ++tries) {
53 display = XOpenDisplay(NULL); 67 scoped_display.set(XOpenDisplay(NULL));
54 if (display) 68 if (scoped_display.display())
55 break; 69 break;
56 Sleep(10 * tries); 70 Sleep(10 * tries);
57 } 71 }
58 72
59 if (!display) { 73 if (!scoped_display.display()) {
60 fprintf(stderr, "Failed to connect to %s\n", XDisplayName(NULL)); 74 fprintf(stderr, "Failed to connect to %s\n", XDisplayName(NULL));
61 return -1; 75 return -1;
62 } 76 }
63 77
64 fprintf(stderr, "Connected after %d retries\n", tries); 78 fprintf(stderr, "Connected after %d retries\n", tries);
65 79
66 #if defined(USE_AURA) 80 #if defined(USE_AURA)
67 // Check for XInput2 81 // Check for XInput2
68 int opcode, event, err; 82 int opcode, event, err;
69 if (!XQueryExtension(display, "XInputExtension", &opcode, &event, &err)) { 83 if (!XQueryExtension(scoped_display.display(), "XInputExtension", &opcode,
84 &event, &err)) {
70 fprintf(stderr, 85 fprintf(stderr,
71 "Failed to get XInputExtension on %s.\n", XDisplayName(NULL)); 86 "Failed to get XInputExtension on %s.\n", XDisplayName(NULL));
72 return -1; 87 return -1;
73 } 88 }
74 89
75 int major = 2, minor = 0; 90 int major = 2, minor = 0;
76 if (XIQueryVersion(display, &major, &minor) == BadRequest) { 91 if (XIQueryVersion(scoped_display.display(), &major, &minor) == BadRequest) {
77 fprintf(stderr, 92 fprintf(stderr,
78 "Server does not have XInput2 on %s.\n", XDisplayName(NULL)); 93 "Server does not have XInput2 on %s.\n", XDisplayName(NULL));
79 return -1; 94 return -1;
80 } 95 }
81 96
82 // Ask for the list of devices. This can cause some Xvfb to crash. 97 // Ask for the list of devices. This can cause some Xvfb to crash.
83 int count = 0; 98 int count = 0;
84 XIDeviceInfo* devices = XIQueryDevice(display, XIAllDevices, &count); 99 XIDeviceInfo* devices =
100 XIQueryDevice(scoped_display.display(), XIAllDevices, &count);
85 if (devices) 101 if (devices)
86 XIFreeDeviceInfo(devices); 102 XIFreeDeviceInfo(devices);
87 103
88 fprintf(stderr, 104 fprintf(stderr,
89 "XInput2 verified initially sane on %s.\n", XDisplayName(NULL)); 105 "XInput2 verified initially sane on %s.\n", XDisplayName(NULL));
90 #endif 106 #endif
91
92 return 0; 107 return 0;
93 } 108 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698