buc 58fba43
From 185c8b182ac6f7fa6a5c69975f9dabdb9af6fce0 Mon Sep 17 00:00:00 2001
buc 58fba43
From: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
buc 58fba43
Date: Mon, 11 Jun 2018 13:34:08 -0300
buc 58fba43
Subject: [PATCH 1/3] fbtv: don't keep a black screen in case of fatal errors
buc 58fba43
buc 58fba43
If something bad happens and fbtv exits, it should restore
buc 58fba43
the VT window, as otherwise the error messages won't be
buc 58fba43
displayed.
buc 58fba43
buc 58fba43
So, be sure to call fb_cleanup() before calling exit().
buc 58fba43
buc 58fba43
Let's also start ncurses later, as this is used only to get
buc 58fba43
keys, and this happens only within the image display loop.
buc 58fba43
buc 58fba43
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
buc 58fba43
---
buc 58fba43
 console/fbtv.c | 16 +++++++++++++---
buc 58fba43
 1 file changed, 13 insertions(+), 3 deletions(-)
buc 58fba43
buc 58fba43
diff --git a/console/fbtv.c b/console/fbtv.c
buc 58fba43
index aba517e4fc8e..33372385b7c6 100644
buc 58fba43
--- a/console/fbtv.c
buc 58fba43
+++ b/console/fbtv.c
buc 58fba43
@@ -279,8 +279,8 @@ fb_initcolors(int fd, int gray)
buc 58fba43
 #endif
buc 58fba43
 	break;
buc 58fba43
     default:
buc 58fba43
-	fprintf(stderr, "Oops: %i bit/pixel ???\n",
buc 58fba43
-		fb_var.bits_per_pixel);
buc 58fba43
+	fb_cleanup();
buc 58fba43
+	fprintf(stderr, "Oops: %i bit/pixel ???\n", fb_var.bits_per_pixel);
buc 58fba43
 	exit(1);
buc 58fba43
     }
buc 58fba43
 
buc 58fba43
@@ -404,6 +404,7 @@ static void do_capture(int from, int to, int tmp_switch)
buc 58fba43
 	if (0 != ng_grabber_setformat(&fmt,1)) {
buc 58fba43
 	    gfmt = fmt;
buc 58fba43
 	    if (NULL == (conv = ng_grabber_findconv(&gfmt,0))) {
buc 58fba43
+		fb_cleanup();
buc 58fba43
 		fprintf(stderr,"can't find useful capture format\n");
buc 58fba43
 		exit(1);
buc 58fba43
 	    }
buc 58fba43
@@ -528,6 +529,7 @@ grabber_init(void)
buc 58fba43
 
buc 58fba43
     drv = ng_vid_open(&ng_dev.video, ng_dev.driver, &screen, 0, &h_drv);
buc 58fba43
     if (NULL == drv) {
buc 58fba43
+	fb_cleanup();
buc 58fba43
 	fprintf(stderr,"no grabber device available\n");
buc 58fba43
 	exit(1);
buc 58fba43
     }
buc 58fba43
@@ -724,7 +726,6 @@ main(int argc, char *argv[])
buc 58fba43
     exit_hook         = do_exit;
buc 58fba43
     fullscreen_hook   = do_fullscreen;
buc 58fba43
 
buc 58fba43
-    tty_init();
buc 58fba43
     memset(&act,0,sizeof(act));
buc 58fba43
     act.sa_handler = ctrlc;
buc 58fba43
     sigemptyset(&act.sa_mask);
buc 58fba43
@@ -770,6 +771,7 @@ main(int argc, char *argv[])
buc 58fba43
     }
buc 58fba43
 #endif
buc 58fba43
 
buc 58fba43
+    tty_init();
buc 58fba43
     fb_memset(fb_mem+fb_mem_offset,0,fb_fix.smem_len);
buc 58fba43
     for (;!sig;) {
buc 58fba43
 	if ((fb_switch_state == FB_ACTIVE || keep_dma_on) && !quiet) {
buc 58fba43
@@ -824,6 +826,14 @@ main(int argc, char *argv[])
buc 58fba43
 		fps++;
buc 58fba43
 		/* grab + convert frame */
buc 58fba43
 		if (NULL == (buf = ng_grabber_grab_image(0))) {
buc 58fba43
+		    do_va_cmd(2,"capture","off");
buc 58fba43
+		    if (mute)
buc 58fba43
+			audio_off();
buc 58fba43
+		    drv->close(h_drv);
buc 58fba43
+		    if (fb_switch_state == FB_ACTIVE)
buc 58fba43
+			fb_memset(fb_mem+fb_mem_offset,0,fb_fix.smem_len);
buc 58fba43
+		    tty_cleanup();
buc 58fba43
+		    fb_cleanup();
buc 58fba43
 		    fprintf(stderr,"capturing image failed\n");
buc 58fba43
 		    exit(1);
buc 58fba43
 		}
buc 58fba43
-- 
buc 58fba43
2.17.1
buc 58fba43