Patchwork D1736: osutil: add a function to unblock signals

login
register
mail settings
Submitter phabricator
Date Dec. 21, 2017, 2:54 p.m.
Message ID <f4b8953e2c8f2c197d5e9f10747e28fe@localhost.localdomain>
Download mbox | patch
Permalink /patch/26378/
State Not Applicable
Headers show

Comments

phabricator - Dec. 21, 2017, 2:54 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG8652ab4046e4: osutil: add a function to unblock signals (authored by quark, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D1736?vs=4561&id=4569

REVISION DETAIL
  https://phab.mercurial-scm.org/D1736

AFFECTED FILES
  mercurial/cext/osutil.c
  mercurial/policy.py
  mercurial/util.py

CHANGE DETAILS




To: quark, #hg-reviewers, yuja
Cc: yuja, mercurial-devel

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -163,6 +163,10 @@ 
     setprocname = osutil.setprocname
 except AttributeError:
     pass
+try:
+    unblocksignal = osutil.unblocksignal
+except AttributeError:
+    pass
 
 # Python compatibility
 
diff --git a/mercurial/policy.py b/mercurial/policy.py
--- a/mercurial/policy.py
+++ b/mercurial/policy.py
@@ -74,7 +74,7 @@ 
     (r'cext', r'bdiff'): 1,
     (r'cext', r'diffhelpers'): 1,
     (r'cext', r'mpatch'): 1,
-    (r'cext', r'osutil'): 1,
+    (r'cext', r'osutil'): 2,
     (r'cext', r'parsers'): 4,
 }
 
diff --git a/mercurial/cext/osutil.c b/mercurial/cext/osutil.c
--- a/mercurial/cext/osutil.c
+++ b/mercurial/cext/osutil.c
@@ -20,6 +20,7 @@ 
 #include <windows.h>
 #else
 #include <dirent.h>
+#include <signal.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -1111,6 +1112,25 @@ 
 }
 #endif /* defined(HAVE_LINUX_STATFS) || defined(HAVE_BSD_STATFS) */
 
+static PyObject *unblocksignal(PyObject *self, PyObject *args)
+{
+	int sig = 0;
+	int r;
+	if (!PyArg_ParseTuple(args, "i", &sig))
+		return NULL;
+	sigset_t set;
+	r = sigemptyset(&set);
+	if (r != 0)
+		return PyErr_SetFromErrno(PyExc_OSError);
+	r = sigaddset(&set, sig);
+	if (r != 0)
+		return PyErr_SetFromErrno(PyExc_OSError);
+	r = sigprocmask(SIG_UNBLOCK, &set, NULL);
+	if (r != 0)
+		return PyErr_SetFromErrno(PyExc_OSError);
+	Py_RETURN_NONE;
+}
+
 #endif /* ndef _WIN32 */
 
 static PyObject *listdir(PyObject *self, PyObject *args, PyObject *kwargs)
@@ -1291,6 +1311,8 @@ 
 	{"getfstype", (PyCFunction)getfstype, METH_VARARGS,
 	 "get filesystem type (best-effort)\n"},
 #endif
+	{"unblocksignal", (PyCFunction)unblocksignal, METH_VARARGS,
+	 "change signal mask to unblock a given signal\n"},
 #endif /* ndef _WIN32 */
 #ifdef __APPLE__
 	{
@@ -1301,7 +1323,7 @@ 
 	{NULL, NULL}
 };
 
-static const int version = 1;
+static const int version = 2;
 
 #ifdef IS_PY3K
 static struct PyModuleDef osutil_module = {