|
| 1 | +#include "handlers_api.h" |
| 2 | +#include "remote_config.h" |
| 3 | +#include <signal.h> |
| 4 | +#include <php.h> |
| 5 | + |
| 6 | +/* We need to do signal blocking for the remote config signaling to not interfere with some PHP functions. |
| 7 | + * See e.g. https://github.com/php/php-src/issues/16800 |
| 8 | + * I don't know the full problem space, so I expect there might be functions missing here, and we need to eventually expand this list. |
| 9 | + */ |
| 10 | +static void dd_handle_signal(zif_handler original_function, INTERNAL_FUNCTION_PARAMETERS) { |
| 11 | + sigset_t x; |
| 12 | + sigemptyset(&x); |
| 13 | + sigaddset(&x, SIGVTALRM); |
| 14 | + sigprocmask(SIG_BLOCK, &x, NULL); |
| 15 | + |
| 16 | + original_function(INTERNAL_FUNCTION_PARAM_PASSTHRU); |
| 17 | + |
| 18 | + sigprocmask(SIG_UNBLOCK, &x, NULL); |
| 19 | + ddtrace_check_for_new_config_now(); |
| 20 | +} |
| 21 | + |
| 22 | +#define BLOCKSIGFN(function) \ |
| 23 | + static zif_handler dd_handle_signal_zif_##function;\ |
| 24 | + static ZEND_FUNCTION(dd_handle_signal_##function) { \ |
| 25 | + dd_handle_signal(dd_handle_signal_zif_##function, INTERNAL_FUNCTION_PARAM_PASSTHRU); \ |
| 26 | + } |
| 27 | + |
| 28 | +#define BLOCK(x) \ |
| 29 | + x(ftp_alloc) \ |
| 30 | + x(ftp_append) \ |
| 31 | + x(ftp_cdup) \ |
| 32 | + x(ftp_chdir) \ |
| 33 | + x(ftp_chmod) \ |
| 34 | + x(ftp_close) \ |
| 35 | + x(ftp_connect) \ |
| 36 | + x(ftp_delete) \ |
| 37 | + x(ftp_exec) \ |
| 38 | + x(ftp_fget) \ |
| 39 | + x(ftp_fput) \ |
| 40 | + x(ftp_get) \ |
| 41 | + x(ftp_get_option) \ |
| 42 | + x(ftp_login) \ |
| 43 | + x(ftp_mdtm) \ |
| 44 | + x(ftp_mkdir) \ |
| 45 | + x(ftp_mlsd) \ |
| 46 | + x(ftp_nb_continue) \ |
| 47 | + x(ftp_nb_fget) \ |
| 48 | + x(ftp_nb_fput) \ |
| 49 | + x(ftp_nb_get) \ |
| 50 | + x(ftp_nb_put) \ |
| 51 | + x(ftp_nlist) \ |
| 52 | + x(ftp_pasv) \ |
| 53 | + x(ftp_put) \ |
| 54 | + x(ftp_pwd) \ |
| 55 | + x(ftp_quit) \ |
| 56 | + x(ftp_raw) \ |
| 57 | + x(ftp_rawlist) \ |
| 58 | + x(ftp_rename) \ |
| 59 | + x(ftp_rmdir) \ |
| 60 | + x(ftp_site) \ |
| 61 | + x(ftp_size) \ |
| 62 | + x(ftp_ssl_connect) \ |
| 63 | + x(ftp_systype) \ |
| 64 | + |
| 65 | +BLOCK(BLOCKSIGFN) |
| 66 | + |
| 67 | +void ddtrace_signal_block_handlers_startup() { |
| 68 | +#define BLOCKFNENTRY(function) { ZEND_STRL(#function), &dd_handle_signal_zif_##function, ZEND_FN(dd_handle_signal_##function) }, |
| 69 | + datadog_php_zif_handler handlers[] = { BLOCK(BLOCKFNENTRY) }; |
| 70 | + |
| 71 | + size_t handlers_len = sizeof handlers / sizeof handlers[0]; |
| 72 | + for (size_t i = 0; i < handlers_len; ++i) { |
| 73 | + datadog_php_install_handler(handlers[i]); |
| 74 | + } |
| 75 | +} |
0 commit comments