Commit b0ea3096 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

XCB: fallback to SHM with promiscuous permissions on attach error

Some X servers cannot borrow VLC user privileges to attach to its
shared memory segments. This fallback should fix MIT-SHM with those
X servers. However other users will be able to snoop on the decoded
video frames.
parent 8516a403
......@@ -29,7 +29,8 @@
#include <sys/types.h>
#ifdef HAVE_SYS_SHM_H
#include <sys/shm.h>
# include <sys/shm.h>
# include <sys/stat.h>
#endif
#include <xcb/xcb.h>
......@@ -196,7 +197,7 @@ int PictureResourceAlloc (vout_display_t *vd, picture_resource_t *res, size_t si
#ifdef HAVE_SYS_SHM_H
/* Allocate shared memory segment */
int id = shmget (IPC_PRIVATE, size, IPC_CREAT | 0700);
int id = shmget (IPC_PRIVATE, size, IPC_CREAT | S_IRWXU);
if (id == -1)
{
msg_Err (vd, "shared memory allocation error: %m");
......@@ -223,8 +224,25 @@ int PictureResourceAlloc (vout_display_t *vd, picture_resource_t *res, size_t si
segment = xcb_generate_id (conn);
ck = xcb_shm_attach_checked (conn, segment, id, 1);
if (CheckError (vd, conn, "shared memory server-side error", ck))
switch (CheckError (vd, conn, "shared memory server-side error", ck))
{
case 0:
break;
case XCB_ACCESS:
{
struct shmid_ds buf;
/* Retry with promiscuous permissions */
shmctl (id, IPC_STAT, &buf);
buf.shm_perm.mode |= S_IRGRP|S_IROTH;
shmctl (id, IPC_SET, &buf);
ck = xcb_shm_attach_checked (conn, segment, id, 1);
if (CheckError (vd, conn, "same error on retry", ck) == 0)
break;
/* fall through */
}
default:
msg_Info (vd, "using buggy X11 server - SSH proxying?");
segment = 0;
}
......@@ -232,7 +250,7 @@ int PictureResourceAlloc (vout_display_t *vd, picture_resource_t *res, size_t si
else
segment = 0;
shmctl (id, IPC_RMID, 0);
shmctl (id, IPC_RMID, NULL);
res->p_sys->segment = segment;
res->p->p_pixels = shm;
#else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment