Author: tack
Date: Mon Dec 31 18:42:21 2007
New Revision: 2934
Log:
Support for modifying the process name as it appears in ps. (Also
supports killall via prctl.)
Added:
trunk/base/src/extensions/utils.c (contents, props changed)
Modified:
trunk/base/setup.py
trunk/base/src/utils.py
Modified: trunk/base/setup.py
==============================================================================
--- trunk/base/setup.py (original)
+++ trunk/base/setup.py Mon Dec 31 18:42:21 2007
@@ -75,6 +75,13 @@
print "inotify supported by glibc; good."
extensions.append(inotify_ext)
+ utils_ext = Extension('kaa._utils', ['src/extensions/utils.c'],
config='src/extensions/config.h')
+ extensions.append(utils_ext)
+ if inotify_ext.check_cc(['<sys/prctl.h>'], 'prctl(PR_SET_NAME, "x");'):
+ utils_ext.config('#define HAVE_PRCTL')
+ else:
+ print 'Disabling Linux-specific features.'
+
# call setup
setup(
module = 'base',
Added: trunk/base/src/extensions/utils.c
==============================================================================
--- (empty file)
+++ trunk/base/src/extensions/utils.c Mon Dec 31 18:42:21 2007
@@ -0,0 +1,67 @@
+/*
+ * ----------------------------------------------------------------------------
+ * Miscellaneous low-level functions
+ * ----------------------------------------------------------------------------
+ * $Id$
+ * ----------------------------------------------------------------------------
+ * Copyright (C) 2007 Jason Tackaberry
+ *
+ * First Edition: Jason Tackaberry <[EMAIL PROTECTED]>
+ * Maintainer: Jason Tackaberry <[EMAIL PROTECTED]>
+ *
+ * Please see the file AUTHORS for a complete list of authors.
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version
+ * 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ * ----------------------------------------------------------------------------
+ */
+
+#include "Python.h"
+#include "config.h"
+#ifdef HAVE_PRCTL
+#include <sys/prctl.h>
+#endif
+
+extern void Py_GetArgcArgv(int *argc, char ***argv);
+
+PyObject *set_process_name(PyObject *self, PyObject *args)
+{
+#ifdef HAVE_PRCTL
+ int argc, limit;
+ char **argv, *name;
+
+ if (!PyArg_ParseTuple(args, "si", &name, &limit))
+ return NULL;
+
+ Py_GetArgcArgv(&argc, &argv);
+ memset(argv[0], 0, limit);
+ strncpy(argv[0], name, limit-1);
+
+ // Needed for killall
+ prctl(PR_SET_NAME, argv[0], 0, 0, 0);
+#endif
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+PyMethodDef utils_methods[] = {
+ {"set_process_name", set_process_name, METH_VARARGS },
+ { NULL }
+};
+
+void init_utils(void)
+{
+ Py_InitModule("_utils", utils_methods);
+}
Modified: trunk/base/src/utils.py
==============================================================================
--- trunk/base/src/utils.py (original)
+++ trunk/base/src/utils.py Mon Dec 31 18:42:21 2007
@@ -37,6 +37,7 @@
import logging
import kaa
+import _utils
# get logging object
log = logging.getLogger('kaa')
@@ -174,15 +175,31 @@
return 0
-def set_running(name):
+def set_running(name, modify = True):
"""
- Set this program as running with the given name.
+ Set this program as running with the given name. If modify is True,
+ the process name is updated as described in set_process_name().
"""
cmdline = open('/proc/%s/cmdline' % os.getpid()).readline()
run = open(kaa.tempfile('run/' + name), 'w')
run.write(str(os.getpid()) + '\n')
run.write(cmdline)
run.close()
+ if modify:
+ _utils.set_process_name(name, len(cmdline))
+
+
+def set_process_name(name):
+ """
+ On Linux systems later than 2.6.9, this function sets the process name as
it
+ appears in ps, and so that it can be found with killall.
+
+ Note: name will be truncated to the cumulative length of the original
+ process name and all its arguments; once updated, passed arguments will no
+ longer be visible.
+ """
+ cmdline = open('/proc/%s/cmdline' % os.getpid()).readline()
+ _utils.set_process_name(name, len(cmdline))
class Singleton(object):
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog