Gentoo Archives: gentoo-commits

From: "Mike Gilbert (floppym)" <floppym@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in dev-lang/python/files: python-2.7.10-semaphore-pid.patch
Date: Thu, 28 May 2015 04:10:54
Message-Id: 20150528041047.A9354A11@oystercatcher.gentoo.org
1 floppym 15/05/28 04:10:47
2
3 Added: python-2.7.10-semaphore-pid.patch
4 Log:
5 Version bump.
6
7 (Portage version: 2.2.20/cvs/Linux x86_64, signed Manifest commit with key 0BBEEA1FEA4843A4)
8
9 Revision Changes Path
10 1.1 dev-lang/python/files/python-2.7.10-semaphore-pid.patch
11
12 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-lang/python/files/python-2.7.10-semaphore-pid.patch?rev=1.1&view=markup
13 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-lang/python/files/python-2.7.10-semaphore-pid.patch?rev=1.1&content-type=text/plain
14
15 Index: python-2.7.10-semaphore-pid.patch
16 ===================================================================
17 Fix for semaphores in pid namespaces
18
19 http://bugs.python.org/issue24303
20
21 --- a/Modules/_multiprocessing/semaphore.c
22 +++ b/Modules/_multiprocessing/semaphore.c
23 @@ -7,6 +7,7 @@
24 */
25
26 #include "multiprocessing.h"
27 +#include <time.h>
28
29 enum { RECURSIVE_MUTEX, SEMAPHORE };
30
31 @@ -419,7 +420,7 @@ semlock_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
32 {
33 char buffer[256];
34 SEM_HANDLE handle = SEM_FAILED;
35 - int kind, maxvalue, value;
36 + int kind, maxvalue, value, try;
37 PyObject *result;
38 static char *kwlist[] = {"kind", "value", "maxvalue", NULL};
39 static int counter = 0;
40 @@ -433,10 +434,24 @@ semlock_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
41 return NULL;
42 }
43
44 - PyOS_snprintf(buffer, sizeof(buffer), "/mp%ld-%d", (long)getpid(), counter++);
45 + /* With pid namespaces, we may have multiple processes with the same pid.
46 + * Instead of relying on the pid to be unique, we use the microseconds time
47 + * to attempt to a unique filename. */
48 + for (try = 0; try < 100; ++try) {
49 + struct timespec tv;
50 + long arbitrary = clock_gettime(CLOCK_REALTIME, &tv) ? 0 : tv.tv_nsec;
51 + PyOS_snprintf(buffer, sizeof(buffer), "/mp%ld-%d-%ld",
52 + (long)getpid(),
53 + counter++,
54 + arbitrary);
55 + SEM_CLEAR_ERROR();
56 + handle = SEM_CREATE(buffer, value, maxvalue);
57 + if (handle != SEM_FAILED)
58 + break;
59 + else if (errno != EEXIST)
60 + goto failure;
61 + }
62
63 - SEM_CLEAR_ERROR();
64 - handle = SEM_CREATE(buffer, value, maxvalue);
65 /* On Windows we should fail if GetLastError()==ERROR_ALREADY_EXISTS */
66 if (handle == SEM_FAILED || SEM_GET_LAST_ERROR() != 0)
67 goto failure;