etc: Add environment option to run init.d/ashd silently.
[ashd.git] / src / accesslog.c
index 7328c4d..0c7ef8d 100644 (file)
@@ -96,6 +96,16 @@ static void logitem(struct logdata *data, char o, char *d)
            qputs(h, out);
        }
        break;
+    case 'p':
+       if(!data->resp || ((h = getheader(data->resp, d)) == NULL)) {
+           putc('-', out);
+       } else {
+           qputs(h, out);
+       }
+       break;
+    case 'P':
+       logitem(data, 'p', sprintf3("X-Ash-%s", d));
+       break;
     case 'u':
        qputs(data->req->url, out);
        break;
@@ -223,9 +233,12 @@ static int passdata(struct bufio *in, struct bufio *out, off_t *passed)
     
     total = 0;
     while(!bioeof(in)) {
-       if((read = biocopysome(out, in)) < 0)
-           return(-1);
-       total += read;
+       if((read = biordata(in)) > 0) {
+           if((read = biowritesome(out, in->rbuf.b + in->rh, read)) < 0)
+               return(-1);
+           in->rh += read;
+           total += read;
+       }
        if(biorspace(in) && (biofillsome(in) < 0))
            return(-1);
     }
@@ -241,6 +254,7 @@ static void filterreq(struct muth *mt, va_list args)
     int pfds[2];
     struct hthead *resp;
     struct bufio *cl, *hd;
+    struct stdiofd *cli, *hdi;
     struct logdata data;
     
     hd = NULL;
@@ -248,10 +262,10 @@ static void filterreq(struct muth *mt, va_list args)
     data = defdata;
     data.req = req;
     gettimeofday(&data.start, NULL);
-    cl = mtbioopen(fd, 1, 600, "r+", NULL);
+    cl = mtbioopen(fd, 1, 600, "r+", &cli);
     if(socketpair(PF_UNIX, SOCK_STREAM, 0, pfds))
        goto out;
-    hd = mtbioopen(pfds[1], 1, 600, "r+", NULL);
+    hd = mtbioopen(pfds[1], 1, 600, "r+", &hdi);
     if(sendreq(ch, req, pfds[0])) {
        close(pfds[0]);
        goto out;
@@ -265,6 +279,8 @@ static void filterreq(struct muth *mt, va_list args)
     shutdown(pfds[1], SHUT_WR);
     if((resp = parseresponseb(hd)) == NULL)
        goto out;
+    cli->sendrights = hdi->rights;
+    hdi->rights = -1;
     data.resp = resp;
     writerespb(cl, resp);
     bioprintf(cl, "\r\n");
@@ -502,7 +518,7 @@ int main(int argc, char **argv)
            pidfile = optarg;
            break;
        case 'a':
-           format = "%A - - [%{%d/%b/%Y:%H:%M:%S %z}t] \"%m %u %v\" %c %o \"%R\" \"%G\"";
+           format = "%A - %{log-user}P [%{%d/%b/%Y:%H:%M:%S %z}t] \"%m %u %v\" %c %o \"%R\" \"%G\"";
            break;
        default:
            usage(stderr);