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
c0f4d193
Commit
c0f4d193
authored
Jul 01, 2016
by
antirez
Browse files
Added a trivial program to randomly corrupt RDB files in /utils.
parent
2ab70971
Changes
1
Hide whitespace changes
Inline
Side-by-side
utils/corrupt_rdb.c
0 → 100644
View file @
c0f4d193
/* Trivia program to corrupt an RDB file in order to check the RDB check
* program behavior and effectiveness.
*
* Copyright (C) 2016 Salvatore Sanfilippo.
* This software is released in the 3-clause BSD license. */
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
int
main
(
int
argc
,
char
**
argv
)
{
struct
stat
stat
;
int
fd
,
cycles
;
if
(
argc
!=
3
)
{
fprintf
(
stderr
,
"Usage: <filename> <cycles>
\n
"
);
exit
(
1
);
}
srand
(
time
(
NULL
));
cycles
=
atoi
(
argv
[
2
]);
fd
=
open
(
"dump.rdb"
,
O_RDWR
);
if
(
fd
==
-
1
)
{
perror
(
"open"
);
exit
(
1
);
}
fstat
(
fd
,
&
stat
);
while
(
cycles
--
)
{
unsigned
char
buf
[
32
];
unsigned
long
offset
=
rand
()
%
stat
.
st_size
;
int
writelen
=
1
+
rand
()
%
31
;
int
j
;
for
(
j
=
0
;
j
<
writelen
;
j
++
)
buf
[
j
]
=
(
char
)
rand
();
lseek
(
fd
,
offset
,
SEEK_SET
);
printf
(
"Writing %d bytes at offset %lu
\n
"
,
writelen
,
offset
);
write
(
fd
,
buf
,
writelen
);
}
return
0
;
}
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