Skip to content

Commit 2809a67

Browse files
vobruba-martinweltling
authored andcommitted
Pass error severity to SAPI modules and raise corresponding error level in Apache
1 parent 2e3903b commit 2809a67

File tree

11 files changed

+42
-14
lines changed

11 files changed

+42
-14
lines changed

ext/standard/basic_functions.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -4740,7 +4740,7 @@ PHPAPI int _php_error_log_ex(int opt_err, char *message, size_t message_len, cha
47404740

47414741
case 4: /* send to SAPI */
47424742
if (sapi_module.log_message) {
4743-
sapi_module.log_message(message);
4743+
sapi_module.log_message(message, -1);
47444744
} else {
47454745
return FAILURE;
47464746
}

main/SAPI.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ struct _sapi_module_struct {
241241
char *(*read_cookies)(void);
242242

243243
void (*register_server_variables)(zval *track_vars_array);
244-
void (*log_message)(char *message);
244+
void (*log_message)(char *message, int syslog_type_int);
245245
double (*get_request_time)(void);
246246
void (*terminate_process)(void);
247247

main/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ PHPAPI ZEND_COLD void php_log_err_with_severity(char *log_message, int syslog_ty
698698
/* Otherwise fall back to the default logging location, if we have one */
699699

700700
if (sapi_module.log_message) {
701-
sapi_module.log_message(log_message);
701+
sapi_module.log_message(log_message, syslog_type_int);
702702
}
703703
PG(in_error_log) = 0;
704704
}

sapi/apache2handler/sapi_apache2.c

+31-3
Original file line numberDiff line numberDiff line change
@@ -314,16 +314,44 @@ php_apache_sapi_flush(void *server_context)
314314
}
315315
}
316316

317-
static void php_apache_sapi_log_message(char *msg)
317+
static void php_apache_sapi_log_message(char *msg, int syslog_type_int)
318318
{
319319
php_struct *ctx;
320+
int aplog_type = APLOG_ERR;
320321

321322
ctx = SG(server_context);
322323

324+
switch (syslog_type_int) {
325+
case LOG_EMERG:
326+
aplog_type = APLOG_EMERG;
327+
break;
328+
case LOG_ALERT:
329+
aplog_type = APLOG_ALERT;
330+
break;
331+
case LOG_CRIT:
332+
aplog_type = APLOG_CRIT;
333+
break;
334+
case LOG_ERR:
335+
aplog_type = APLOG_ERR;
336+
break;
337+
case LOG_WARNING:
338+
aplog_type = APLOG_WARNING;
339+
break;
340+
case LOG_NOTICE:
341+
aplog_type = APLOG_NOTICE;
342+
break;
343+
case LOG_INFO:
344+
aplog_type = APLOG_INFO;
345+
break;
346+
case LOG_DEBUG:
347+
aplog_type = APLOG_DEBUG;
348+
break;
349+
}
350+
323351
if (ctx == NULL) { /* we haven't initialized our ctx yet, oh well */
324352
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, 0, NULL, "%s", msg);
325353
} else {
326-
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, ctx->r, "%s", msg);
354+
ap_log_rerror(APLOG_MARK, aplog_type, 0, ctx->r, "%s", msg);
327355
}
328356
}
329357

@@ -332,7 +360,7 @@ static void php_apache_sapi_log_message_ex(char *msg, request_rec *r)
332360
if (r) {
333361
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, msg, r->filename);
334362
} else {
335-
php_apache_sapi_log_message(msg);
363+
php_apache_sapi_log_message(msg, -1);
336364
}
337365
}
338366

sapi/cgi/cgi_main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ static void sapi_cgi_register_variables(zval *track_vars_array)
711711
}
712712
}
713713

714-
static void sapi_cgi_log_message(char *message)
714+
static void sapi_cgi_log_message(char *message, int syslog_type_int)
715715
{
716716
if (fcgi_is_fastcgi() && CGIG(fcgi_logging)) {
717717
fcgi_request *request;

sapi/cli/php_cli.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ static void sapi_cli_register_variables(zval *track_vars_array) /* {{{ */
377377
}
378378
/* }}} */
379379

380-
static void sapi_cli_log_message(char *message) /* {{{ */
380+
static void sapi_cli_log_message(char *message, int syslog_type_int) /* {{{ */
381381
{
382382
fprintf(stderr, "%s\n", message);
383383
}

sapi/cli/php_cli_server.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ static void sapi_cli_server_register_variables(zval *track_vars_array) /* {{{ */
689689
zend_hash_apply_with_arguments(&client->request.headers, (apply_func_args_t)sapi_cli_server_register_entry_cb, 1, track_vars_array);
690690
} /* }}} */
691691

692-
static void sapi_cli_server_log_message(char *msg) /* {{{ */
692+
static void sapi_cli_server_log_message(char *msg, int syslog_type_int) /* {{{ */
693693
{
694694
char buf[52];
695695

@@ -1184,7 +1184,7 @@ static void php_cli_server_logf(const char *format, ...) /* {{{ */
11841184
}
11851185

11861186
if (sapi_module.log_message) {
1187-
sapi_module.log_message(buf);
1187+
sapi_module.log_message(buf, -1);
11881188
}
11891189

11901190
efree(buf);

sapi/embed/php_embed.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static void php_embed_send_header(sapi_header_struct *sapi_header, void *server_
9494
{
9595
}
9696

97-
static void php_embed_log_message(char *message)
97+
static void php_embed_log_message(char *message, int syslog_type_int)
9898
{
9999
fprintf (stderr, "%s\n", message);
100100
}

sapi/fpm/fpm/fpm_main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ void sapi_cgi_log_fastcgi(int level, char *message, size_t len)
660660

661661
/* {{{ sapi_cgi_log_message
662662
*/
663-
static void sapi_cgi_log_message(char *message)
663+
static void sapi_cgi_log_message(char *message, int syslog_type_int)
664664
{
665665
zlog(ZLOG_NOTICE, "PHP message: %s", message);
666666
}

sapi/litespeed/lsapi_main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ static int sapi_lsapi_send_headers(sapi_headers_struct *sapi_headers)
398398

399399
/* {{{ sapi_lsapi_send_headers
400400
*/
401-
static void sapi_lsapi_log_message(char *message)
401+
static void sapi_lsapi_log_message(char *message, int syslog_type_int)
402402
{
403403
char buf[8192];
404404
int len = strlen( message );

sapi/phpdbg/phpdbg.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ static void php_sapi_phpdbg_send_header(sapi_header_struct *sapi_header, void *s
795795
}
796796
/* }}} */
797797

798-
static void php_sapi_phpdbg_log_message(char *message) /* {{{ */
798+
static void php_sapi_phpdbg_log_message(char *message, int syslog_type_int) /* {{{ */
799799
{
800800
/*
801801
* We must not request TSRM before being booted

0 commit comments

Comments
 (0)