libxml2: moved to github
[packages.git] / libs / libv4l / patches / 001-no-shm_open-fix.patch
1 --- a/lib/libv4lconvert/control/libv4lcontrol.c
2 +++ b/lib/libv4lconvert/control/libv4lcontrol.c
3 @@ -525,7 +525,7 @@ static void v4lcontrol_get_flags_from_db
4  
5  struct v4lcontrol_data *v4lcontrol_create(int fd, int always_needs_conversion)
6  {
7 -       int shm_fd;
8 +       int shm_fd, fdflags;
9         int i, rc, got_usb_info, speed, init = 0;
10         char *s, shm_name[256], pwd_buf[1024];
11         struct v4l2_capability cap;
12 @@ -638,33 +638,38 @@ struct v4lcontrol_data *v4lcontrol_creat
13  
14         if (getpwuid_r(geteuid(), &pwd, pwd_buf, sizeof(pwd_buf), &pwd_p) == 0) {
15                 if (got_usb_info)
16 -                       snprintf(shm_name, 256, "/libv4l-%s:%s:%04x:%04x:%s", pwd.pw_name,
17 +                       snprintf(shm_name, 256, "/dev/shm/libv4l-%s:%s:%04x:%04x:%s", pwd.pw_name,
18                                         cap.bus_info, (int)vendor_id, (int)product_id, cap.card);
19                 else
20 -                       snprintf(shm_name, 256, "/libv4l-%s:%s:%s", pwd.pw_name,
21 +                       snprintf(shm_name, 256, "/dev/shm/libv4l-%s:%s:%s", pwd.pw_name,
22                                         cap.bus_info, cap.card);
23         } else {
24                 perror("libv4lcontrol: error getting username using uid instead");
25                 if (got_usb_info)
26 -                       snprintf(shm_name, 256, "/libv4l-%lu:%s:%04x:%04x:%s",
27 +                       snprintf(shm_name, 256, "/dev/shm/libv4l-%lu:%s:%04x:%04x:%s",
28                                         (unsigned long)geteuid(), cap.bus_info,
29                                         (int)vendor_id, (int)product_id, cap.card);
30                 else
31 -                       snprintf(shm_name, 256, "/libv4l-%lu:%s:%s", (unsigned long)geteuid(),
32 +                       snprintf(shm_name, 256, "/dev/shm/libv4l-%lu:%s:%s", (unsigned long)geteuid(),
33                                         cap.bus_info, cap.card);
34         }
35  
36         /* / is not allowed inside shm names */
37 -       for (i = 1; shm_name[i]; i++)
38 +       for (i = 9; shm_name[i]; i++) /* start after "/dev/shm", i = 9 */
39                 if (shm_name[i] == '/')
40                         shm_name[i] = '-';
41  
42         /* Open the shared memory object identified by shm_name */
43 -       shm_fd = shm_open(shm_name, (O_CREAT | O_EXCL | O_RDWR), (S_IREAD | S_IWRITE));
44 +       shm_fd = open(shm_name, (O_CREAT | O_EXCL | O_RDWR), (S_IREAD | S_IWRITE));
45         if (shm_fd >= 0)
46                 init = 1;
47         else
48 -               shm_fd = shm_open(shm_name, O_RDWR, (S_IREAD | S_IWRITE));
49 +               shm_fd = open(shm_name, O_RDWR, (S_IREAD | S_IWRITE));
50 +
51 +       /* This is all uClibc > 0.9.30 seems to do for shm_open() in librt/shm.c */
52 +       fdflags = fcntl(shm_fd, F_GETFD, 0);
53 +       if (fdflags >= 0)
54 +               fdflags = fcntl(fd, F_SETFD, fdflags | FD_CLOEXEC);
55  
56         if (shm_fd >= 0) {
57                 /* Set the shared memory size */