+AP_DECLARE(void) ap_log_cserror_(const char *file, int line, int module_index,
+ int level, apr_status_t status,
+ const conn_rec *c, const server_rec *s,
+ const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ log_error_core(file, line, module_index, level, status, s, c,
+ NULL, NULL, fmt, args);
+ va_end(args);
+}
+
+AP_DECLARE(void) ap_log_cerror_(const char *file, int line, int module_index,
+ int level, apr_status_t status,
+ const conn_rec *c, const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ log_error_core(file, line, module_index, level, status, c->base_server, c,
+ NULL, NULL, fmt, args);
+ va_end(args);
+}
+
+#define BYTES_LOGGED_PER_LINE 16
+#define LOG_BYTES_BUFFER_SIZE (BYTES_LOGGED_PER_LINE * 3 + 2)
+
+static void fmt_data(unsigned char *buf, const void *vdata, apr_size_t len, apr_size_t *off)
+{
+ const unsigned char *data = (const unsigned char *)vdata;
+ unsigned char *chars;
+ unsigned char *hex;
+ apr_size_t this_time = 0;
+
+ memset(buf, ' ', LOG_BYTES_BUFFER_SIZE - 1);
+ buf[LOG_BYTES_BUFFER_SIZE - 1] = '\0';
+
+ chars = buf; /* start character dump here */
+ hex = buf + BYTES_LOGGED_PER_LINE + 1; /* start hex dump here */
+ while (*off < len && this_time < BYTES_LOGGED_PER_LINE) {
+ unsigned char c = data[*off];
+
+ if (apr_isprint(c)
+ && c != '\\') { /* backslash will be escaped later, which throws
+ * off the formatting
+ */
+ *chars = c;
+ }
+ else {
+ *chars = '.';
+ }
+
+ if ((c >> 4) >= 10) {
+ *hex = 'a' + ((c >> 4) - 10);
+ }
+ else {
+ *hex = '0' + (c >> 4);
+ }
+
+ if ((c & 0x0F) >= 10) {
+ *(hex + 1) = 'a' + ((c & 0x0F) - 10);
+ }
+ else {
+ *(hex + 1) = '0' + (c & 0x0F);
+ }
+
+ chars += 1;
+ hex += 2;
+ *off += 1;
+ ++this_time;
+ }
+}
+
+static void log_data_core(const char *file, int line, int module_index,
+ int level, const server_rec *s,
+ const conn_rec *c, const request_rec *r,
+ const char *label, const void *data, apr_size_t len,
+ unsigned int flags)
+{
+ unsigned char buf[LOG_BYTES_BUFFER_SIZE];
+ apr_size_t off;
+ char prefix[20];
+
+ if (!(flags & AP_LOG_DATA_SHOW_OFFSET)) {
+ prefix[0] = '\0';
+ }
+
+ if (len > 0xffff) { /* bug in caller? */
+ len = 0xffff;
+ }
+
+ if (label) {
+ log_error_va_glue(file, line, module_index, level, APR_SUCCESS, s,
+ c, r, NULL, "%s (%" APR_SIZE_T_FMT " bytes)",
+ label, len);
+ }
+
+ off = 0;
+ while (off < len) {
+ if (flags & AP_LOG_DATA_SHOW_OFFSET) {
+ apr_snprintf(prefix, sizeof prefix, "%04x: ", (unsigned int)off);
+ }
+ fmt_data(buf, data, len, &off);
+ log_error_va_glue(file, line, module_index, level, APR_SUCCESS, s,
+ c, r, NULL, "%s%s", prefix, buf);
+ }
+}
+
+AP_DECLARE(void) ap_log_data_(const char *file, int line,
+ int module_index, int level,
+ const server_rec *s, const char *label,
+ const void *data, apr_size_t len,
+ unsigned int flags)
+{
+ log_data_core(file, line, module_index, level, s, NULL, NULL, label,
+ data, len, flags);
+}
+
+AP_DECLARE(void) ap_log_rdata_(const char *file, int line,
+ int module_index, int level,
+ const request_rec *r, const char *label,
+ const void *data, apr_size_t len,
+ unsigned int flags)
+{
+ log_data_core(file, line, module_index, level, r->server, NULL, r, label,
+ data, len, flags);
+}
+
+AP_DECLARE(void) ap_log_cdata_(const char *file, int line,
+ int module_index, int level,
+ const conn_rec *c, const char *label,
+ const void *data, apr_size_t len,
+ unsigned int flags)
+{
+ log_data_core(file, line, module_index, level, c->base_server, c, NULL,
+ label, data, len, flags);
+}
+
+AP_DECLARE(void) ap_log_csdata_(const char *file, int line, int module_index,
+ int level, const conn_rec *c, const server_rec *s,
+ const char *label, const void *data,
+ apr_size_t len, unsigned int flags)
+{
+ log_data_core(file, line, module_index, level, s, c, NULL, label, data,
+ len, flags);
+}
+
+AP_DECLARE(void) ap_log_command_line(apr_pool_t *plog, server_rec *s)
+{
+ int i;
+ process_rec *process = s->process;
+ char *result;
+ int len_needed = 0;
+
+ /* Piece together the command line from the pieces
+ * in process->argv, with spaces in between.
+ */
+ for (i = 0; i < process->argc; i++) {
+ len_needed += strlen(process->argv[i]) + 1;
+ }
+
+ result = (char *) apr_palloc(plog, len_needed);
+ *result = '\0';
+
+ for (i = 0; i < process->argc; i++) {
+ strcat(result, process->argv[i]);
+ if ((i+1)< process->argc) {
+ strcat(result, " ");
+ }
+ }
+ ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s, APLOGNO(00094)
+ "Command line: '%s'", result);
+}
+
+/* grab bag function to log commonly logged and shared info */
+AP_DECLARE(void) ap_log_mpm_common(server_rec *s)
+{
+ ap_log_error(APLOG_MARK, APLOG_DEBUG , 0, s, APLOGNO(02639)
+ "Using SO_REUSEPORT: %s (%d)",
+ ap_have_so_reuseport ? "yes" : "no",
+ ap_num_listen_buckets);
+}
+
+AP_DECLARE(void) ap_remove_pid(apr_pool_t *p, const char *rel_fname)
+{
+ apr_status_t rv;
+ const char *fname = ap_server_root_relative(p, rel_fname);
+
+ if (fname != NULL) {
+ rv = apr_file_remove(fname, p);
+ if (rv != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, rv, ap_server_conf, APLOGNO(00095)
+ "failed to remove PID file %s", fname);
+ }
+ else {
+ ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf, APLOGNO(00096)
+ "removed PID file %s (pid=%" APR_PID_T_FMT ")",
+ fname, getpid());
+ }
+ }
+}
+