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
Show 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
;
do
{
i
=
read_tmo
(
fd
,
res
,
CLI_LINE0_LEN
,
tmo
);
i
=
read_tmo
(
fd
,
res
,
CLI_LINE0_LEN
,
tmo
);
if
(
i
!=
CLI_LINE0_LEN
)
{
if
(
i
!=
CLI_LINE0_LEN
)
*
status
=
CLIS_COMMS
;
break
;
if
(
ptr
!=
NULL
)
*
ptr
=
strdup
(
"CLI communication error (hdr)"
);
if
(
res
[
3
]
!=
' '
)
if
(
i
!=
0
)
break
;
return
(
i
);
return
(
*
status
);
if
(
res
[
CLI_LINE0_LEN
-
1
]
!=
'\n'
)
}
break
;
assert
(
i
==
CLI_LINE0_LEN
);
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
);
assert
(
j
==
2
);
if
(
j
!=
2
)
break
;
err
=
"CLI communication error (body)"
;
*
status
=
u
;
*
status
=
u
;
p
=
malloc
(
v
+
1L
);
p
=
malloc
(
v
+
1L
);
assert
(
p
!=
NULL
);
if
(
p
==
NULL
)
break
;
i
=
read_tmo
(
fd
,
p
,
v
+
1
,
tmo
);
i
=
read_tmo
(
fd
,
p
,
v
+
1
,
tmo
);
if
(
i
<
0
)
{
if
(
i
<
0
)
*
status
=
CLIS_COMMS
;
break
;
free
(
p
);
if
(
i
!=
v
+
1
)
if
(
ptr
!=
NULL
)
break
;
*
ptr
=
strdup
(
"CLI communication error (body)"
);
if
(
p
[
v
]
!=
'\n'
)
return
(
i
);
break
;
}
assert
(
i
==
v
+
1
);
assert
(
p
[
v
]
==
'\n'
);
p
[
v
]
=
'\0'
;
p
[
v
]
=
'\0'
;
if
(
ptr
==
NULL
)
if
(
ptr
==
NULL
)
free
(
p
);
free
(
p
);
else
else
*
ptr
=
p
;
*
ptr
=
p
;
return
(
0
);
return
(
0
);
}
while
(
0
);
if
(
p
!=
NULL
)
free
(
p
);
*
status
=
CLIS_COMMS
;
if
(
ptr
!=
NULL
)
*
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