From: przanoni@gmail.com Subject: [gpu-tools 4/7] testdisplay: don't enter the main loop if dump_info or test_all_modes Date: Thu, 15 Sep 2011 15:14:18 -0300 Message-ID: <1316110458-19133-1-git-send-email-przanoni@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail-yx0-f177.google.com (mail-yx0-f177.google.com [209.85.213.177]) by gabe.freedesktop.org (Postfix) with ESMTP id 6A8229F687 for ; Thu, 15 Sep 2011 11:14:31 -0700 (PDT) Received: by yxi11 with SMTP id 11so2665416yxi.36 for ; Thu, 15 Sep 2011 11:14:30 -0700 (PDT) List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: intel-gfx-bounces+gcfxdi-intel-gfx=m.gmane.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+gcfxdi-intel-gfx=m.gmane.org@lists.freedesktop.org To: intel-gfx@lists.freedesktop.org Cc: Paulo Zanoni List-Id: intel-gfx@lists.freedesktop.org From: Paulo Zanoni If calls inside update_display fail, the function returns and we don't quit the program if dump_info or test_all_modes. So we enter the main loop and keep waiting for user input, even on cases where we are not supposed to require user input. To fix this, we move the check to outside the update_display function. As a side effect, we also do cleanup instead of just exit(0) and we return 1 in case update_display failed. Signed-off-by: Paulo Zanoni --- tests/testdisplay.c | 18 ++++++++++++------ 1 files changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/testdisplay.c b/tests/testdisplay.c index cae04e9..69dbf42 100644 --- a/tests/testdisplay.c +++ b/tests/testdisplay.c @@ -909,7 +909,7 @@ set_mode(struct connector *c) * Each connector has a corresponding encoder, except in the SDVO case * where an encoder may have multiple connectors. */ -static void update_display(void) +static int update_display(void) { struct connector *connectors; int c; @@ -918,13 +918,13 @@ static void update_display(void) if (!resources) { fprintf(stderr, "drmModeGetResources failed: %s\n", strerror(errno)); - return; + return 0; } connectors = calloc(resources->count_connectors, sizeof(struct connector)); if (!connectors) - return; + return 0; if (dump_info) { dump_connectors(); @@ -940,8 +940,7 @@ static void update_display(void) } } drmModeFreeResources(resources); - if (dump_info || test_all_modes) - exit(0); + return 1; } extern char *optarg; @@ -1138,7 +1137,14 @@ int main(int argc, char **argv) goto out_stdio_off; } - update_display(); + if (!update_display()) { + ret = 1; + goto out_stdio_off; + } + + if (dump_info || test_all_modes) + goto out_stdio_off; + g_main_loop_run(mainloop); out_stdio_off: -- 1.7.4.1