GNOME Bugzilla – Bug 684339
shm: use O_CLOEXEC where appropriate in shmpipe
Last modified: 2013-02-28 17:54:40 UTC
Created attachment 224682 [details] [review] patch to add CLOEXEC in sp_client_open shmpipe.c provides two functions which open sockets, one for shmsrc, a reader, and one for shmsink, a writer. sp_client_open opens a socket but doesn't set CLOEXEC, so i've provided an '#if defined' version which uses SOCK_CLOEXEC if it's defined and otherwise uses fnctl and O_CLOEXEC. sp_writer_create opens the socket for the writer and sets CLOEXEC, but it doesn't make use of SOCK_CLOEXEC, which can lead to a race condition.
Created attachment 224683 [details] [review] patch to add SOCK_CLOEXEC in sp_writer_create
Created attachment 228512 [details] [review] patch to add CLOEXEC in sp_writer_create and sp_client_open Patch updated. sp_client_open socket does need to be blocking (non-blocking flag was added by accident in the previous patches).
I pushed the patch for O_CLOEXEC, but I'm not convinced about the usefulness of SOCK_CLOEXEC, because 1. you have to build against recent linux 2. you have to test at runtime if you're running against a recent enough kernel (and fallback to fcntl anyway). 3. fcntl isn't that expensive at all commit c175c6b3d083f6bf3798cd172b38c4979b067c73 Author: Blake Tregre <blake@oblong.com> Date: Thu Nov 8 13:22:41 2012 -0800 shm: use O_CLOEXEC where appropriate in shmpipe https://bugzilla.gnome.org/show_bug.cgi?id=684339