From patchwork Wed Nov 18 12:40:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marius Vlad X-Patchwork-Id: 7648441 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2F3029F392 for ; Wed, 18 Nov 2015 12:40:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4A0F32062A for ; Wed, 18 Nov 2015 12:40:33 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 5F28620620 for ; Wed, 18 Nov 2015 12:40:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D82926E6ED; Wed, 18 Nov 2015 04:40:31 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTP id D1CD46E6E8 for ; Wed, 18 Nov 2015 04:40:30 -0800 (PST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP; 18 Nov 2015 04:40:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,313,1444719600"; d="scan'208";a="688424013" Received: from mcvlad-wk.rb.intel.com (HELO mcvlad-wk) ([10.237.105.57]) by orsmga003.jf.intel.com with ESMTP; 18 Nov 2015 04:40:30 -0800 Received: by mcvlad-wk (Postfix, from userid 1000) id 62814C0067; Wed, 18 Nov 2015 14:40:39 +0200 (EET) From: marius.c.vlad@intel.com To: intel-gfx@lists.freedesktop.org Date: Wed, 18 Nov 2015 14:40:29 +0200 Message-Id: <1447850429-8303-1-git-send-email-marius.c.vlad@intel.com> X-Mailer: git-send-email 2.6.2 Subject: [Intel-gfx] [PATCH i-g-t] overlay/intel-gpu-overlay X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Marius Vlad Use sigaction() instead of signal() and add SIGINT, SIGTERM to close the overlay window. With this change the overlay window will be destroyed. Signed-off-by: Marius Vlad --- overlay/overlay.c | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/overlay/overlay.c b/overlay/overlay.c index 3c0dbb4..48ba67c 100644 --- a/overlay/overlay.c +++ b/overlay/overlay.c @@ -804,11 +804,19 @@ static void show_gem_objects(struct overlay_context *ctx, struct overlay_gem_obj static int take_snapshot; -static void signal_snapshot(int sig) +static void +signal_snapshot(int sig, siginfo_t *si, void *__unused) { take_snapshot = sig; } +static void +signal_x11_destroy(int sig, siginfo_t *si, void *__unused) +{ + x11_overlay_stop(); + exit(EXIT_SUCCESS); +} + static int get_sample_period(struct config *config) { const char *value; @@ -854,6 +862,7 @@ int main(int argc, char **argv) }; struct overlay_context ctx; struct config config; + struct sigaction sa; int index, sample_period; int daemonize = 1, renice = 0; int i; @@ -898,14 +907,22 @@ int main(int argc, char **argv) ctx.width = 640; ctx.height = 236; ctx.surface = NULL; - if (ctx.surface == NULL) + + if (ctx.surface == NULL) { ctx.surface = x11_overlay_create(&config, &ctx.width, &ctx.height); - if (ctx.surface == NULL) + } + if (ctx.surface == NULL) { + fprintf(stderr, "Failed to create X11 overlay.\n"); ctx.surface = x11_window_create(&config, &ctx.width, &ctx.height); - if (ctx.surface == NULL) + } + if (ctx.surface == NULL) { + fprintf(stderr, "Failed to create X11 window.\n"); ctx.surface = kms_overlay_create(&config, &ctx.width, &ctx.height); - if (ctx.surface == NULL) + } + if (ctx.surface == NULL) { + fprintf(stderr, "Failed to create KMS overlay.\n"); return ENXIO; + } if (daemonize && daemon(0, 0)) return EINVAL; @@ -913,7 +930,20 @@ int main(int argc, char **argv) if (renice && (nice(renice) == -1)) fprintf(stderr, "Could not renice: %s\n", strerror(errno)); - signal(SIGUSR1, signal_snapshot); + sa.sa_flags = SA_SIGINFO; + sigemptyset(&sa.sa_mask); + sa.sa_sigaction = &signal_snapshot; + + if (sigaction(SIGUSR1, &sa, NULL) == -1) { + x11_overlay_stop(); + return EXIT_FAILURE; + } + + sa.sa_sigaction = &signal_x11_destroy; + if (sigaction(SIGINT | SIGTERM, &sa, NULL) == -1) { + x11_overlay_stop(); + return EXIT_FAILURE; + } debugfs_init();