Skip to content
Browse files

Add a function to set the thread name

git-svn-id: http://svn.php.net/repository/pecl/proctitle/trunk@310615 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent dce6fc2 commit c692c82d089c549aa4290259f8c8d09c95b54c10 bjori committed Apr 28, 2011
Showing with 48 additions and 1 deletion.
  1. +10 −0 config.m4
  2. +38 −1 proctitle.c
View
10 config.m4
@@ -12,6 +12,16 @@ if test "$PHP_PROCTITLE" != "no"; then
],[
php_system_provides_setproctitle_call=no
])])
+
+ AC_MSG_CHECKING([for prctl])
+
+ AC_TRY_COMPILE([ #include <sys/prctl.h> ], [prctl(0, 0, 0, 0, 0);], [
+ AC_DEFINE([HAVE_PRCTL], 1, [do we have prctl?])
+ AC_MSG_RESULT([yes])
+ ], [
+ AC_MSG_RESULT([no])
+ ])
+
AC_MSG_CHECKING([if your OS provides a native way to change a process title])
if test "$php_system_provides_setproctitle_call" = "yes"; then
AC_MSG_RESULT(yes)
View
39 proctitle.c
@@ -27,6 +27,10 @@
#include <dlfcn.h>
#include <string.h>
+#ifdef HAVE_PRCTL
+#include <sys/prctl.h>
+#endif
+
#include "php_proctitle.h"
static char *argv0 = NULL;
@@ -87,12 +91,36 @@ PHP_FUNCTION(setproctitle)
}
/* }}} */
+#if HAVE_PRCTL
+/* {{{ bool mixed setthreadtitle(string title)
+ Sets the thread name */
+PHP_FUNCTION(setthreadtitle)
+{
+ char *title;
+ int title_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &title, &title_len) == FAILURE) {
+ return;
+ }
+ if (0 == prctl(PR_SET_NAME, title, 0, 0, 0)) {
+ RETURN_TRUE;
+ } else {
+ RETURN_FALSE;
+ }
+
+}
+/* }}} */
+#endif
+
/* {{{ proctitle_functions[]
*
* Every user visible function must have an entry in proctitle_functions[].
*/
static zend_function_entry proctitle_functions[] = {
- PHP_FE(setproctitle, NULL) /* For testing, remove later. */
+ PHP_FE(setproctitle, NULL)
+#if HAVE_PRCTL
+ PHP_FE(setthreadtitle, NULL)
+#endif
{NULL, NULL, NULL} /* Must be the last line in proctitle_functions[] */
};
/* }}} */
@@ -135,3 +163,12 @@ zend_module_entry proctitle_module_entry = {
ZEND_GET_MODULE(proctitle)
#endif
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: fdm=marker
+ * vim: noet sw=4 ts=4
+ */

0 comments on commit c692c82

Please sign in to comment.
Something went wrong with that request. Please try again.