xref: /PHP-7.3/sapi/cli/php_cli_process_title.c (revision 8d3f8ca1)
1 /*
2   +----------------------------------------------------------------------+
3   | PHP Version 7                                                        |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 1997-2018 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   | license@php.net so we can mail you a copy immediately.               |
14   +----------------------------------------------------------------------+
15   | Author: Keyur Govande (kgovande@gmail.com)                           |
16   +----------------------------------------------------------------------+
17 */
18 
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22 
23 #include "php.h"
24 #include "php_cli_process_title.h"
25 #include "ps_title.h"
26 
27 /* {{{ proto bool cli_set_process_title(string arg)
28    Return a boolean to confirm if the process title was successfully changed or not */
PHP_FUNCTION(cli_set_process_title)29 PHP_FUNCTION(cli_set_process_title)
30 {
31     char *title = NULL;
32     size_t title_len;
33     int rc;
34 
35     if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &title, &title_len) == FAILURE) {
36         return;
37     }
38 
39     rc = set_ps_title(title);
40     if (rc == PS_TITLE_SUCCESS) {
41         RETURN_TRUE;
42     }
43 
44     php_error_docref(NULL, E_WARNING, "cli_set_process_title had an error: %s", ps_title_errno(rc));
45     RETURN_FALSE;
46 }
47 /* }}} */
48 
49 /* {{{ proto string cli_get_process_title()
50    Return a string with the current process title. NULL if error. */
PHP_FUNCTION(cli_get_process_title)51 PHP_FUNCTION(cli_get_process_title)
52 {
53         int length = 0;
54         const char* title = NULL;
55         int rc;
56 
57         if (zend_parse_parameters_none() == FAILURE) {
58             return;
59         }
60 
61         rc = get_ps_title(&length, &title);
62         if (rc != PS_TITLE_SUCCESS) {
63                 php_error_docref(NULL, E_WARNING, "cli_get_process_title had an error: %s", ps_title_errno(rc));
64                 RETURN_NULL();
65         }
66 
67         RETURN_STRINGL(title, length);
68 }
69 /* }}} */
70 
71 /*
72  * Local variables:
73  * tab-width: 4
74  * c-basic-offset: 4
75  * End:
76  * vim600: noet sw=4 ts=4 fdm=marker
77  * vim<600: noet sw=4 ts=4
78  */
79