Skip to content

Commit a0a995c

Browse files
author
Keyur Govande
committed
A new commit into branch 5.5
1 parent d77eb41 commit a0a995c

11 files changed

+769
-3
lines changed

sapi/cli/config.m4

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@ PHP_ARG_ENABLE(cli,,
66
[ --disable-cli Disable building CLI version of PHP
77
(this forces --without-pear)], yes, no)
88

9+
AC_CHECK_FUNCS(setproctitle)
10+
11+
AC_CHECK_HEADERS([sys/pstat.h])
12+
13+
AC_CACHE_CHECK([for PS_STRINGS], [cli_cv_var_PS_STRINGS],
14+
[AC_TRY_LINK(
15+
[#include <machine/vmparam.h>
16+
#include <sys/exec.h>
17+
],
18+
[PS_STRINGS->ps_nargvstr = 1;
19+
PS_STRINGS->ps_argvstr = "foo";],
20+
[cli_cv_var_PS_STRINGS=yes],
21+
[cli_cv_var_PS_STRINGS=no])])
22+
if test "$cli_cv_var_PS_STRINGS" = yes ; then
23+
AC_DEFINE([HAVE_PS_STRINGS], [], [Define to 1 if the PS_STRINGS thing exists.])
24+
fi
25+
926
AC_MSG_CHECKING(for CLI build)
1027
if test "$PHP_CLI" != "no"; then
1128
PHP_ADD_MAKEFILE_FRAGMENT($abs_srcdir/sapi/cli/Makefile.frag)
@@ -14,7 +31,7 @@ if test "$PHP_CLI" != "no"; then
1431
SAPI_CLI_PATH=sapi/cli/php
1532

1633
dnl Select SAPI
17-
PHP_SELECT_SAPI(cli, program, php_cli.c php_http_parser.c php_cli_server.c,, '$(SAPI_CLI_PATH)')
34+
PHP_SELECT_SAPI(cli, program, php_cli.c php_http_parser.c php_cli_server.c ps_title.c php_cli_process_title.c,, '$(SAPI_CLI_PATH)')
1835

1936
case $host_alias in
2037
*aix*)

sapi/cli/config.w32

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ARG_ENABLE('crt-debug', 'Enable CRT memory dumps for debugging sent to STDERR',
66
ARG_ENABLE('cli-win32', 'Build console-less CLI version of PHP', 'no');
77

88
if (PHP_CLI == "yes") {
9-
SAPI('cli', 'php_cli.c php_http_parser.c php_cli_server.c', 'php.exe');
9+
SAPI('cli', 'php_cli.c php_http_parser.c php_cli_server.c php_cli_process_title.c ps_title.c', 'php.exe');
1010
ADD_FLAG("LIBS_CLI", "ws2_32.lib");
1111
if (PHP_CRT_DEBUG == "yes") {
1212
ADD_FLAG("CFLAGS_CLI", "/D PHP_WIN32_DEBUG_HEAP");
@@ -15,7 +15,7 @@ if (PHP_CLI == "yes") {
1515
}
1616

1717
if (PHP_CLI_WIN32 == "yes") {
18-
SAPI('cli_win32', 'cli_win32.c', 'php-win.exe');
18+
SAPI('cli_win32', 'cli_win32.c php_cli_process_title.c ps_title.c', 'php-win.exe');
1919
ADD_FLAG("LDFLAGS_CLI_WIN32", "/stack:8388608");
2020
}
2121

sapi/cli/php_cli.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@
8686
#include "php_cli_server.h"
8787
#endif
8888

89+
#include "ps_title.h"
90+
#include "php_cli_process_title.h"
91+
8992
#ifndef PHP_WIN32
9093
# define php_select(m, r, w, e, t) select(m, r, w, e, t)
9194
#else
@@ -478,6 +481,8 @@ ZEND_END_ARG_INFO()
478481

479482
static const zend_function_entry additional_functions[] = {
480483
ZEND_FE(dl, arginfo_dl)
484+
PHP_FE(cli_set_process_title, arginfo_cli_set_process_title)
485+
PHP_FE(cli_get_process_title, arginfo_cli_get_process_title)
481486
{NULL, NULL, NULL}
482487
};
483488

@@ -1200,6 +1205,7 @@ int main(int argc, char *argv[])
12001205
int argc = __argc;
12011206
char **argv = __argv;
12021207
#endif
1208+
12031209
int c;
12041210
int exit_status = SUCCESS;
12051211
int module_started = 0, sapi_started = 0;
@@ -1211,6 +1217,12 @@ int main(int argc, char *argv[])
12111217
int ini_ignore = 0;
12121218
sapi_module_struct *sapi_module = &cli_sapi_module;
12131219

1220+
/*
1221+
* Do not move this initialization. It needs to happen before argv is used
1222+
* in any way.
1223+
*/
1224+
argv = save_ps_args(argc, argv);
1225+
12141226
cli_sapi_module.additional_functions = additional_functions;
12151227

12161228
#if defined(PHP_WIN32) && defined(_DEBUG) && defined(PHP_WIN32_DEBUG_HEAP)
@@ -1299,6 +1311,7 @@ int main(int argc, char *argv[])
12991311
#ifndef PHP_CLI_WIN32_NO_CONSOLE
13001312
case 'S':
13011313
sapi_module = &cli_server_sapi_module;
1314+
cli_server_sapi_module.additional_functions = server_additional_functions;
13021315
break;
13031316
#endif
13041317
case 'h': /* help & quit */
@@ -1385,6 +1398,11 @@ int main(int argc, char *argv[])
13851398
tsrm_shutdown();
13861399
#endif
13871400

1401+
/*
1402+
* Do not move this de-initialization. It needs to happen right before
1403+
* exiting.
1404+
*/
1405+
cleanup_ps_args(argv);
13881406
exit(exit_status);
13891407
}
13901408
/* }}} */

sapi/cli/php_cli_process_title.c

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| PHP Version 5 |
4+
+----------------------------------------------------------------------+
5+
| Copyright (c) 1997-2013 The PHP Group |
6+
+----------------------------------------------------------------------+
7+
| This source file is subject to version 3.01 of the PHP license, |
8+
| that is bundled with this package in the file LICENSE, and is |
9+
| available through the world-wide-web at the following url: |
10+
| http://www.php.net/license/3_01.txt |
11+
| If you did not receive a copy of the PHP license and are unable to |
12+
| obtain it through the world-wide-web, please send a note to |
13+
| [email protected] so we can mail you a copy immediately. |
14+
+----------------------------------------------------------------------+
15+
| Author: Keyur Govande ([email protected]) |
16+
+----------------------------------------------------------------------+
17+
*/
18+
19+
/* $Id$ */
20+
21+
#ifdef HAVE_CONFIG_H
22+
#include "config.h"
23+
#endif
24+
25+
#include "php.h"
26+
#include "php_cli_process_title.h"
27+
#include "ps_title.h"
28+
29+
/* {{{ proto boolean cli_set_process_title(string arg)
30+
Return a boolean to confirm if the process title was successfully changed or not */
31+
PHP_FUNCTION(cli_set_process_title)
32+
{
33+
char *title = NULL;
34+
int title_len;
35+
int rc;
36+
37+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &title, &title_len) == FAILURE) {
38+
return;
39+
}
40+
41+
rc = set_ps_title(title);
42+
if (rc == PS_TITLE_SUCCESS) {
43+
RETURN_TRUE;
44+
}
45+
46+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "cli_set_process_title had an error: %s", ps_title_errno(rc));
47+
RETURN_FALSE;
48+
}
49+
/* }}} */
50+
51+
/* {{{ proto string cli_get_process_title()
52+
Return a string with the current process title. NULL if error. */
53+
PHP_FUNCTION(cli_get_process_title)
54+
{
55+
int length = 0;
56+
const char* title = NULL;
57+
int rc;
58+
59+
if (zend_parse_parameters_none() == FAILURE) {
60+
return;
61+
}
62+
63+
rc = get_ps_title(&length, &title);
64+
if (rc != PS_TITLE_SUCCESS) {
65+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "cli_get_process_title had an error: %s", ps_title_errno(rc));
66+
RETURN_NULL();
67+
}
68+
69+
RETURN_STRINGL(title, length, 1);
70+
}
71+
/* }}} */
72+
73+
/*
74+
* Local variables:
75+
* tab-width: 4
76+
* c-basic-offset: 4
77+
* End:
78+
* vim600: noet sw=4 ts=4 fdm=marker
79+
* vim<600: noet sw=4 ts=4
80+
*/

sapi/cli/php_cli_process_title.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| PHP Version 5 |
4+
+----------------------------------------------------------------------+
5+
| Copyright (c) 1997-2013 The PHP Group |
6+
+----------------------------------------------------------------------+
7+
| This source file is subject to version 3.01 of the PHP license, |
8+
| that is bundled with this package in the file LICENSE, and is |
9+
| available through the world-wide-web at the following url: |
10+
| http://www.php.net/license/3_01.txt |
11+
| If you did not receive a copy of the PHP license and are unable to |
12+
| obtain it through the world-wide-web, please send a note to |
13+
| [email protected] so we can mail you a copy immediately. |
14+
+----------------------------------------------------------------------+
15+
| Author: Keyur Govande ([email protected]) |
16+
+----------------------------------------------------------------------+
17+
*/
18+
19+
/* $Id$ */
20+
21+
#ifndef PHP_PS_TITLE_HEADER
22+
#define PHP_PS_TITLE_HEADER
23+
24+
ZEND_BEGIN_ARG_INFO(arginfo_cli_set_process_title, 0)
25+
ZEND_ARG_INFO(0, title)
26+
ZEND_END_ARG_INFO()
27+
28+
ZEND_BEGIN_ARG_INFO(arginfo_cli_get_process_title, 0)
29+
ZEND_END_ARG_INFO()
30+
31+
PHP_FUNCTION(cli_set_process_title);
32+
PHP_FUNCTION(cli_get_process_title);
33+
34+
#endif
35+
36+
/*
37+
* Local variables:
38+
* tab-width: 4
39+
* c-basic-offset: 4
40+
* End:
41+
* vim600: noet sw=4 ts=4 fdm=marker
42+
* vim<600: noet sw=4 ts=4
43+
*/

sapi/cli/php_cli_server.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@
103103
#include "php_http_parser.h"
104104
#include "php_cli_server.h"
105105

106+
#include "php_cli_process_title.h"
107+
106108
#define OUTPUT_NOT_CHECKED -1
107109
#define OUTPUT_IS_TTY 1
108110
#define OUTPUT_NOT_TTY 0
@@ -429,6 +431,12 @@ zend_module_entry cli_server_module_entry = {
429431
};
430432
/* }}} */
431433

434+
const zend_function_entry server_additional_functions[] = {
435+
PHP_FE(cli_set_process_title, arginfo_cli_set_process_title)
436+
PHP_FE(cli_get_process_title, arginfo_cli_get_process_title)
437+
{NULL, NULL, NULL}
438+
};
439+
432440
static int sapi_cli_server_startup(sapi_module_struct *sapi_module) /* {{{ */
433441
{
434442
if (php_module_startup(sapi_module, &cli_server_module_entry, 1) == FAILURE) {

sapi/cli/php_cli_server.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "SAPI.h"
2525

26+
extern const zend_function_entry server_additional_functions[];
2627
extern sapi_module_struct cli_server_sapi_module;
2728
extern int do_cli_server(int argc, char **argv TSRMLS_DC);
2829

0 commit comments

Comments
 (0)