uint32_t capabilities;
};
+static int tbm_drm_fd = -1;
+
/* LCOV_EXCL_START */
static void
handle_tbm_drm_authentication_info(void *data, struct wl_tbm_drm_auth *wl_tbm_drm_auth, const char *device_name, uint32_t capabilities, int32_t auth_fd)
void
tbm_drm_helper_set_fd(int fd)
{
- char buf[32];
- int ret;
+ int fd_max = tbm_bufmgr_get_fd_limit();
- snprintf(buf, sizeof(buf), "%d", fd);
+ if (tbm_drm_fd == fd)
+ return;
- ret = setenv("TBM_DRM_FD", (const char*)buf, 1);
- if (ret) {
- TBM_LOG_E("failed to set TBM_DRM_FD to %d\n", fd);
+ if (fd < 0 || fd > fd_max) {
+ TBM_LOG_E("%d out of fd range\n", fd);
return;
}
- TBM_LOG_I("TBM_DRM_FD: %d\n", fd);
+ if (tbm_drm_fd != -1)
+ TBM_LOG_W("already has TBM_DRM_FD: %d\n", tbm_drm_fd);
+
+ tbm_drm_fd = fd;
+
+ TBM_LOG_I("TBM_DRM_FD: %d\n", tbm_drm_fd);
}
void
tbm_drm_helper_unset_fd(void)
{
- int ret;
-
- ret = unsetenv("TBM_DRM_FD");
- if (ret) {
- TBM_LOG_E("failed to unset TBM_DRM_FD\n");
- return;
- }
+ tbm_drm_fd = -1;
+ TBM_LOG_I("TBM_DRM_FD: %d\n", tbm_drm_fd);
}
int
tbm_drm_helper_get_fd(void)
{
- const char *value;
- int flags, fd = -1;
- int new_fd = -1;
- char *end;
- errno = 0;
-
- value = (const char*)getenv("TBM_DRM_FD");
- if (!value)
- return -1;
+ int new_fd, flags;
- const long sl = strtol(value, &end, 10);
- if (end == value) {
- TBM_LOG_E("%s: not a decimal number\n", value);
- return -1;
- } else if (*end != '\0') {
- TBM_LOG_E("%s: extra characters at end of input: %s\n", value, end);
- return -1;
- } else if ((sl == LONG_MIN || sl == LONG_MAX) && errno == ERANGE) {
- TBM_LOG_E("%s out of range of type long\n", value);
- return -1;
- } else if (sl > INT_MAX) {
- TBM_LOG_E("%ld greater than INT_MAX\n", sl);
- return -1;
- } else if (sl < INT_MIN) {
- TBM_LOG_E("%ld less than INT_MIN\n", sl);
+ if (tbm_drm_fd == -1) {
+ TBM_LOG_E("no drm fd");
return -1;
- } else {
- fd = (int)sl;
- if (fd < 0) {
- TBM_LOG_E("%d out of fd range\n", fd);
- return -1;
- }
}
- TBM_LOG_I("TBM_DRM_FD: %d\n", fd);
+ TBM_LOG_I("TBM_DRM_FD: %d\n", tbm_drm_fd);
- flags = fcntl(fd, F_GETFD);
+ flags = fcntl(tbm_drm_fd, F_GETFD);
if (flags == -1) {
- TBM_LOG_E("fcntl failed: %m\n");
+ TBM_LOG_E("fcntl failed: %m");
return -1;
}
- new_fd = dup(fd);
+ new_fd = dup(tbm_drm_fd);
if (new_fd < 0) {
- TBM_LOG_E("dup failed: %m\n");
+ TBM_LOG_E("dup failed: %m");
return -1;
}