httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sam...@c2.org
Subject error_log with an fd rather than FILE *
Date Mon, 08 Apr 1996 20:02:52 GMT
	here's a patch. 

	I was hoping to use BUFF *, but there is no bprintf. A bprintf
would be a good thing, I think. Perhaps I will go through the FreeBSD
libc and convert the printf from there into a bprintf for inclusion in
buff.c

diff -C3 apache_1.0.3/src/http_log.c napache/src/http_log.c
*** apache_1.0.3/src/http_log.c	Sat Feb 17 00:35:35 1996
--- napache/src/http_log.c	Mon Apr  8 12:18:59 1996
***************
*** 66,79 ****
  
  #include <stdarg.h>
  
  void open_error_log(server_rec *s, pool *p)
  {
      char *fname;
    
      fname = server_root_relative (p, s->error_fname);
!     if(!(s->error_log = pfopen(p, fname, "a"))) {
          fprintf(stderr,"httpd: could not open error log file %s.\n", fname);
!         perror("fopen");
          exit(1);
      }
  }
--- 66,83 ----
  
  #include <stdarg.h>
  
+ static int xfer_flags = ( O_WRONLY | O_APPEND | O_CREAT );
+ static mode_t xfer_mode = ( S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH );
+ 
  void open_error_log(server_rec *s, pool *p)
  {
      char *fname;
    
      fname = server_root_relative (p, s->error_fname);
!     if(!(s->error_log = popenf(p, fname, xfer_flags, xfer_mode)))
!       {
          fprintf(stderr,"httpd: could not open error log file %s.\n", fname);
!         perror("open");
          exit(1);
      }
  }
***************
*** 100,107 ****
  }
  
  void error_log2stderr(server_rec *s) {
!     if(fileno(s->error_log) != STDERR_FILENO)
!         dup2(fileno(s->error_log),STDERR_FILENO);
  }
  
  void log_pid(pool *p, char *pid_fname) {
--- 104,111 ----
  }
  
  void error_log2stderr(server_rec *s) {
!     if(s->error_log != STDERR_FILENO)
!         dup2(s->error_log,STDERR_FILENO);
  }
  
  void log_pid(pool *p, char *pid_fname) {
***************
*** 119,126 ****
  }
  
  void log_error(char *err, server_rec *s) {
!     fprintf(s->error_log, "[%s] %s\n",get_time(),err);
!     fflush(s->error_log);
  }
  
  void
--- 123,132 ----
  }
  
  void log_error(char *err, server_rec *s) {
!   char buf[MAX_STRING_LEN];
! 
!     sprintf(buf, "[%s] %s\n",get_time(),err);
!     write(s->error_log, buf, strlen(buf));
  }
  
  void
***************
*** 128,163 ****
  	    server_rec *s)
  {
      const char *p, *q;
  
      p = strerror(errno);
      q = get_time();
  
      if (file != NULL)
! 	fprintf(s->error_log, "[%s] %s: %s: %s\n", q, routine, file, p);
      else
! 	fprintf(s->error_log, "[%s] %s: %s\n", q, routine, p);
!     if (msg != NULL) fprintf(s->error_log, "[%s] - %s\n", q, msg);
! 
!     fflush(s->error_log);
  }
  
  void
  log_printf(const server_rec *s, const char *fmt, ...)
  {
      va_list args;
      
!     fprintf(s->error_log, "[%s] ", get_time());
      va_start (args, fmt);
!     vfprintf (s->error_log, fmt, args);
      va_end (args);
  
!     fputc('\n', s->error_log);
  }
  
  void log_reason(char *reason, char *file, request_rec *r) {
!     fprintf (r->server->error_log,
  	     "[%s] access to %s failed for %s, reason: %s\n",
  	     get_time(), file, r->connection->remote_name, reason);
!     fflush (r->server->error_log);
  }
  
--- 134,184 ----
  	    server_rec *s)
  {
      const char *p, *q;
+     char buf[MAX_STRING_LEN];
  
      p = strerror(errno);
      q = get_time();
  
      if (file != NULL)
!       {
! 	sprintf(buf, "[%s] %s: %s: %s\n", q, routine, file, p);
! 	write(s->error_log, buf, strlen(buf));
!       }
      else
!       {
! 	sprintf(buf, "[%s] %s: %s\n", q, routine, p);
! 	write(s->error_log, buf, strlen(buf));
!       }
!     if (msg != NULL)
!       {
! 	sprintf(buf, "[%s] - %s\n", q, msg);
! 	write(s->error_log, buf, strlen(buf));
!       }
  }
  
  void
  log_printf(const server_rec *s, const char *fmt, ...)
  {
      va_list args;
+     char buf[HUGE_STRING_LEN];
+ 
      
!     sprintf(buf, "[%s] ", get_time());
!     write(s->error_log, buf, strlen(buf));
      va_start (args, fmt);
!     vsprintf (buf, fmt, args);
!     write(s->error_log, buf, strlen(buf));
      va_end (args);
  
!     write(s->error_log, "\n", 1);
  }
  
  void log_reason(char *reason, char *file, request_rec *r) {
!   char buf[HUGE_STRING_LEN];
! 
!     sprintf (buf,
  	     "[%s] access to %s failed for %s, reason: %s\n",
  	     get_time(), file, r->connection->remote_name, reason);
!   write(r->server->error_log, buf, strlen(buf));
  }
  
Only in napache/src: http_log.c~
Only in napache/src: http_log.o
Only in napache/src: http_main.o
Only in napache/src: http_protocol.o
Only in napache/src: http_request.o
diff -C3 apache_1.0.3/src/httpd.h napache/src/httpd.h
*** apache_1.0.3/src/httpd.h	Mon Mar 18 11:26:37 1996
--- napache/src/httpd.h	Mon Apr  8 12:14:16 1996
***************
*** 373,379 ****
    /* Log files --- note that transfer log is now in the modules... */
    
    char *error_fname;
!   FILE *error_log;
    
    /* Module-specific configuration for server, and defaults... */
  
--- 373,379 ----
    /* Log files --- note that transfer log is now in the modules... */
    
    char *error_fname;
!   int error_log;
    
    /* Module-specific configuration for server, and defaults... */
-- 
Sameer Parekh					Voice:   510-601-9777x3
Community ConneXion, Inc.			FAX:     510-601-9734
The Internet Privacy Provider			Dialin:  510-658-6376
http://www.c2.net/ (or login as "guest")		sameer@c2.net

Mime
View raw message