commit e1c2f8b
Michael Forney
·
2019-08-13 19:23:47 +0000 UTC
parent a98426a
launch: Make sure we stat and open the same file Fixes #50.
1 files changed,
+10,
-18
+10,
-18
1@@ -202,7 +202,12 @@ handle_socket_data(int socket)
2 goto fail;
3 }
4
5- if (stat(path, &st) == -1) {
6+ fd = open(path, request.flags);
7+ if (fd == -1) {
8+ fprintf(stderr, "open %s: %s\n", path, strerror(errno));
9+ goto fail;
10+ }
11+ if (fstat(fd, &st) == -1) {
12 fprintf(stderr, "stat %s: %s\n", path, strerror(errno));
13 goto fail;
14 }
15@@ -215,34 +220,19 @@ handle_socket_data(int socket)
16 fprintf(stderr, "too many input devices opened\n");
17 goto fail;
18 }
19+ input_fds[num_input_fds++] = fd;
20 break;
21 case DRM_MAJOR:
22 if (num_drm_fds == ARRAY_LENGTH(drm_fds)) {
23 fprintf(stderr, "too many DRM devices opened\n");
24 goto fail;
25 }
26+ drm_fds[num_drm_fds++] = fd;
27 break;
28 default:
29 fprintf(stderr, "device is not an input device\n");
30 goto fail;
31 }
32-
33- fd = open(path, request.flags);
34-
35- if (fd == -1) {
36- fprintf(stderr, "open %s: %s\n", path, strerror(errno));
37- goto fail;
38- }
39-
40- switch (major(st.st_rdev)) {
41- case INPUT_MAJOR:
42- input_fds[num_input_fds++] = fd;
43- break;
44- case DRM_MAJOR:
45- drm_fds[num_drm_fds++] = fd;
46- break;
47- }
48-
49 break;
50 case SWC_LAUNCH_REQUEST_ACTIVATE_VT:
51 if (!active)
52@@ -261,6 +251,8 @@ handle_socket_data(int socket)
53
54 fail:
55 response.success = false;
56+ if (fd != -1)
57+ close(fd);
58 fd = -1;
59 done:
60 send_fd(socket, fd, response_iov, 1);