Lines 83-88
Link Here
|
83 |
#if APR_HAVE_STRINGS_H |
83 |
#if APR_HAVE_STRINGS_H |
84 |
#include <strings.h> |
84 |
#include <strings.h> |
85 |
#endif |
85 |
#endif |
|
|
86 |
#include <unistd.h> |
87 |
#include <pwd.h> |
88 |
|
86 |
|
89 |
|
87 |
#define BUFSIZE 65536 |
90 |
#define BUFSIZE 65536 |
88 |
#define ERRMSGSZ 82 |
91 |
#define ERRMSGSZ 82 |
Lines 100-162
Link Here
|
100 |
apr_size_t nRead, nWrite; |
103 |
apr_size_t nRead, nWrite; |
101 |
int use_strftime = 0; |
104 |
int use_strftime = 0; |
102 |
int now = 0; |
105 |
int now = 0; |
|
|
106 |
int c; |
103 |
const char *szLogRoot; |
107 |
const char *szLogRoot; |
|
|
108 |
char *user = NULL; |
104 |
apr_file_t *f_stdin, *nLogFD = NULL, *nLogFDprev = NULL; |
109 |
apr_file_t *f_stdin, *nLogFD = NULL, *nLogFDprev = NULL; |
105 |
apr_pool_t *pool; |
110 |
apr_pool_t *pool; |
106 |
char *ptr = NULL; |
111 |
char *ptr = NULL; |
|
|
112 |
struct passwd *pwd; |
107 |
|
113 |
|
108 |
apr_app_initialize(&argc, &argv, NULL); |
114 |
apr_app_initialize(&argc, &argv, NULL); |
109 |
atexit(apr_terminate); |
115 |
atexit(apr_terminate); |
110 |
|
116 |
|
111 |
apr_pool_create(&pool, NULL); |
117 |
apr_pool_create(&pool, NULL); |
112 |
if (argc < 3 || argc > 4) { |
118 |
optind = 0; /* initialize getopt */ |
113 |
fprintf(stderr, |
119 |
while ((c = getopt(argc, (char * const *) argv, "u:f:t:o:m:")) >= 0) |
114 |
"Usage: %s <logfile> <rotation time in seconds> " |
120 |
{ |
115 |
"[offset minutes from UTC] or <rotation size in megabytes>\n\n", |
121 |
switch (c) |
|
|
122 |
{ |
123 |
case 'f': |
124 |
szLogRoot = optarg; |
125 |
break; |
126 |
case 'o': |
127 |
utc_offset = atoi(optarg) * 60; |
128 |
break; |
129 |
case 'm': |
130 |
sRotation = atoi(optarg) * 1048576; |
131 |
if (sRotation == 0) { |
132 |
fprintf(stderr, "Invalid rotation size parameter\n"); |
133 |
exit(1); |
134 |
} |
135 |
break; |
136 |
case 't': |
137 |
tRotation = atoi(optarg); |
138 |
if (tRotation <= 0) { |
139 |
fprintf(stderr, "Rotation time must be > 0\n"); |
140 |
exit(6); |
141 |
} |
142 |
break; |
143 |
case 'u': |
144 |
user = optarg; |
145 |
break; |
146 |
default: |
147 |
fprintf(stderr,"Invalid usage\n"); |
148 |
fprintf(stderr, |
149 |
"Usage: %s -f <logfile> -t <rotation time in seconds> " |
150 |
"-o [offset minutes from UTC] or -m <rotation size in megabytes>\n\n", |
116 |
argv[0]); |
151 |
argv[0]); |
117 |
#ifdef OS2 |
152 |
#ifdef OS2 |
118 |
fprintf(stderr, |
153 |
fprintf(stderr, |
119 |
"Add this:\n\nTransferLog \"|%s.exe /some/where 86400\"\n\n", |
154 |
"Add this:\n\nTransferLog \"|%s.exe -f /some/where -t 86400\"\n\n", |
120 |
argv[0]); |
155 |
argv[0]); |
121 |
#else |
156 |
#else |
122 |
fprintf(stderr, |
157 |
fprintf(stderr, |
123 |
"Add this:\n\nTransferLog \"|%s /some/where 86400\"\n\n", |
158 |
"Add this:\n\nTransferLog \"|%s -f /some/where -t 86400\"\n\n", |
124 |
argv[0]); |
159 |
argv[0]); |
125 |
fprintf(stderr, |
160 |
fprintf(stderr, |
126 |
"or \n\nTransferLog \"|%s /some/where 5M\"\n\n", argv[0]); |
161 |
"or \n\nTransferLog \"|%s -f /some/where -m 5\"\n\n", argv[0]); |
127 |
#endif |
162 |
#endif |
128 |
fprintf(stderr, |
163 |
fprintf(stderr, |
129 |
"to httpd.conf. The generated name will be /some/where.nnnn " |
164 |
"to httpd.conf. The generated name will be /some/where.nnnn " |
130 |
"where nnnn is the\nsystem time at which the log nominally " |
165 |
"where nnnn is the\nsystem time at which the log nominally " |
131 |
"starts (N.B. if using a rotation time,\nthe time will always " |
166 |
"starts (N.B. if using a rotation time,\nthe time will always " |
132 |
"be a multiple of the rotation time, so you can synchronize\n" |
167 |
"be a multiple of the rotation time, so you can synchronize\n" |
133 |
"cron scripts with it). At the end of each rotation time or " |
168 |
"cron scripts with it). At the end of each rotation time or " |
134 |
"when the file size\nis reached a new log is started.\n"); |
169 |
"when the file size\nis reached a new log is started.\n"); |
135 |
exit(1); |
|
|
136 |
} |
137 |
|
138 |
szLogRoot = argv[1]; |
139 |
|
170 |
|
140 |
ptr = strchr (argv[2], 'M'); |
171 |
exit(1); |
141 |
if (ptr) { |
172 |
} |
142 |
if (*(ptr+1) == '\0') { |
173 |
} |
143 |
sRotation = atoi(argv[2]) * 1048576; |
174 |
|
144 |
} |
175 |
if (user != NULL) { |
145 |
if (sRotation == 0) { |
176 |
pwd = getpwnam(user); |
146 |
fprintf(stderr, "Invalid rotation size parameter\n"); |
177 |
if (pwd == NULL) { |
147 |
exit(1); |
178 |
fprintf(stderr,"User %s unknown\n",user); |
148 |
} |
179 |
exit(1); |
149 |
} |
180 |
} |
150 |
else { |
181 |
if (setuid(pwd->pw_uid) != 0) { |
151 |
if (argc >= 4) { |
182 |
fprintf(stderr,"Failed to setuid %s\n",user); |
152 |
utc_offset = atoi(argv[3]) * 60; |
183 |
exit(1); |
153 |
} |
184 |
} |
154 |
tRotation = atoi(argv[2]); |
185 |
} |
155 |
if (tRotation <= 0) { |
|
|
156 |
fprintf(stderr, "Rotation time must be > 0\n"); |
157 |
exit(6); |
158 |
} |
159 |
} |
160 |
|
186 |
|
161 |
use_strftime = (strchr(szLogRoot, '%') != NULL); |
187 |
use_strftime = (strchr(szLogRoot, '%') != NULL); |
162 |
if (apr_file_open_stdin(&f_stdin, pool) != APR_SUCCESS) { |
188 |
if (apr_file_open_stdin(&f_stdin, pool) != APR_SUCCESS) { |