Skip to content

Commit

Permalink
Add a function to set the thread name
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.php.net/repository/pecl/proctitle/trunk@310615 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
bjori committed Apr 28, 2011
1 parent dce6fc2 commit c692c82
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
10 changes: 10 additions & 0 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
39 changes: 38 additions & 1 deletion proctitle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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[] */
};
/* }}} */
Expand Down Expand Up @@ -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.