commit e1c2f8b50aa7bc97e022743b1f967439c87a99f4
parent a98426ae69b43396cb22bb62316e270fb1f9d8f1
Author: Michael Forney <mforney@mforney.org>
Date: Tue, 13 Aug 2019 12:23:47 -0700
launch: Make sure we stat and open the same file
Fixes #50.
Diffstat:
1 file changed, 10 insertions(+), 18 deletions(-)
diff --git a/launch/launch.c b/launch/launch.c
@@ -202,7 +202,12 @@ handle_socket_data(int socket)
goto fail;
}
- if (stat(path, &st) == -1) {
+ fd = open(path, request.flags);
+ if (fd == -1) {
+ fprintf(stderr, "open %s: %s\n", path, strerror(errno));
+ goto fail;
+ }
+ if (fstat(fd, &st) == -1) {
fprintf(stderr, "stat %s: %s\n", path, strerror(errno));
goto fail;
}
@@ -215,34 +220,19 @@ handle_socket_data(int socket)
fprintf(stderr, "too many input devices opened\n");
goto fail;
}
+ input_fds[num_input_fds++] = fd;
break;
case DRM_MAJOR:
if (num_drm_fds == ARRAY_LENGTH(drm_fds)) {
fprintf(stderr, "too many DRM devices opened\n");
goto fail;
}
+ drm_fds[num_drm_fds++] = fd;
break;
default:
fprintf(stderr, "device is not an input device\n");
goto fail;
}
-
- fd = open(path, request.flags);
-
- if (fd == -1) {
- fprintf(stderr, "open %s: %s\n", path, strerror(errno));
- goto fail;
- }
-
- switch (major(st.st_rdev)) {
- case INPUT_MAJOR:
- input_fds[num_input_fds++] = fd;
- break;
- case DRM_MAJOR:
- drm_fds[num_drm_fds++] = fd;
- break;
- }
-
break;
case SWC_LAUNCH_REQUEST_ACTIVATE_VT:
if (!active)
@@ -261,6 +251,8 @@ handle_socket_data(int socket)
fail:
response.success = false;
+ if (fd != -1)
+ close(fd);
fd = -1;
done:
send_fd(socket, fd, response_iov, 1);