Skip to content

Allow FPM_LOG_BUFFER to be adjusted in conf file, changed the buffer to be dynamically allocated #18328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions sapi/fpm/fpm/fpm_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "fastcgi.h"
#include "zlog.h"

#define FPM_LOG_BUFFER 1024
#define FPM_LOG_BUFFER fpm_global_config.log_limit

static char *fpm_log_format = NULL;
static int fpm_log_fd = -1;
Expand Down Expand Up @@ -108,8 +108,13 @@ int fpm_log_init_child(struct fpm_worker_pool_s *wp) /* {{{ */
int fpm_log_write(char *log_format) /* {{{ */
{
char *s, *b;
char buffer[FPM_LOG_BUFFER+1];
int token, test;
char *buffer = malloc(FPM_LOG_BUFFER + 1);
if (!buffer) {
zlog(ZLOG_WARNING, "unable to allocate memory for log buffer");
return -1;
}
memset(buffer, '\0', FPM_LOG_BUFFER + 1);
int token, test;
size_t len, len2;
struct fpm_scoreboard_proc_s proc, *proc_p;
struct fpm_scoreboard_s *scoreboard;
Expand All @@ -121,6 +126,7 @@ int fpm_log_write(char *log_format) /* {{{ */
#endif

if (!log_format && (!fpm_log_format || fpm_log_fd == -1)) {
free(buffer);
return -1;
}

Expand All @@ -137,24 +143,26 @@ int fpm_log_write(char *log_format) /* {{{ */
scoreboard = fpm_scoreboard_get();
if (!scoreboard) {
zlog(ZLOG_WARNING, "unable to get scoreboard while preparing the access log");
free(buffer);
return -1;
}
proc_p = fpm_scoreboard_proc_acquire(NULL, -1, 0);
if (!proc_p) {
zlog(ZLOG_WARNING, "[pool %s] Unable to acquire shm slot while preparing the access log", scoreboard->pool);
free(buffer);
return -1;
}
proc = *proc_p;
fpm_scoreboard_proc_release(proc_p);

if (UNEXPECTED(fpm_access_log_suppress(&proc))) {
free(buffer);
return -1;
}
}

token = 0;

memset(buffer, '\0', sizeof(buffer));
b = buffer;
len = 0;

Expand Down Expand Up @@ -202,6 +210,7 @@ int fpm_log_write(char *log_format) /* {{{ */
}
} else {
zlog(ZLOG_WARNING, "only 'total', 'user' or 'system' are allowed as a modifier for %%%c ('%s')", *s, format);
free(buffer);
return -1;
}

Expand Down Expand Up @@ -236,6 +245,7 @@ int fpm_log_write(char *log_format) /* {{{ */

} else {
zlog(ZLOG_WARNING, "only 'seconds', 'milli', 'milliseconds', 'micro' or 'microseconds' are allowed as a modifier for %%%c ('%s')", *s, format);
free(buffer);
return -1;
}
format[0] = '\0';
Expand All @@ -244,6 +254,7 @@ int fpm_log_write(char *log_format) /* {{{ */
case 'e': /* fastcgi env */
if (format[0] == '\0') {
zlog(ZLOG_WARNING, "the name of the environment variable must be set between embraces for %%%c", *s);
free(buffer);
return -1;
}

Expand Down Expand Up @@ -293,6 +304,7 @@ int fpm_log_write(char *log_format) /* {{{ */

} else {
zlog(ZLOG_WARNING, "only 'bytes', 'kilo', 'kilobytes', 'mega' or 'megabytes' are allowed as a modifier for %%%c ('%s')", *s, format);
free(buffer);
return -1;
}
format[0] = '\0';
Expand All @@ -307,6 +319,7 @@ int fpm_log_write(char *log_format) /* {{{ */
case 'o': /* header output */
if (format[0] == '\0') {
zlog(ZLOG_WARNING, "the name of the header must be set between embraces for %%%c", *s);
free(buffer);
return -1;
}
if (!test) {
Expand Down Expand Up @@ -444,18 +457,21 @@ int fpm_log_write(char *log_format) /* {{{ */
}
if (s[1] == '\0') {
zlog(ZLOG_WARNING, "missing closing embrace in the access.format");
free(buffer);
return -1;
}
}
break;

default:
zlog(ZLOG_WARNING, "Invalid token in the access.format (%%%c)", *s);
free(buffer);
return -1;
}

if (*s != '}' && format[0] != '\0') {
zlog(ZLOG_WARNING, "embrace is not allowed for modifier %%%c", *s);
free(buffer);
return -1;
}
s++;
Expand Down Expand Up @@ -485,6 +501,7 @@ int fpm_log_write(char *log_format) /* {{{ */
zend_quiet_write(fpm_log_fd, buffer, len + 1);
}

free(buffer);
return 0;
}
/* }}} */
Expand Down Expand Up @@ -522,4 +539,4 @@ static int fpm_access_log_suppress(struct fpm_scoreboard_proc_s *proc)
}

return 0;
}
}
Loading