Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnishevent
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
varnishevent
Commits
2b404e42
Commit
2b404e42
authored
Sep 24, 2015
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use fwrite() instead of fprintf() for output (saves parsing the format
string)
parent
9866aa56
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
17 deletions
+27
-17
format.c
src/format.c
+6
-6
test_format.c
src/test/test_format.c
+13
-6
varnishevent.h
src/varnishevent.h
+1
-1
writer.c
src/writer.c
+7
-4
No files found.
src/format.c
View file @
2b404e42
...
...
@@ -1464,11 +1464,10 @@ fmt_resize(size_t curlen)
}
char
*
FMT_Format
(
tx_t
*
tx
)
FMT_Format
(
tx_t
*
tx
,
size_t
*
curlen
)
{
compiled_fmt_t
fmt
;
char
*
p
=
obuf
;
size_t
curlen
=
0
;
CHECK_OBJ_NOTNULL
(
tx
,
TX_MAGIC
);
assert
(
tx
->
state
==
TX_SUBMITTED
);
...
...
@@ -1490,21 +1489,22 @@ FMT_Format(tx_t *tx)
tx
->
state
=
TX_FORMATTING
;
*
p
=
'\0'
;
*
curlen
=
0
;
for
(
int
i
=
0
;
i
<
fmt
.
n
;
i
++
)
{
char
*
s
=
NULL
;
size_t
len
=
0
;
if
(
fmt
.
str
[
i
]
!=
NULL
)
{
curlen
+=
fmt
.
strlen
[
i
];
fmt_resize
(
curlen
);
*
curlen
+=
fmt
.
strlen
[
i
];
fmt_resize
(
*
curlen
);
memcpy
(
p
,
fmt
.
str
[
i
],
fmt
.
strlen
[
i
]);
p
+=
fmt
.
strlen
[
i
];
}
if
(
fmt
.
formatter
[
i
]
!=
NULL
)
{
(
fmt
.
formatter
[
i
])(
tx
,
&
fmt
.
args
[
i
],
&
s
,
&
len
);
if
(
s
!=
NULL
&&
len
!=
0
)
{
curlen
+=
len
;
fmt_resize
(
curlen
);
*
curlen
+=
len
;
fmt_resize
(
*
curlen
);
memcpy
(
p
,
s
,
len
);
p
+=
len
;
}
...
...
src/test/test_format.c
View file @
2b404e42
...
...
@@ -1881,6 +1881,7 @@ static const char
chunk_t
c
[
NTAGS
];
struct
tm
*
tm
;
time_t
t
=
1427743146
;
size_t
len
;
printf
(
"... testing FMT_*() interface
\n
"
);
...
...
@@ -1945,13 +1946,14 @@ static const char
add_record_data
(
&
tx
,
SLT_RespStatus
,
&
rec
[
9
],
&
c
[
9
],
"200"
);
add_record_data
(
&
tx
,
SLT_ReqAcct
,
&
rec
[
10
],
&
c
[
10
],
REQACCT_PAYLOAD
);
os
=
FMT_Format
(
&
tx
);
os
=
FMT_Format
(
&
tx
,
&
len
);
#define EXP_DEFAULT_OUTPUT "127.0.0.1 - varnish [%d/%b/%Y:%T %z] "\
"\"GET http://bazquux.com/foo HTTP/1.1\" 200 105 "\
"\"http://foobar.com/\" \"Mozilla\"\n"
tm
=
localtime
(
&
t
);
MAN
(
strftime
(
strftime_s
,
BUFSIZ
,
EXP_DEFAULT_OUTPUT
,
tm
));
VMASSERT
(
strcmp
(
os
,
strftime_s
)
==
0
,
"'%s' != '%s'"
,
os
,
strftime_s
);
MASSERT
(
len
==
strlen
(
strftime_s
));
/* Client format with all formatters */
FMT_Fini
();
...
...
@@ -2027,7 +2029,7 @@ static const char
}
setup_full_client_tx
(
&
tx
,
node
,
nptr
,
rec
,
c
);
os
=
FMT_Format
(
&
tx
);
os
=
FMT_Format
(
&
tx
,
&
len
);
#define EXP_FULL_CLIENT_OUTPUT "105 c 15963 HTTP/1.1 127.0.0.1 60 foohdr "\
"barhdr - GET 283 bar=baz&quux=wilco GET "\
"http://foobar.com/foo?bar=baz&quux=wilco HTTP/1.1 200 "\
...
...
@@ -2037,6 +2039,7 @@ static const char
tm
=
localtime
(
&
t
);
MAN
(
strftime
(
strftime_s
,
BUFSIZ
,
EXP_FULL_CLIENT_OUTPUT
,
tm
));
VMASSERT
(
strcmp
(
os
,
strftime_s
)
==
0
,
"'%s' != '%s'"
,
os
,
strftime_s
);
MASSERT
(
len
==
strlen
(
strftime_s
));
/* Backend format with all formatters */
FMT_Fini
();
...
...
@@ -2103,7 +2106,7 @@ static const char
}
setup_full_backend_tx
(
&
tx
,
node
,
nptr
,
rec
,
c
);
os
=
FMT_Format
(
&
tx
);
os
=
FMT_Format
(
&
tx
,
&
len
);
#define EXP_FULL_BACKEND_OUTPUT "105 b 15703 HTTP/1.1 default(127.0.0.1,,80) "\
"283 foohdr barhdr - GET 60 bar=baz&quux=wilco GET "\
"http://foobar.com/foo?bar=baz&quux=wilco HTTP/1.1 200 "\
...
...
@@ -2113,6 +2116,7 @@ static const char
tm
=
localtime
(
&
t
);
MAN
(
strftime
(
strftime_s
,
BUFSIZ
,
EXP_FULL_BACKEND_OUTPUT
,
tm
));
VMASSERT
(
strcmp
(
os
,
strftime_s
)
==
0
,
"'%s' != '%s'"
,
os
,
strftime_s
);
MASSERT
(
len
==
strlen
(
strftime_s
));
/* Both backend and client formats */
FMT_Fini
();
...
...
@@ -2216,16 +2220,18 @@ static const char
}
setup_full_client_tx
(
&
tx
,
node
,
nptr
,
rec
,
c
);
os
=
FMT_Format
(
&
tx
);
os
=
FMT_Format
(
&
tx
,
&
len
);
tm
=
localtime
(
&
t
);
MAN
(
strftime
(
strftime_s
,
BUFSIZ
,
EXP_FULL_CLIENT_OUTPUT
,
tm
));
VMASSERT
(
strcmp
(
os
,
strftime_s
)
==
0
,
"'%s' != '%s'"
,
os
,
strftime_s
);
MASSERT
(
len
==
strlen
(
strftime_s
));
setup_full_backend_tx
(
&
tx
,
node
,
nptr
,
rec
,
c
);
os
=
FMT_Format
(
&
tx
);
os
=
FMT_Format
(
&
tx
,
&
len
);
tm
=
localtime
(
&
t
);
MAN
(
strftime
(
strftime_s
,
BUFSIZ
,
EXP_FULL_BACKEND_OUTPUT
,
tm
));
VMASSERT
(
strcmp
(
os
,
strftime_s
)
==
0
,
"'%s' != '%s'"
,
os
,
strftime_s
);
MASSERT
(
len
==
strlen
(
strftime_s
));
/* Raw format */
FMT_Fini
();
...
...
@@ -2259,12 +2265,13 @@ static const char
#define HEALTH_PAYLOAD "b Still healthy 4--X-RH 5 4 5 0.032728 0.035774 " \
"HTTP/1.1 200 OK"
add_record_data
(
&
tx
,
SLT_Backend_health
,
&
rec
[
0
],
&
c
[
0
],
HEALTH_PAYLOAD
);
os
=
FMT_Format
(
&
tx
);
os
=
FMT_Format
(
&
tx
,
&
len
);
#define EXP_FULL_RAW_OUTPUT "[%d/%b/%Y:%T %z] %F-%T.529143 "\
"b Still healthy 4--X-RH 5 4 5 0.032728 0.035774 HTTP/1.1 200 OK 4711\n"
tm
=
localtime
(
&
t
);
MAN
(
strftime
(
strftime_s
,
BUFSIZ
,
EXP_FULL_RAW_OUTPUT
,
tm
));
VMASSERT
(
strcmp
(
os
,
strftime_s
)
==
0
,
"'%s' != '%s'"
,
os
,
strftime_s
);
MASSERT
(
len
==
strlen
(
strftime_s
));
/* Illegal backend formats */
FMT_Fini
();
...
...
src/varnishevent.h
View file @
2b404e42
...
...
@@ -278,7 +278,7 @@ void MON_Output(void);
int
FMT_Init
(
char
*
err
);
int
FMT_GetMaxIdx
(
void
);
int
FMT_Estimate_RecsPerTx
(
void
);
char
*
FMT_Format
(
tx_t
*
tx
);
char
*
FMT_Format
(
tx_t
*
tx
,
size_t
*
len
);
void
FMT_Fini
(
void
);
/* handler.c */
...
...
src/writer.c
View file @
2b404e42
...
...
@@ -180,6 +180,7 @@ wrt_write(tx_t *tx)
{
char
*
os
;
int
ready
=
1
;
size_t
len
;
CHECK_OBJ_NOTNULL
(
tx
,
TX_MAGIC
);
assert
(
tx
->
state
==
TX_SUBMITTED
);
...
...
@@ -207,7 +208,7 @@ wrt_write(tx_t *tx)
AZ
(
pthread_mutex_unlock
(
&
reopen_lock
));
VRMB
();
os
=
FMT_Format
(
tx
);
os
=
FMT_Format
(
tx
,
&
len
);
assert
(
tx
->
state
==
TX_WRITTEN
);
if
(
blocking
)
{
...
...
@@ -242,17 +243,19 @@ wrt_write(tx_t *tx)
}
}
if
(
ready
)
{
errno
=
0
;
double
start
=
VTIM_mono
();
int
ret
=
fprintf
(
fo
,
"%s"
,
os
);
int
items
=
fwrite
(
os
,
1
,
len
,
fo
);
writet
+=
VTIM_mono
()
-
start
;
if
(
ret
<
0
)
{
if
(
ferror
(
fo
)
||
items
<
len
)
{
LOG_Log
(
LOG_ERR
,
"Output error %d (%s), DATA DISCARDED: %s"
,
errno
,
strerror
(
errno
),
os
);
errors
++
;
clearerr
(
fo
);
}
else
{
writes
++
;
bytes
+=
strlen
(
os
)
;
bytes
+=
len
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment