Skip to content

Commit 7a9a5b1

Browse files
zmyWLmatyhtf
andauthored
Optimize bug report message (#4368)
* update * update * update * Revert "update" This reverts commit cc2c580. * update * update * Delete useless code * update * update * Update base.cc Co-authored-by: 韩天峰-Rango <[email protected]>
1 parent 396edca commit 7a9a5b1

File tree

7 files changed

+54
-2
lines changed

7 files changed

+54
-2
lines changed

ext-src/php_swoole.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,13 @@ static void fatal_error(int code, const char *format, ...) {
418418
zend_end_try();
419419
}
420420

421+
static void bug_report_message_init() {
422+
SwooleG.bug_report_message += swoole::std_string::format(
423+
"PHP_VERSION : %s\n",
424+
PHP_VERSION
425+
);
426+
}
427+
421428
/* {{{ PHP_MINIT_FUNCTION
422429
*/
423430
PHP_MINIT_FUNCTION(swoole) {
@@ -745,6 +752,9 @@ PHP_MINIT_FUNCTION(swoole) {
745752
}
746753

747754
swoole_init();
755+
756+
// init bug report message
757+
bug_report_message_init();
748758
if (strcmp("cli", sapi_module.name) == 0 || strcmp("phpdbg", sapi_module.name) == 0) {
749759
SWOOLE_G(cli) = 1;
750760
}

include/swoole.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,9 @@ struct Global {
666666
//-----------------------[Hook]--------------------------
667667
void *hooks[SW_MAX_HOOK_TYPE];
668668
std::function<bool(Reactor *reactor, int &event_num)> user_exit_condition;
669+
670+
// bug report message
671+
std::string bug_report_message = "";
669672
};
670673

671674
std::string dirname(const std::string &file);

include/swoole_ssl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <openssl/x509.h>
3434
#include <openssl/x509v3.h>
3535
#include <openssl/rand.h>
36+
#include <openssl/opensslv.h>
3637

3738
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
3839
#define SW_SUPPORT_DTLS
@@ -169,5 +170,6 @@ void swoole_ssl_server_http_advise(swoole::SSLContext &);
169170
const char *swoole_ssl_get_error();
170171
int swoole_ssl_get_ex_connection_index();
171172
int swoole_ssl_get_ex_port_index();
173+
std::string swoole_ssl_get_version_message();
172174

173175
#endif

src/core/base.cc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "swoole_async.h"
4242
#include "swoole_c_api.h"
4343
#include "swoole_coroutine_c_api.h"
44+
#include "swoole_ssl.h"
4445

4546
using swoole::String;
4647

@@ -110,6 +111,30 @@ void *sw_realloc(void *ptr, size_t size) {
110111
return SwooleG.std_allocator.realloc(ptr, size);
111112
}
112113

114+
static void bug_report_message_init() {
115+
SwooleG.bug_report_message += "\n" + std::string(SWOOLE_BUG_REPORT) + "\n";
116+
117+
struct utsname u;
118+
if (uname(&u) != -1) {
119+
SwooleG.bug_report_message += swoole::std_string::format(
120+
"OS: %s %s %s %s\n",
121+
u.sysname,
122+
u.release,
123+
u.version,
124+
u.machine);
125+
}
126+
127+
#ifdef __VERSION__
128+
SwooleG.bug_report_message += swoole::std_string::format(
129+
"GCC_VERSION: %s\n",
130+
__VERSION__);
131+
#endif
132+
133+
#ifdef SW_USE_OPENSSL
134+
SwooleG.bug_report_message += swoole_ssl_get_version_message();
135+
136+
#endif
137+
}
113138
void swoole_init(void) {
114139
if (SwooleG.init) {
115140
return;
@@ -169,6 +194,9 @@ void swoole_init(void) {
169194
SwooleG.use_signalfd = 1;
170195
SwooleG.enable_signalfd = 1;
171196
#endif
197+
198+
// init bug report message
199+
bug_report_message_init();
172200
}
173201

174202
SW_EXTERN_C_BEGIN

src/os/process_pool.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ int ProcessPool::wait() {
704704
exit_worker->id,
705705
exit_status.get_code(),
706706
exit_status.get_signal(),
707-
exit_status.get_signal() == SIGSEGV ? "\n" SWOOLE_BUG_REPORT : "");
707+
exit_status.get_signal() == SIGSEGV ? SwooleG.bug_report_message.c_str() : "");
708708
}
709709
new_pid = spawn(exit_worker);
710710
if (new_pid < 0) {

src/protocol/ssl.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "swoole_string.h"
1919
#include "swoole_socket.h"
2020
#include "swoole_ssl.h"
21+
#include "swoole_util.h"
2122

2223
#ifdef SW_USE_OPENSSL
2324

@@ -54,6 +55,14 @@ static int swoole_ssl_verify_cookie(SSL *ssl, const uchar *cookie, uint cookie_l
5455
#define MAYBE_UNUSED
5556
#endif
5657

58+
std::string swoole_ssl_get_version_message() {
59+
std::string message = swoole::std_string::format(
60+
"OPENSSL_VERSION: %s\n",
61+
OPENSSL_VERSION_TEXT);
62+
63+
return message;
64+
}
65+
5766
static void MAYBE_UNUSED swoole_ssl_lock_callback(int mode, int type, const char *file, int line);
5867

5968
void swoole_ssl_init(void) {

src/server/manager.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ void Server::check_worker_exit_status(int worker_id, const ExitStatus &exit_stat
209209
worker_id,
210210
exit_status.get_code(),
211211
exit_status.get_signal(),
212-
exit_status.get_signal() == SIGSEGV ? "\n" SWOOLE_BUG_REPORT : "");
212+
exit_status.get_signal() == SIGSEGV ? SwooleG.bug_report_message.c_str() : "");
213213
if (onWorkerError != nullptr) {
214214
onWorkerError(this, worker_id, exit_status);
215215
}

0 commit comments

Comments
 (0)