Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
10bfefca
Commit
10bfefca
authored
Nov 13, 2011
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrite VCLI_ReadResult() to be much more robust.
parent
62986111
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
35 deletions
+47
-35
cli_common.c
lib/libvarnish/cli_common.c
+47
-35
No files found.
lib/libvarnish/cli_common.c
View file @
10bfefca
...
@@ -121,7 +121,7 @@ read_tmo(int fd, char *ptr, unsigned len, double tmo)
...
@@ -121,7 +121,7 @@ read_tmo(int fd, char *ptr, unsigned len, double tmo)
struct
pollfd
pfd
;
struct
pollfd
pfd
;
if
(
tmo
>
0
)
if
(
tmo
>
0
)
to
=
tmo
*
1e3
;
to
=
(
int
)(
tmo
*
1e3
)
;
else
else
to
=
-
1
;
to
=
-
1
;
pfd
.
fd
=
fd
;
pfd
.
fd
=
fd
;
...
@@ -150,44 +150,56 @@ VCLI_ReadResult(int fd, unsigned *status, char **ptr, double tmo)
...
@@ -150,44 +150,56 @@ VCLI_ReadResult(int fd, unsigned *status, char **ptr, double tmo)
char
res
[
CLI_LINE0_LEN
];
/* For NUL */
char
res
[
CLI_LINE0_LEN
];
/* For NUL */
int
i
,
j
;
int
i
,
j
;
unsigned
u
,
v
,
s
;
unsigned
u
,
v
,
s
;
char
*
p
;
char
*
p
=
NULL
;
const
char
*
err
=
"CLI communication error (hdr)"
;
if
(
status
==
NULL
)
if
(
status
==
NULL
)
status
=
&
s
;
status
=
&
s
;
if
(
ptr
!=
NULL
)
if
(
ptr
!=
NULL
)
*
ptr
=
NULL
;
*
ptr
=
NULL
;
i
=
read_tmo
(
fd
,
res
,
CLI_LINE0_LEN
,
tmo
);
do
{
if
(
i
!=
CLI_LINE0_LEN
)
{
i
=
read_tmo
(
fd
,
res
,
CLI_LINE0_LEN
,
tmo
);
*
status
=
CLIS_COMMS
;
if
(
i
!=
CLI_LINE0_LEN
)
if
(
ptr
!=
NULL
)
break
;
*
ptr
=
strdup
(
"CLI communication error (hdr)"
);
if
(
i
!=
0
)
if
(
res
[
3
]
!=
' '
)
return
(
i
);
break
;
return
(
*
status
);
}
if
(
res
[
CLI_LINE0_LEN
-
1
]
!=
'\n'
)
assert
(
i
==
CLI_LINE0_LEN
);
break
;
assert
(
res
[
3
]
==
' '
);
assert
(
res
[
CLI_LINE0_LEN
-
1
]
==
'\n'
);
res
[
CLI_LINE0_LEN
-
1
]
=
'\0'
;
res
[
CLI_LINE0_LEN
-
1
]
=
'\0'
;
j
=
sscanf
(
res
,
"%u %u
\n
"
,
&
u
,
&
v
);
j
=
sscanf
(
res
,
"%u %u
\n
"
,
&
u
,
&
v
);
if
(
j
!=
2
)
assert
(
j
==
2
);
break
;
*
status
=
u
;
p
=
malloc
(
v
+
1L
);
err
=
"CLI communication error (body)"
;
assert
(
p
!=
NULL
);
i
=
read_tmo
(
fd
,
p
,
v
+
1
,
tmo
);
*
status
=
u
;
if
(
i
<
0
)
{
p
=
malloc
(
v
+
1L
);
*
status
=
CLIS_COMMS
;
if
(
p
==
NULL
)
free
(
p
);
break
;
if
(
ptr
!=
NULL
)
*
ptr
=
strdup
(
"CLI communication error (body)"
);
i
=
read_tmo
(
fd
,
p
,
v
+
1
,
tmo
);
return
(
i
);
if
(
i
<
0
)
}
break
;
assert
(
i
==
v
+
1
);
if
(
i
!=
v
+
1
)
assert
(
p
[
v
]
==
'\n'
);
break
;
p
[
v
]
=
'\0'
;
if
(
p
[
v
]
!=
'\n'
)
if
(
ptr
==
NULL
)
break
;
p
[
v
]
=
'\0'
;
if
(
ptr
==
NULL
)
free
(
p
);
else
*
ptr
=
p
;
return
(
0
);
}
while
(
0
);
if
(
p
!=
NULL
)
free
(
p
);
free
(
p
);
else
*
status
=
CLIS_COMMS
;
*
ptr
=
p
;
if
(
ptr
!=
NULL
)
return
(
0
);
*
ptr
=
strdup
(
err
);
return
(
*
status
);
}
}
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