php_cli_process_title.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Copyright (c) The PHP Group |
  4. +----------------------------------------------------------------------+
  5. | This source file is subject to version 3.01 of the PHP license, |
  6. | that is bundled with this package in the file LICENSE, and is |
  7. | available through the world-wide-web at the following url: |
  8. | https://www.php.net/license/3_01.txt |
  9. | If you did not receive a copy of the PHP license and are unable to |
  10. | obtain it through the world-wide-web, please send a note to |
  11. | license@php.net so we can mail you a copy immediately. |
  12. +----------------------------------------------------------------------+
  13. | Author: Keyur Govande (kgovande@gmail.com) |
  14. +----------------------------------------------------------------------+
  15. */
  16. #ifdef HAVE_CONFIG_H
  17. #include "config.h"
  18. #endif
  19. #include "php.h"
  20. #include "php_cli_process_title.h"
  21. #include "ps_title.h"
  22. /* {{{ Return a boolean to confirm if the process title was successfully changed or not */
  23. PHP_FUNCTION(cli_set_process_title)
  24. {
  25. char *title = NULL;
  26. size_t title_len;
  27. int rc;
  28. if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &title, &title_len) == FAILURE) {
  29. RETURN_THROWS();
  30. }
  31. rc = set_ps_title(title);
  32. if (rc == PS_TITLE_SUCCESS) {
  33. RETURN_TRUE;
  34. }
  35. php_error_docref(NULL, E_WARNING, "cli_set_process_title had an error: %s", ps_title_errno(rc));
  36. RETURN_FALSE;
  37. }
  38. /* }}} */
  39. /* {{{ Return a string with the current process title. NULL if error. */
  40. PHP_FUNCTION(cli_get_process_title)
  41. {
  42. int length = 0;
  43. const char* title = NULL;
  44. int rc;
  45. if (zend_parse_parameters_none() == FAILURE) {
  46. RETURN_THROWS();
  47. }
  48. rc = get_ps_title(&length, &title);
  49. if (rc != PS_TITLE_SUCCESS) {
  50. php_error_docref(NULL, E_WARNING, "cli_get_process_title had an error: %s", ps_title_errno(rc));
  51. RETURN_NULL();
  52. }
  53. RETURN_STRINGL(title, length);
  54. }
  55. /* }}} */