Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
2c38caa1
Unverified
Commit
2c38caa1
authored
Sep 29, 2021
by
Wen Hui
Committed by
GitHub
Sep 28, 2021
Browse files
adding missing error check for fstat (#9532)
parent
4be2dd6a
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/cluster.c
View file @
2c38caa1
...
...
@@ -142,9 +142,15 @@ int clusterLoadConfig(char *filename) {
}
}
if
(
redis_fstat
(
fileno
(
fp
),
&
sb
)
==
-
1
)
{
serverLog
(
LL_WARNING
,
"Unable to obtain the cluster node config file stat %s: %s"
,
filename
,
strerror
(
errno
));
exit
(
1
);
}
/* Check if the file is zero-length: if so return C_ERR to signal
* we have to write the config. */
if
(
fstat
(
fileno
(
fp
),
&
sb
)
!=
-
1
&&
sb
.
st_size
==
0
)
{
if
(
sb
.
st_size
==
0
)
{
fclose
(
fp
);
return
C_ERR
;
}
...
...
@@ -383,13 +389,14 @@ int clusterSaveConfig(int do_fsync) {
if
((
fd
=
open
(
server
.
cluster_configfile
,
O_WRONLY
|
O_CREAT
,
0644
))
==
-
1
)
goto
err
;
if
(
redis_fstat
(
fd
,
&
sb
)
==
-
1
)
goto
err
;
/* Pad the new payload if the existing file length is greater. */
if
(
fstat
(
fd
,
&
sb
)
!=
-
1
)
{
if
(
sb
.
st_size
>
(
off_t
)
content_size
)
{
ci
=
sdsgrowzero
(
ci
,
sb
.
st_size
);
memset
(
ci
+
content_size
,
'\n'
,
sb
.
st_size
-
content_size
);
}
if
(
sb
.
st_size
>
(
off_t
)
content_size
)
{
ci
=
sdsgrowzero
(
ci
,
sb
.
st_size
);
memset
(
ci
+
content_size
,
'\n'
,
sb
.
st_size
-
content_size
);
}
if
(
write
(
fd
,
ci
,
sdslen
(
ci
))
!=
(
ssize_t
)
sdslen
(
ci
))
goto
err
;
if
(
do_fsync
)
{
server
.
cluster
->
todo_before_sleep
&=
~
CLUSTER_TODO_FSYNC_CONFIG
;
...
...
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