[PATCH 2 of 4] osutil: implement setprocname to set process title
Jun Wu
quark at fb.com
Wed Aug 10 13:29:58 EDT 2016
# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1470846674 -3600
# Wed Aug 10 17:31:14 2016 +0100
# Node ID 6913c4d46efa50511191c3c310882602d07cc305
# Parent 4485f6b4073cf2e22d8a8afaddb9c86eea2a019a
# Available At https://bitbucket.org/quark-zju/hg-draft
# hg pull https://bitbucket.org/quark-zju/hg-draft -r 6913c4d46efa
osutil: implement setprocname to set process title
Use prctl (Linux) or setproctitle (FreeBSD) to implement the feature.
It is useful for forked command servers - to show what it is doing.
diff --git a/mercurial/osutil.c b/mercurial/osutil.c
--- a/mercurial/osutil.c
+++ b/mercurial/osutil.c
@@ -31,6 +31,10 @@
#include <sys/vnode.h>
#endif
+#ifdef HAVE_PRCTL
+#include <sys/prctl.h>
+#endif
+
#include "util.h"
/* some platforms lack the PATH_MAX definition (eg. GNU/Hurd) */
@@ -719,6 +723,24 @@ bail:
}
#endif /* CMSG_LEN */
+
+#if defined(HAVE_SETPROCTITLE) || (defined(PR_SET_NAME) && defined(HAVE_PRCTL))
+static PyObject *setprocname(PyObject *self, PyObject *args)
+{
+ const char *name = NULL;
+ if (!PyArg_ParseTuple(args, "s", &name))
+ return NULL;
+
+#ifdef HAVE_SETPROCTITLE
+ setproctitle("%s", name);
+#else
+ prctl(PR_SET_NAME, name, NULL, NULL);
+#endif
+
+ Py_RETURN_NONE;
+}
+#endif
+
#endif /* ndef _WIN32 */
static PyObject *listdir(PyObject *self, PyObject *args, PyObject *kwargs)
@@ -891,7 +913,11 @@ static PyMethodDef methods[] = {
{"recvfds", (PyCFunction)recvfds, METH_VARARGS,
"receive list of file descriptors via socket\n"},
#endif
+#if defined(HAVE_SETPROCTITLE) || (defined(PR_SET_NAME) && defined(HAVE_PRCTL))
+ {"setprocname", (PyCFunction)setprocname, METH_VARARGS,
+ "set process title\n"},
#endif
+#endif /* ndef _WIN32 */
#ifdef __APPLE__
{
"isgui", (PyCFunction)isgui, METH_NOARGS,
More information about the Mercurial-devel
mailing list