Documentation Source Text

Check-in [357e7b7813]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Update althttpd.c to use getrusage() for finding run-time information for the log. Always wait for children prior to reporting child runtimes.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 357e7b7813a09b7359fed8002af483c3e0a1ddb5
User & Date: drh 2012-10-26 14:21:39
Context
2012-10-29
13:15
Fix the name of the command-line tool in the whentouse.html page. check-in: bb4847adbb user: drh tags: trunk
2012-10-26
14:21
Update althttpd.c to use getrusage() for finding run-time information for the log. Always wait for children prior to reporting child runtimes. check-in: 357e7b7813 user: drh tags: trunk
2012-10-23
13:29
Added "charset=utf-8" marks to the content type in althttpd.c. check-in: de32cdc42a user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to misc/althttpd.c.

77
78
79
80
81
82
83

84
85
86
87
88
89
90
...
180
181
182
183
184
185
186
187
188
189

190
191
192
193
194
195
196
...
197
198
199
200
201
202
203
204
205

206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdarg.h>
#include <time.h>
#include <sys/times.h>
#include <netdb.h>
#include <errno.h>

#ifdef linux
#include <sys/sendfile.h>
#endif
#include <assert.h>

/*
** Configure the server by setting the following macros and recompiling.
................................................................................
  FILE *log;
  if( zTmpNam ){
    unlink(zTmpNam);
  }
  if( zLogFile && !omitLog ){
    time_t now;
    struct tm *pTm;
    struct tms sTms;
    double rScale;
    int i;

    char zDate[200];
    char *zRM = zRemoteUser ? zRemoteUser : "*";

    if( zScript==0 || zScript[0]==0 ) zScript = "*";
    if( zRemoteAddr==0 || zRemoteAddr[0]==0 ) zRemoteAddr = "*";
    if( zHttpHost==0 || zHttpHost[0]==0 ) zHttpHost = "*";
    if( zReferer==0 || zReferer[0]==0 ) zReferer = "*";
................................................................................
    for(i=0; zReferer[i]; i++){ 
      if( isspace(zReferer[i]) ){ zReferer = "*"; break; }
    }
    if( zAgent==0 || zAgent[0]==0 ) zAgent = "*";
    time(&now);
    pTm = localtime(&now);
    strftime(zDate, sizeof(zDate), "%Y-%m-%d %H:%M:%S", pTm);
    times(&sTms);
    rScale = 1.0/(double)sysconf(_SC_CLK_TCK);

    if( (log = fopen(zLogFile,"a"))!=0 ){
#ifdef COMBINED_LOG_FORMAT
      strftime(zDate, sizeof(zDate), "%d/%b/%Y:%H:%M:%S %z", pTm);
      fprintf(log, "%s - - [%s] \"%s %s %s\" %s %d \"%s\" \"%s\"\n",
              zRemoteAddr, zDate, zMethod, zScript, zProtocol,
              zReplyStatus, nOut, zReferer, zAgent);
#else
      strftime(zDate, sizeof(zDate), "%Y-%m-%d %H:%M:%S", pTm);
      fprintf(log, "%s %s %s://%s%s %s %s %d %d %g %g %g %g %d %d %s %s\n", 
          zDate, zRemoteAddr, zHttp, zHttpHost, zScript, zReferer,
          zReplyStatus, nIn, nOut,
          rScale*sTms.tms_utime,
          rScale*sTms.tms_stime,
          rScale*sTms.tms_cutime,
          rScale*sTms.tms_cstime,
          (int)(now - beginTime),
          nRequest, zAgent, zRM
      );
#endif
      fclose(log);
      nIn = nOut = 0;
    }







>







 







|
<

>







 







|
|
>








|


|
|
|
|







77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
...
181
182
183
184
185
186
187
188

189
190
191
192
193
194
195
196
197
...
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdarg.h>
#include <time.h>
#include <sys/times.h>
#include <netdb.h>
#include <errno.h>
#include <sys/resource.h>
#ifdef linux
#include <sys/sendfile.h>
#endif
#include <assert.h>

/*
** Configure the server by setting the following macros and recompiling.
................................................................................
  FILE *log;
  if( zTmpNam ){
    unlink(zTmpNam);
  }
  if( zLogFile && !omitLog ){
    time_t now;
    struct tm *pTm;
    struct rusage self, children;

    int i;
    int waitStatus;
    char zDate[200];
    char *zRM = zRemoteUser ? zRemoteUser : "*";

    if( zScript==0 || zScript[0]==0 ) zScript = "*";
    if( zRemoteAddr==0 || zRemoteAddr[0]==0 ) zRemoteAddr = "*";
    if( zHttpHost==0 || zHttpHost[0]==0 ) zHttpHost = "*";
    if( zReferer==0 || zReferer[0]==0 ) zReferer = "*";
................................................................................
    for(i=0; zReferer[i]; i++){ 
      if( isspace(zReferer[i]) ){ zReferer = "*"; break; }
    }
    if( zAgent==0 || zAgent[0]==0 ) zAgent = "*";
    time(&now);
    pTm = localtime(&now);
    strftime(zDate, sizeof(zDate), "%Y-%m-%d %H:%M:%S", pTm);
    waitpid(-1, &waitStatus, WNOHANG);
    getrusage(RUSAGE_SELF, &self);
    getrusage(RUSAGE_CHILDREN, &children);
    if( (log = fopen(zLogFile,"a"))!=0 ){
#ifdef COMBINED_LOG_FORMAT
      strftime(zDate, sizeof(zDate), "%d/%b/%Y:%H:%M:%S %z", pTm);
      fprintf(log, "%s - - [%s] \"%s %s %s\" %s %d \"%s\" \"%s\"\n",
              zRemoteAddr, zDate, zMethod, zScript, zProtocol,
              zReplyStatus, nOut, zReferer, zAgent);
#else
      strftime(zDate, sizeof(zDate), "%Y-%m-%d %H:%M:%S", pTm);
      fprintf(log, "%s %s %s://%s%s %s %s %d %d %d %d %d %d %d %d %s %s\n", 
          zDate, zRemoteAddr, zHttp, zHttpHost, zScript, zReferer,
          zReplyStatus, nIn, nOut,
          (int)(self.ru_utime.tv_sec*1000000 + self.ru_utime.tv_usec),
          (int)(self.ru_stime.tv_sec*1000000 + self.ru_stime.tv_usec),
          (int)(children.ru_utime.tv_sec*1000000 + children.ru_utime.tv_usec),
          (int)(children.ru_stime.tv_sec*1000000 + children.ru_stime.tv_usec),
          (int)(now - beginTime),
          nRequest, zAgent, zRM
      );
#endif
      fclose(log);
      nIn = nOut = 0;
    }