Index: trunk/willow/src/willow/wlogwriter.c |
— | — | @@ -1,83 +0,0 @@ |
2 | | -/* @(#) $Header$ */ |
3 | | -/* This source code is in the public domain. */ |
4 | | -/* |
5 | | - * Willow: Lightweight HTTP reverse-proxy. |
6 | | - * wlogwriter: child process for log writing. |
7 | | - */ |
8 | | - |
9 | | -#if defined __SUNPRO_C || defined __DECC || defined __HP_cc |
10 | | -# pragma ident "@(#)$Header$" |
11 | | -#endif |
12 | | - |
13 | | -#include <stdio.h> |
14 | | -#include <unistd.h> |
15 | | -#include <errno.h> |
16 | | -#include <string.h> |
17 | | -#include <stdlib.h> |
18 | | -#include <signal.h> |
19 | | - |
20 | | -#include "willow.h" |
21 | | -#include "wlogwriter.h" |
22 | | -#include "wconfig.h" |
23 | | -#include "wlog.h" |
24 | | - |
25 | | -static void wlogwriter_run(int); |
26 | | - |
27 | | -void |
28 | | -wlogwriter_start(fd) |
29 | | - int *fd; |
30 | | -{ |
31 | | - switch (fork()) { |
32 | | - case -1: |
33 | | - wlog(WLOG_ERROR, "fork: %s", strerror(errno)); |
34 | | - exit(8); |
35 | | - /*NOTREACHED*/ |
36 | | - case 0: |
37 | | - (void)close(fd[0]); |
38 | | - wlogwriter_run(fd[1]); |
39 | | - break; |
40 | | - default: |
41 | | - (void)close(fd[1]); |
42 | | - break; |
43 | | - } |
44 | | -} |
45 | | - |
46 | | -static void |
47 | | -wlogwriter_run(pipe) |
48 | | - int pipe; |
49 | | -{ |
50 | | - FILE *inf, *outf; |
51 | | - char *line; |
52 | | - size_t lnsz; |
53 | | - |
54 | | - lnsz = 8192; |
55 | | - line = malloc(lnsz); |
56 | | - |
57 | | - (void)signal(SIGPIPE, SIG_IGN); |
58 | | - |
59 | | -#ifdef HAVE_SETPROCTITLE |
60 | | - setproctitle("log writer: %s", config.access_log); |
61 | | -#endif |
62 | | - wlog(WLOG_NOTICE, "wlogwriter starting (pid %d) for %s", (int)getpid(), config.access_log); |
63 | | - |
64 | | - if ((inf = fdopen(pipe, "r")) == NULL) { |
65 | | - perror("wlogwriter: fdopen"); |
66 | | - exit(8); |
67 | | - } |
68 | | - /*LINTED unsafe fopen*/ |
69 | | - if ((outf = fopen(config.access_log, "a")) == NULL) { |
70 | | - perror(config.access_log); |
71 | | - exit(8); |
72 | | - } |
73 | | - |
74 | | - while (fgets(line, lnsz, inf)) { |
75 | | - if (fputs(line, outf) == EOF || fflush(outf) == EOF) { |
76 | | - wlog(WLOG_NOTICE, "fatal: writing access log: %s", strerror(errno)); |
77 | | - exit(8); |
78 | | - } |
79 | | - } |
80 | | - |
81 | | - wlog(WLOG_NOTICE, "wlogwriter terminating"); |
82 | | - exit(0); |
83 | | -} |
84 | | - |