summaryrefslogtreecommitdiffstats
path: root/package/weston/weston-0000-dont-leak-fd-on-launcher-error.patch
blob: 0929d010b111be981795e45917004c5bef5819f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
commit 4a74d5a4a45423752105f865a8310ce878b1790a
Author: Kristian Høgsberg <krh@bitplanet.net>
Date:   Wed Oct 9 11:19:11 2013 -0700

    launcher: Don't leak tty file descriptor on error

---
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>

diff --git a/src/launcher-util.c b/src/launcher-util.c
index d90271f..8ab61f1 100644
--- a/src/launcher-util.c
+++ b/src/launcher-util.c
@@ -275,7 +275,7 @@ setup_tty(struct weston_launcher *launcher, int tty)
 		weston_log("%s not a vt\n", tty_device);
 		weston_log("if running weston from ssh, "
 			   "use --tty to specify a tty\n");
-		return -1;
+		goto err_close;
 	}
 
 	ret = ioctl(launcher->tty, KDGETMODE, &kd_mode);
@@ -286,7 +286,7 @@ setup_tty(struct weston_launcher *launcher, int tty)
 	if (kd_mode != KD_TEXT) {
 		weston_log("%s is already in graphics mode, "
 			   "is another display server running?\n", tty_device);
-		return -1;
+		goto err_close;
 	}
 
 	ret = ioctl(launcher->tty, VT_ACTIVATE, minor(buf.st_rdev));
@@ -297,19 +297,19 @@ setup_tty(struct weston_launcher *launcher, int tty)
 
 	if (ioctl(launcher->tty, KDGKBMODE, &launcher->kb_mode)) {
 		weston_log("failed to read keyboard mode: %m\n");
-		return -1;
+		goto err_close;
 	}
 
 	if (ioctl(launcher->tty, KDSKBMUTE, 1) &&
 	    ioctl(launcher->tty, KDSKBMODE, K_OFF)) {
 		weston_log("failed to set K_OFF keyboard mode: %m\n");
-		return -1;
+		goto err_close;
 	}
 
 	ret = ioctl(launcher->tty, KDSETMODE, KD_GRAPHICS);
 	if (ret) {
 		weston_log("failed to set KD_GRAPHICS mode on tty: %m\n");
-		return -1;
+		goto err_close;
 	}
 
 	mode.mode = VT_PROCESS;
@@ -317,16 +317,20 @@ setup_tty(struct weston_launcher *launcher, int tty)
 	mode.acqsig = SIGUSR1;
 	if (ioctl(launcher->tty, VT_SETMODE, &mode) < 0) {
 		weston_log("failed to take control of vt handling\n");
-		return -1;
+		goto err_close;
 	}
 
 	loop = wl_display_get_event_loop(launcher->compositor->wl_display);
 	launcher->vt_source =
 		wl_event_loop_add_signal(loop, SIGUSR1, vt_handler, launcher);
 	if (!launcher->vt_source)
-		return -1;
+		goto err_close;
 
 	return 0;
+
+ err_close:
+	close(launcher->tty);
+	return -1;
 }
 
 int
OpenPOWER on IntegriCloud